/*
 Delphi Group - 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);
	$('#main').addClass('clearfix');
	$('ul#sitemap>li').addClass('callout');
	$('.panes>div').click(function(){
		$(this).find('a').click();
	});
	$('.getStartedWrapper').equalHeights(true);
	$('#footerSections').equalHeights(true);
	//$('#productsLanding>div').equalHeights(true);
	//$(".definitionListAlpha dd").parent().append("<strong>test</strong>");

	jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
		return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
	};

	if($('#contactForm')){
		$.get("/token.php",function(txt){
			$("#contactForm").append('<input type="hidden" name="ts" value="'+txt+'" />');
		});
	}
	if($('#requestMeetingForm')){
		$.get("/token.php",function(txt){
			$("#requestMeetingForm").append('<input type="hidden" name="ts" value="'+txt+'" />');
		});
	}

	$("#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");
	});   

    /*
	if($('#customerSlideshow').length>0){
		$('#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");
		}
	});

    //remove margin on right of last thumbnail in row
	$('.clientList a:last-child').addClass('last');
    //remove margin on bottom of last callout
	$('#sidebar .callout:last-child').addClass('last');
    //adjust two-line nav items to vertically center the text
	$('#sectionNav>ul>li>a').wrapInner('<span></span>');
	$('#sectionNav>ul>li>ul>li>a').wrapInner('<span></span>');
	$('#sectionNav>ul>li>a>span').each(function(){
		thisHeight = $(this).height();
		if (thisHeight > 20) {
			$(this).parent().addClass("two-line");
		}
	});
	$('#sectionNav>ul>li>ul>li>a>span').each(function(){
		thisHeight2 = $(this).height();
		if (thisHeight2 > 20) {
			$(this).parent().addClass("two-line");
		}
	});
	
	$('#footerFourth .globIcon a').attr({
		"title": "Request a Meeting"
	});

    //form validation
    
    /*jQuery.validator.addMethod("phoneNums", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, ""); 
	return this.optional(element) || phone_number.length > 9 &&
		phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "Please specify a valid phone number");*/

	/* jQuery.validator.addMethod("phone", function(value, element) {
	return !jQuery.validator.methods.required(value, element) || /^\d{3}-\d{3}-\d{4}$/.test(value); */
    
	$("#contactForm").validate();
    
	$("#requestMeetingForm").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").mouseover(function(){
		$("#quickLinks").addClass("hover");
	}).mouseout(function(){
		$("#quickLinks").removeClass("hover");
	});
    
    // clear default value of form text inputs
	$("#contactForm .text").focus(function(){
		clearDefault(this);
	}).blur(function(){
		restoreDefault(this);
	});
    
	$("#resourceSearch .txt").focus(function(){
		clearDefault(this);
	}).blur(function(){
		restoreDefault(this);
	});
    
	$("#resourceSearchFull .txt").focus(function(){
		clearDefault(this);
	}).blur(function(){
		restoreDefault(this);
	});

	$(".clientDropdown").mouseover(function(){ // enhanced dropdown lists
		$(this).addClass("hover");
	}).mouseout(function(){
		$(this).removeClass("hover");
	});

	$("#supportLoginForm .textField").focus(function(){
		clearDefault(this);
	}).blur(function(){
		restoreDefault(this);
	});
/*
	$("#servicesAccordion h3").bind("click",function(){ // custom accordions
		if($(this).hasClass('current')) {

		}
		else {
			$("#servicesAccordion h3.current").next().slideFadeToggle();
			$("#servicesAccordion h3.current").toggleClass("current");
		}
		
		$(this).next().slideFadeToggle();
		$(this).toggleClass("current");
		$(this).blur();
		$(this).deselect();
	});
	*/
	$("#locationsAccordion h3 a").removeAttr('href');
	
	$("#locationsAccordion h3 a").bind("click",function(){ // custom accordions
		if($(this).hasClass('current')) {
		
		}
		else {
			$("#locationsAccordion h3 a.current").parent().next().slideFadeToggle();
			$("#locationsAccordion h3 a.current").toggleClass("current");
		}
		
		$(this).parent().next().slideFadeToggle();
		$(this).toggleClass("current");
		$(this).blur();
		$(this).deselect();
		return false;
	});

	$("#clientListAccordion h3").bind("click",function(){ // custom accordions
		if($(this).hasClass('current')) {
		
		}
		else {
			$("#clientListAccordion h3.current").next().slideFadeToggle();
			$("#clientListAccordion h3.current").toggleClass("current");
		}
		
		$(this).next().slideFadeToggle();
		$(this).toggleClass("current");
		$(this).blur();
		$(this).deselect();
	});
    
	$("#resourcesAccordion h3").bind("click",function(){ // custom accordions
		if($(this).hasClass('current')) {
		
		}
		else {
			$("#resourcesAccordion h3.current").next().slideFadeToggle();
			$("#resourcesAccordion h3.current").toggleClass("current");
		}
		
		$(this).next().slideFadeToggle();
		$(this).toggleClass("current");
		$(this).blur();
		$(this).deselect();
	});
    
	$(".ourPeople h3").bind("click",function(){ // custom accordions
		if($(this).hasClass('current')) {
		
		}
		else {
			$(".ourPeople h3.current").next().slideFadeToggle();
			$(".ourPeople h3.current").toggleClass("current");
		}
		
		$(this).next().slideFadeToggle();
		$(this).toggleClass("current");
		$(this).blur();
		$(this).deselect();
	});
    
    $('h3 a').each(function(){$(this).attr('title',$(this).text());});
    $('h4 a').each(function(){$(this).attr('title',$(this).text());});
    $('h5 a').each(function(){$(this).attr('title',$(this).text());});


	$('a[rel^="prettyPhoto"]').prettyPhoto({
		theme:'facebook'
	});

	$('a[rel="external"]').attr('target','_blank');
	
	$('#main').append('<div class="clear"></div>');
});


	var ie6 = false;


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
	DD_belatedPNG.fix('.mirevenueBtn'); // Belated PNG fix by Drew Diller - http://www.dillerdesign.com/experiment/DD_belatedPNG/s
	DD_belatedPNG.fix('.mibankingBtn'); // Belated PNG fix by Drew Diller - http://www.dillerdesign.com/experiment/DD_belatedPNG/s
	ie6 = true;
}

	//rounded corners
	if ( ie6 != true) {
		DD_roundies.addRule('#main', '8px 8px 0 0', true);
	}
	DD_roundies.addRule('#socialNav', '5px', true);
	DD_roundies.addRule('.callout', '8px', true);
	DD_roundies.addRule('.quickWrapper', '5px', true);
	DD_roundies.addRule('.homeBucket', '6px', true);
	DD_roundies.addRule('.resourceBucket', '12px', true);
	DD_roundies.addRule('.getStartedBox', '12px', true);
	DD_roundies.addRule('.sidebarMore', '12px', true);
	DD_roundies.addRule('.sidebarContactNum', '12px', true);
	DD_roundies.addRule('.productsCaseStudy', '6px', true);
	DD_roundies.addRule('.publicationBox', '5px', true);
	DD_roundies.addRule('#resourceSearchFull', '5px', true);
