/*
 Palladium Insurance - Common Scripts by bv02 Inc.
 */

/* Declare some page variables & functions */

//clear default value of an element
function clearDefault(el) {
	if (el.defaultValue==el.value){el.value = "";}
}
//restore default value of an element
function restoreDefault(el) {
	if (el.value==""){el.value = el.defaultValue;}
}


/* jQuery - wait for DOM to load, then manipulate some elements */

$(document).ready(function() {

	$('.homeFourCol').equalHeights(true);
	$('.getStartedWrapper').equalHeights(true);
	$('#footerSections').equalHeights(true);
	$('#searchform input#search').typeSearch();
	//$('#headerSearch input.search').focus(function(){  }).blur(function(){ alert('adsfasf');  });
	$('#searchform label').hide();

	if($('#sitemap')){
		var sitemapSec1 = $('#sitemap > li:nth-child(1) > ul').css('height');
		$('#sitemap > li:nth-child(2) > ul').css('height',sitemapSec1);
	}

	if($('#signupForm')){
		$.get("/token.php",function(txt){
			$("#signupForm").append('<input type="hidden" name="ts" value="'+txt+'" />');
		});
	}
	if($('#contactForm')){
		$.get("/token.php",function(txt){
			$("#contactForm").append('<input type="hidden" name="ts" value="'+txt+'" />');
		});
	}

	jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
		return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
	};
/*
	$('#headerSearch input.search').attr({ // fancy safari-style search inputs
		value: ""
	});
	$('#headerSearch input.search').typeSearch(); 
	$('#resourceSearch input.txt').typeSearch(); 
	$('#resourceSearchFull input.txt').typeSearch(); 
	$('#contactSearch').typeSearch(); 
	*/

	$("#btnPrint").bind("click",function(){ // print button. no href="javascript" here
		window.print();
		return false;
	});
    
	$("#btnSmallText").bind("click",function(){ // small text button
		setActiveStyleSheet("small");
		return false;
	});
    
	$("#btnNormalText").bind("click",function(){ // normal text button
		setActiveStyleSheet("normal");
		return false;
	});
    
	$("#btnLargeText").bind("click",function(){ // large text button
		setActiveStyleSheet("large");
		return false;
	});
    
	$("#footerSubmit").bind("click",function(){ // clear default form values on submit
		clearDefault("#footerName");
	});
    
	/*$('#customerSlideshow').cycle({ 
		fx:     'fade', 
		easing: 'linear', 
		delay:  -4000 
	});*/
		
	$(".accordionContent").removeClass("visible"); //hide accordion items with JS to maintain accessibility
	
	$(".bioContent").removeClass("visible"); //hide accordion items with JS to maintain accessibility
    
	$(".accordionHeader").each(function(){ //style fix for accordion nav items that break to two lines
		thisHeight = $(this).height();
		if (thisHeight > 18) {
			$(this).addClass("tall");
		}
	});
    
    //add blue striping to lists    
	$(".clientList ul").each(function(){
		var isBlue = "true";
		$(this).children().each(function(){
			if (isBlue == "true") {
				$(this).addClass("blue");
				isBlue = "false";
			} else if (isBlue == "false") {
				isBlue = "true";
			}
		});
	});
    // end stripes
    
    //form validation
    
	$("#contactForm").validate();
	$("#signupForm").validate();
	$("#newsletterForm").validate();
    
    //end validation
    
	$(".clientList a").each(function(){ // ensures all links in the client list open in a new window 
		$(this).attr("target","_blank");
	});
    
	$(".linkList a").each(function(){ // ensures all links in the client list open in a new window 
		$(this).attr("target","_blank");
	});

    
    // dumbing down :hover pseudo-classes for IE6
	$("#quickLinks").hover(function(){
			$("#quickLinks").addClass("hover");
			$('#quickList').slideFadeToggle();
		},function(){
			$("#quickLinks").removeClass("hover");
			$('#quickList').slideFadeToggle();
		}
	);
    
    // clear default value of form text inputs
	$("#newsletterForm .text").focus(function(){
		clearDefault(this);
	}).blur(function(){
		restoreDefault(this);
	});
    
	$("#signupForm .text").focus(function(){
		clearDefault(this);
	}).blur(function(){
		restoreDefault(this);
	});

	var quoteToggle = function(){
		$(this).toggleClass('showing');
		$("#getQuote #getQuoteBtn").bind("click",quoteDrop);
		$("#homeGetQuoteBanner").bind("click",quoteDrop);
	};

	var quoteDrop = function(){
		$(this).toggleClass('showing');
		$("#getQuote #dropdownWrapper").slideFadeToggle(quoteToggle);
		$(this).unbind("click");
		return false;
	};

	$("#getQuote #getQuoteBtn").bind("click",quoteDrop);
	$("#homeGetQuoteBanner").bind("click",quoteDrop);

	$('a[rel^="external"]').attr('target','_blank');

	if($('#homeBanners .panes').length !== 0){
		if($.browser.msie && $.browser.version.substr(0,1)<7) {}
		else{
		    $('#homeBanners .panes').cycle({ 
				fx:     'scrollHorz',
				speed:  1100,
				delay:  -4000,
				pause: true,
				manualTrump: false,
				timeout: 9000,
				next:   '.homeBannerNext a',
				prev:   '.homeBannerPrev a',
				easing: 'easeInOutQuad'
			});
			$('.homeBannerPrev a').bind('click',function(){
				if($("#getQuote #getQuoteBtn").hasClass("showing") || $("#homeGetQuoteBanner").hasClass("showing")){
					$("#getQuote #getQuoteBtn").click();
				}
			});
			$('.homeBannerNext a').bind('click',function(){
				if($("#getQuote #getQuoteBtn").hasClass("showing") || $("#homeGetQuoteBanner").hasClass("showing")){
					$("#getQuote #getQuoteBtn").click();
				}
			});
		}
	}


});

if ($.browser.msie && $.browser.version.substr(0,1)<7) { // add PNG Fix in IE6
	DD_belatedPNG.fix('.png'); // Belated PNG fix by Drew Diller - http://www.dillerdesign.com/experiment/DD_belatedPNG/s
}
