$(function() {
	//call to preload plugin that parses through CSS files and preloads all images referenced within them
	$.preloadCssImages();
	$('#home #sidebar div.row div[align=right]').css('width', 'auto');
	$("#content li").wrapInner("<span></span>");
	
	$("p.prevPage a").wrapInner("<span></span>");
	$("p.nextPage a").wrapInner("<span></span>");
	/*-----vertically center text in top nav------*/
	//loop through each #nav li a
	/*$("#nav li a").each(function(i){
		//store the height of each #nav li a in the variable $navHeight
		var $navHeight = $(this).height();
		// subtract the height of each #nav li a from the max height of each list item (50px). Divide it by 2 to determine the amount of padding above and below the #nav li a, store it in the $leftover variable 
		var $leftover = (50 - $navHeight)/2;
		// set the padding-top and padding-bottom equal to the amount in $leftover, which equals half the remaining space	
		$(this).css({
			"padding-top": $leftover,
			"padding-bottom": $leftover
		});
	});*/
	
	/*$("#nav ul ul li a").each(function(){
		$(this).css({"padding":0});
	});*/
	
	// Align drop down menus to their parents
	$("#nav li.dd ul").each(function(i){
		var self = $(this);
		var p = self.parent('li').children('a').children('span').position();
	
		self.css({
			"padding-left": p.left,
			"padding-right": p.left
		});
	});
	
	$("#nav ul.alt_menu li ul").each(function(i){
		var self = $(this);
		
		var parent = self.parent("li").innerWidth();
		var padding = self.innerWidth();

		var right = padding - parent -3;
self.css("right", right);
	});
	
	/*----------------------------------------------*/
	
	/*-----vertically center banner text------*/
	$("#bannerText h1").each(function(i){
		var $textHeight = $(this).height();
		var $padding = (180 - $textHeight)/2;
		$(this).css({
			"padding-top": $padding,
			"padding-bottom": $padding
		});
	});
	
	/*------------------ANALYTICS-------------------*/
	//track clicks to extranet
	$("a[href=https://extranet.golder.com/]").click(function(){
		try {
			pageTracker._trackPageview("/extranet_link_click.html"); // track google analytics conversion
		}
		catch(err){}
	});

	/*----------------------------------------------*/
	/*-------------------CAREERS--------------------*/
	
	/*-----vertically center "arrow" graphics in careers section------*/
	$(".col15 img").each(function(i){
		var $parentHeight = $(this).parents(".row").height();
		var $parentPadding = ($parentHeight - 33) / 2;
		$(this).css({
			"padding-top": $parentPadding,
			"padding-bottom": $parentPadding
		});
	});
	//Modified Landing Page template: make the entire div clickable by going into it and finding the href attached to the arrow image's parent <a> element
	$(".tealTop .row").click(function() { 
		$(this).children(".col15").find('a').each(function(){ 
			if($(this).attr("target") == "_blank"){
				window.open(this.href); 
			} else {
				window.location = this.href; 
			}
		});
	});	
	
	//Splash Page: make the entire div clickable by going into it and finding the href attached to the arrow image's parent <a> element
	$(".careerHome #sidebar div.row").click(function(){
		$(this).children(".col15").find('a').each(function(){ 
			if($(this).attr("target") == "_blank"){
				window.open(this.href); 
			} else {
				window.location = this.href; 
			}
		});
	});	

	var arrowGlow = new Image(33,33);
	arrowGlow.src = "themes/spartan/images/buttons/career_glow.gif";

//career splash page: effect when user hovers over sidebar divs. Modern browsers get a png background, IE6 gets a solid color
	$(".careerHome #sidebar div.row:has(div)").hover(function(){
		if (jQuery.browser.msie && (jQuery.browser.version < 7)) {
			$(this).addClass("ie6hover");
		} else {
			$(this).addClass("goodHover");				
		}
		//the arrow image needs to "glow" on hover, so the src attribute needs to be switched out 
		$(this).children(".col15").find("img").attr({src : "themes/spartan/images/buttons/career_glow.gif"});
	}, function() {
		if (jQuery.browser.msie && (jQuery.browser.version < 7)) {
			$(this).removeClass("ie6hover");
		} else {
			$(this).removeClass("goodHover");				
		}
		
		//return the arrow to its normal state
		$(this).children(".col15").find("img").attr({src : "themes/spartan/images/buttons/career_arrow.gif"});
	});
	
	//CSS can handle the hovers for the splash page in modern browsers, the code below is for IE6 only.
	$(".careerHome #subNav li").hover(function(){
		if (jQuery.browser.msie && (jQuery.browser.version < 7)) {
			$(this).css("background-color", "#287c7f");
		} else {}
	}, function(){
		if (jQuery.browser.msie && (jQuery.browser.version < 7)) {
			$(this).css("background-color", "transparent");
		} else {}
	});
	
	//Career "landing page" template hovers, same deal with the arrow image needing to "glow"
	$("#sidebarB .tealTop div.row:has(div)").hover(function(){
		if (jQuery.browser.msie && (jQuery.browser.version < 7)) {
			$(this).css({
				"background-color": "#26787d",
				"cursor": "pointer"
			});
				
			$(this).children(".col15").find("img").attr({src : "themes/spartan/images/buttons/career_glow.gif"});
		} else {
			$(this).children(".col15").find("img").attr({src : "themes/spartan/images/buttons/career_glow.gif"});
			$(this).css({
				"background-color": "#26787d",
				"cursor": "pointer"
			});
		}
	}, function(){
		if (jQuery.browser.msie && (jQuery.browser.version < 7)) {
			$(this).css({
				"background-color": "transparent",
				"cursor": "default"
			});
			$(this).children(".col15").find("img").attr({src : "themes/spartan/images/buttons/career_arrow.gif"});
		} else {
			$(this).children(".col15").find("img").attr({src : "themes/spartan/images/buttons/career_arrow.gif"});
			$(this).css({
				"background-color": "transparent",
				"cursor": "default"
			});
		}
	});
	
	/*----------------------------------------------*/
	
	
	/*--make text in search boxes get darker on focus-MODIFIED MAY 1 to remove dependence on inline CSS-*/
	$("#servSearchBox, #sectSearchBox, #projSearchBox").addClass("searchNorm");
	$("#servSearchBox, #sectSearchBox, #projSearchBox").focus(function() {
		$(this).addClass("searchFocus");
		$(this).removeClass("searchNorm");
	});
	$("#servSearchBox, #sectSearchBox, #projSearchBox").blur(function() {
		$(this).removeClass("searchFocus");
		$(this).addClass("searchNorm");
	});
	
	/*----------------------------------------------*/
	

	/*----- JAVASCRIPT FOR SERVICES PAGES. ----*/
	// empties input boxes when click and refills them if empty on blur
	$(".clickErase").each(function(){
		var origText = $(this).val();
		
		$(this).focus(function(){
			if(origText == $(this).val()){
				$(this).val("");
			}
		});
		$(this).blur(function(){
			if($(this).val() == ""){
				$(this).val(origText);
			}
		});
	});
	function isValidEmailAddress(emailAddress) {
		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		return pattern.test(emailAddress);
	}
	// ajax submission of the question contact form with google analytics tracking on services and sectors page
	$("#servicesContact").submit(function(){
		var nameBox = $("#servicesContact #nameBox");
		var emailBox = $("#servicesContact #emailBox");
		var messageBox = $("#servicesContact #messageBox");
		var trackingBox = $("#servicesContact #trackingBox");
		var warnMsg = "";
		// validation
		if(nameBox.val() == "" || nameBox.val() == "Name"){
			warnMsg += "Please enter your name.\n";
		}
		if(!isValidEmailAddress(emailBox.val())){
			warnMsg += "Please enter your email or you entered an invalid email.\n";
		}
		if(messageBox.val() == "" || messageBox.val() == "Enter your message"){
			warnMsg += "Please enter your message.\n";
		}
		if(warnMsg != ""){
			alert(warnMsg);
			return false;
		}
		// ajax post and response effects
		trackingBox.val(query);
		var data = $(this).serialize();
		$.post($(this).attr("action"),data,function(response){
			if(response == "success"){
				messageBox.val("");
				$("#servicesContact .note").fadeIn(500);
				setTimeout("$(\"#servicesContact .note\").fadeOut(1000);",10000);
				//submit google analytics goal tracking
				try {
					var conversionHTML = '<iframe src="/themes/spartan/conversion_contact_form.html" width="1" height="1" /></iframe>';
					$("body").append(conversionHTML); //track google adwords conversion
					pageTracker._trackPageview("/track_contact_submission.html"); //track google analytics goals
				}
				catch(err){}
				
				us_homepage_conversion_cookie = readCookie("us_homepage_conversion");
				if(us_homepage_conversion_cookie == "convert") {
					try {
						var conversionHTML = '<iframe src="/themes/spartan/conversion_pages/us_homepage_service_sectors.html" width="1" height="1" /></iframe>';
						$("body").append(conversionHTML); //track google adwords conversion
						eraseCookie("us_homepage_conversion");
					}
					catch(err){}
				}
				
			} else {
				alert('Sorry, there was an error in processing your request. Please try again later');
			}
		});
		return false;
	});
	/*----------------------------------------------*/

	/*----- JAVASCRIPT FOR PROJECTS PAGES. ----*/
	
	// initially hide the expandable divs and the minimize span
	var startHighlightedService = $("#show_services li.current a");
	var startHighlightedSector = $("#show_sectors li.current a");

	if (!startHighlightedService.length && !startHighlightedSector.length) {
		$("#viewAllProjects").hide();
	}
	$("#show_sectors").hide();
	$("#show_services").hide();
	$("#projSearch div.expanded").hide();
	$("#projSearch .minimize").hide();
	
	// show expand bar as clickable
	$("#projSearch #expandBar").css("cursor", "pointer");

	// bind click event so when the green bar is clicked, project gallery will toggle
	$("#projSearch #expandBar").click(function(){
		$("#projSearch div.expanded").slideToggle("fast", function(){
			$("#projSearch .minimize").toggle();
			$("#projSearch .expand").toggle();
		});
		
	});

	// bind click event so when services is clicked, services div will show
	$("#clickServices").click(function() {

		// change highlight
		$("#clickSectors").removeClass("current");
		$("#clickServices").addClass("current");

		// hide sectors div
		$("#show_sectors").hide();
		
		// show services div
		$("#show_services").show();
		
		return false;
	});
	
	// bind click event so when sectors is clicked, sectors div will show
	$("#clickSectors").click(function() {

		// change highlight
		$("#clickServices").removeClass("current");
		$("#clickSectors").addClass("current");

		// hide services div
		$("#show_services").hide();
		
		// show sectors div
		$("#show_sectors").show();
		
		return false;
	});
	
	// bind additional click events
	bindViewAll()
	bindSectors();
	bindServices();
	bindProjectResults();

	// function to bind a click events to 'view all'
	function bindViewAll() {
		$("#viewAllProjects a").click(clickViewAll);
		return true;
	}

	// function to bind click events to sectors
	function bindSectors() {
		$("#show_sectors a").click(clickSector);
		return true;
	}
	
	// function to bind click events to services
	function bindServices() {
		$("#show_services a").click(clickService);
		return true;
	}
	
	// function to bind events to project results
	function bindProjectResults() {
		
		// bind click events
		$("#sortSearch a").click(clickProjectResults);
		$("#projList a").click(clickProjectResults);
		$("#projResults #paging a").click(clickProjectResults);
		
		// bind cell click
		$('#projList table td').click(function() { 
			$(this).find('a').each(clickProjectResults);
		});

		// bind cell hover states
		$("#projList table td").hover(function() {
			$(this).css({
				"background-color": "#f4faf4",
				"cursor": "pointer"
			});
			$(this).children().children("a").css("color", "#619a8d" );
		}, function() {
			$(this).css({
				"background-color": "transparent",
				"cursor": "default"
			});
			$(this).children().children("a").css("color", "#00765A");
		});
		
	}

	// function when view all projects is clicked on
	function clickViewAll() {

		// hide service/sector divs
		$("#show_services").hide();
		$("#show_sectors").hide();

		// remove highlights
		$("#show_services li").removeClass("current");
		$("#show_sectors li").removeClass("current");
		$("#clickServices").removeClass("current");
		$("#clickSectors").removeClass("current");

		// change gallery label
		$(".breadcrumbs").html($("#hiddenViewByProjectsByTranslation").val());
		
		// hide the link to 'view all'
		$("#viewAllProjects").hide();

		// get clicked link
		var clickedLink = $(this).attr('href');

		// update project results
		updateProjectResults(clickedLink);
		
		return false;
	}

	// function when sector is clicked on
	function clickSector() {

		// remove highlights
		$("#show_services li").removeClass("current");
		$("#show_sectors li").removeClass("current");

		// highlight selected item
		$(this).parents("li").addClass("current");
		
		// change gallery label
		var sectorName = $(this).html();
		$(".breadcrumbs").html(sectorName);
		
		// show a link to 'view all'
		$("#viewAllProjects").show();

		// get clicked link
		var clickedLink = $(this).attr('href');

		// update project results
		updateProjectResults(clickedLink);

		return false;
	}
	
	// function when service is clicked on
	function clickService() {

		// remove highlights
		$("#show_services li").removeClass("current");
		$("#show_sectors li").removeClass("current");

		// highlight selected item
		$(this).parents("li").addClass("current");

		// change gallery label
		var serviceName = $(this).html();
		$(".breadcrumbs").html(serviceName);

		// show a link to 'view all'
		$("#viewAllProjects").show();

		// get clicked link
		var clickedLink = $(this).attr('href');

		// update project results
		updateProjectResults(clickedLink);

		return false;
	}
	
	// function when project results is clicked on
	function clickProjectResults() {
		
		// get clicked link
		var clickedLink = $(this).attr('href');

		// update project results
		updateProjectResults(clickedLink);

		return false;
	}
		
	// function to update the project results area
	function updateProjectResults(clickedLink) {

		// display loader
		$("#projResults").prepend("<span id='load'>Loading...</span>");
		
		// load project results
		$("#projResults").load(clickedLink + '&op=ajaxprojresults', hideLoading);
		
		// hide loader
		function hideLoading() {
			bindProjectResults();
			$("#load").fadeOut("fast");
			//run the equal columns script after all images have finished loading so that heights are correctly calculated
			$("#projDetail img").load(function (){
				projCols();
			});
			
		};		
	
		return true;
	}
	
	/*----------------------------------------------*/
	
	
	/*-------MAKE THE SERVICE AND SECTOR TAGS MORE EASILY CLICKABLE IN THE PUBLICATIONS SECTION-----*/
	$(".sectorTags li").click(function(){
		$(this).find('a').each(function(){ window.location = this.href; });
	});
	$(".serviceTags li").click(function(){
		$(this).find('a').each(function(){ window.location = this.href; });
	});
	/*----------------------------------------------*/
	
	
	
	/*---give entire table-rows a background color on hover, give newsletter table cells background color on hover. make the entire cell/row clickable--MODIFIED MAY 1 to remove dependence on inline CSS */
	$('.newsletterContents td').click(function() { 
    	$(this).find('a').each(function(){ window.location = this.href; });
	});
	
	$(".newsletterContents td").hover(function() {
		$(this).addClass("rowHover");
	}, function() {
		$(this).removeClass("rowHover");
	});
	
	$('.newsList tr').click(function() { 
    	$(this).find('a').each(function(){ window.location = this.href; });
	});
	
	$(".newsList tr").hover(function() {
		$(this).addClass("rowHover");
			
	}, function() {
		$(this).removeClass("rowHover");
	});
	
	$('.eventsList tr').click(function() { 
    	$(this).find('a').each(function(){ window.location = this.href; });
	});
	
	$(".eventsList tr").hover(function(){
		$(this).addClass("rowHover");
			
	}, function(){
		$(this).removeClass("rowHover");
	});
	/*----------------------------------------------*/
	
	
	/*--SET WIDTH OF EACH SCROLLING DIV CONTAINER----*/
	
	$("#serviceScroll .scroll-content").width(($("#serviceScroll .scroll-content-item").length)*197);
	$("#sectorScroll .scroll-content").width(($("#sectorScroll .scroll-content-item").length)*197);
	$("#assocScroll .scroll-content").width(($("#assocScroll .scroll-content-item").length)*197);
	
	$("#frac3 #serviceScroll, #frac3 #sectorScroll").width("auto");
	
	/*----Initialize functions for slideshows on service and sector detail pages----*/
	servSlideL();
	sectSlideL();
	removeScrolls();	

	// code for language drop down
	$("#locationBar li.language, #locationBar li.language ul li").hover(function(){
		$(this).addClass("hover");
	}, function() {
		$(this).removeClass("hover");
	});

	$('.newsletterRow .col28:eq(0),.newsletterRow .col28:eq(1), .newsletterRow .col28:eq(3), .newsletterRow .col28:eq(4)').addClass('mr40');
	// Make newsletter titles equal height in each row so the pictures align
	$('.newsletterContents tr').each(function(){
		var $heights = [];
		$(this).find('.title').each(function(){
			$heights.push($(this).height());
			$heights.sort().reverse();
		});
		$(this).find('.title').height($heights[0]);	
	});
	wrapRows();
	disableFields();
	
	// analytics analytics and conversion tracking
	$("#home #sidebar a").each(function(){
		var link = $(this);
		var location = link.attr("href");
		if(location.match(/name=Services/i) || location.match(/name=Sectors/i)){
			link.click(function(){
				createCookie("us_homepage_conversion","convert");
			});
		}
	});
	// tracking clicks on email address on contact page
	$("a").live("click",function(){
		if($(this).attr("href").match(/^mailto/i)){
			try {
				var conversionHTML = '<iframe src="/themes/spartan/conversion_email_link_click.html" width="1" height="1" /></iframe>';
				$("body").append(conversionHTML); //track google adwords conversion
				pageTracker._trackPageview("/email_link_click.html"); // track google analytics conversion
			}
			catch(err){}
			
			us_homepage_conversion_cookie = readCookie("us_homepage_conversion");
			if(us_homepage_conversion_cookie == "convert") {
				try {
					var conversionHTML = '<iframe src="/themes/spartan/conversion_pages/us_homepage_service_sectors.html" width="1" height="1" /></iframe>';
					$("body").append(conversionHTML); //track google adwords conversion
					eraseCookie("us_homepage_conversion");
				}
				catch(err){}
			}
		}
	});	
	//tracking for referrals from search engines
	
	engines = new Array(
		Array("Google","google.com","q="),
		Array("Yahoo","yahoo.com","p="),
		Array("Bing","bing.com","q="),
		Array("Aol","aol.com","query="),
		Array("Ask","ask.com","q=")
	);
	query = "no search term specified";
	refer = document.referrer;
	
	for (var j in engines){
		queryExp = new RegExp("^"+engines[j][2]);
		urlExp = new RegExp(engines[j][1]);
		if(refer.match(urlExp)){
			url = refer.split(/\?/);
			urlArr = url[1].split(/&/);
			for (var i in urlArr){
				if(urlArr[i].match(queryExp)){
					query = urlArr[i].replace(queryExp,"");
					query = engines[j][0]+": "+query.replace(/\+/g," ");
					createCookie("spartanTracking",query);
				}
			}
		} else {
			if(readCookie("spartanTracking") != null){
				query = readCookie("spartanTracking");
			}
		}
	}
	
	/*-- Services Description Tooltips --*/
	$("a.service_header").cluetip({
		showTitle: false,
		arrows:		true,
		cluezIndex: 9000,
		splitTitle: '|',
		dropShadow: false,
		width: 400
	});
	
	//Set html5 placeholder substitute
	$("input[type='text']").placeholder();
	
	//New contact view accordion
	$("#accordion").accordion({header: 'h1', autoHeight:false, active:false, collapsible:true});
	
	//New contact view columns
	$("#accordion .country").columns(3);
	
	//Subsidiaries page template rotating header
	$("#fracSlide").cycle();
	
	
}); //close document.ready//
/*--images aren't necessarily ready when the document is ready, and cacheing may be a problem too, so run the equal columns script after everything else, on eache page load--*/
($(window).load(
	
	
	function equalCols() {
		var servContent = $("#contentWrap").innerHeight();
		var landingContent = $("#landingPage #contentWrap").innerHeight();
		var sidebarHeight = $("#sidebar").innerHeight();
		var contentHeight = $("#content").innerHeight();
		var sectionLandHeight = $("#sectionLand").innerHeight();
		var tabHeight = $("#glTab").innerHeight();
		var sidebarB = $("#sidebarB").innerHeight();
		var landSidebar = $("#landingPage #sidebar").innerHeight();
		var landContent = $("#landingPage #content").innerHeight();
		var homecontent = $("#home #content").innerHeight();
		var homesidebar = $("#home #sidebar").innerHeight();

	//Sidebar height fixes
	if((contentHeight > sidebarHeight)&&(contentHeight > sidebarB))
	{
		$("#sidebar").height(contentHeight - 20);
		$("#sidebarB").height(contentHeight);
	}
	if(sidebarHeight < sidebarB)
	{
		$("#sidebar").height(sidebarB - 20);
	}
		
	if(sidebarHeight < contentHeight) {
		$("#sidebar").height(contentHeight - 20);
		
	} else if (contentHeight < sidebarHeight) {
		$("#content").height(sidebarHeight - 40);
	}
	if(homesidebar < homecontent) {
		$("#home #sidebar").height(homecontent);
	} else if (homecontent < homesidebar) {
		$("#home #content").height(homesidebar);
	}
	if(landSidebar < landContent) {
		//$("#landingPage #sidebar").height(landContent - 20);
		
	} else if(landContent < landSidebar) {
		//$("#landingPage #content").height(landSidebar - 44);
	}

	if(tabHeight < sectionLandHeight) {
		$("#glTab").height(sectionLandHeight - 20);	
	} else if(sectionLandHeight < tabHeight) {
		$("#sectionLand").height(tabHeight - 21);
	}
	
	if(tabHeight < servContent) {
		$("#glTab").height(servContent);
		$("#services #sidebar").height(servContent + 20);
		$("#sectors #sidebar").height(servContent + 20);
	} else {}
	
	if(landingContent < sidebarB) {
		$("#landingPage #sidebar").height(sidebarB - 412);
		$("#landingPage #content").height(sidebarB - 437);
	} else if(sidebarB < landingContent) {
		$("#landingPage #sidebarB").height(landingContent + 45);
		$("#landingPage #sidebar").height(landingContent - 367);
		$("#landingPage #content").height(landingContent - 392);
	}
	var projLeft = $("#projects #left").innerHeight();
	var projSide = $("#projects #projSidebar").innerHeight();
	//alert(projLeft);
	if(projSide < projLeft) {
		$("#projects #projSidebar").height(projLeft);
	} else {
		$("#projects #left").height(projSide);
	}
	$("#bannerText h1").each(function(i){
		var $textHeight = $(this).height();
		var $padding = (180 - $textHeight)/2;
		$(this).css({
			"padding-top": $padding,
			"padding-bottom": $padding
		});
	});
	
	
}


));//end window.load

function servSlideL(){
	$('.slideControl').hide();
		
		$(".local #servSlideWrap").hover(
		  function () {
			var servSlides = $("#servSlide").children().length;
			if(servSlides > 1) {
				$(".slideControl").fadeIn();
			} else {}
		  }, 
		  function () {
			var servSlides = $("#servSlide").children().length;
			if(servSlides > 1) {
				$(".slideControl").fadeOut();
			} else {}
		  }
		);
	
	var slideURL = $(".local #servSlide").attr("title");
	$(".local #servSlide").load(slideURL, function(){
		$(this).cycle({
			timeout: 5000,
			fit: 0,
			containerResize: 0,
			pagerClick: resumeShow,
			pager: "#paging"
		});
		
		function resumeShow() {
			$(".local #servSlide").cycle("resume");
		}
	});
	
	$("#services .local #playPause").toggle(function(){
		$(".local #servSlide").cycle('pause');
		$(this).attr({src: "themes/spartan/images/buttons/play.gif"}, {alt: "resume slideshow"});
		}, function() {
			$(".local #servSlide").cycle('resume', true);
			$(this).attr({src: "themes/spartan/images/buttons/pause.gif"}, {alt: "pause slideshow"});
	});
	
}


function sectSlideL(){
	$('.slideControl').hide();
		
		$(".local #sectSlideWrap").hover(
		  function () {
			 var sectSlides = $("#sectSlide").children().length; 
			if(sectSlides > 1) {
				$(".slideControl").fadeIn(); 
			} else {}
		  }, 
		  function () {
			  var sectSlides = $("#sectSlide").children().length;
			if(sectSlides > 1) {
				$(".slideControl").fadeOut();
			} else {}
		  }
		);
	
	var slideURL = $(".local #sectSlide").attr("title");
	$(".local #sectSlide").load(slideURL, function(){
		$(this).cycle({
			timeout: 5000,
			fit: 0,
			containerResize: 0,
			pagerClick: resumeShow,
			pager: "#paging"
		});
		
		function resumeShow() {
			$(".local #sectSlide").cycle("resume");
		}
	});
	
	$("#sectors .local #playPause").toggle(function(){
		$(".local #sectSlide").cycle('pause');
		$(this).attr({src: "themes/spartan/images/buttons/play.gif"}, {alt: "resume slideshow"});
		}, function() {
			$(".local #sectSlide").cycle('resume', true);
			$(this).attr({src: "themes/spartan/images/buttons/pause.gif"}, {alt: "pause slideshow"});
	});
}

function removeScrolls(){
	if($("#serviceScroll .scroll-content-item").length <= 2) {
		
		$("#serviceScroll .scroll-bar-wrap").remove();
	} else {}
	
	if($("#assocScroll .scroll-content-item").length <= 2) {
		$("#assocScroll .scroll-bar-wrap").remove();
	} else {}
	
	if($("#sectorScroll .scroll-content-item").length <= 2) {
		$("#sectorScroll .scroll-bar-wrap").remove();
	} else {}
}

function projCols(){
	var projLeft = $("#projects #left").innerHeight();
	var projSide = $("#projects #projSidebar").innerHeight();
	//alert(projLeft);
	if(projSide < projLeft) {
		$("#projects #projSidebar").height(projLeft);
	} else {
		$("#projects #left").height(projSide);
	}
}

// update on March 23, 2009
function newWindow(pageLink,showscrollbar) {
var winOption='scrollbars=no,menubar=no,height=800,width=1000,resizable=yes,toolbar=no,location=no,status=no'
if(showscrollbar!=undefined){
	if (showscrollbar==true)
	winOption='scrollbars=yes,menubar=no,height=800,width=1000,resizable=yes,toolbar=no,location=no,status=no'
}
var newWindow = window.open(pageLink,'',winOption);
}

// function to clear text in a search box when search box is clicked
var hasClicked = false;
function searchTextClick(searchTextBox) {
	if (!hasClicked) {
		searchTextBox.value = '';
		hasClicked = true;
	}
}
function vertCenter(){
	$("#bannerText h1").each(function(i){
		var $textHeight = $(this).height();
		var $padding = (180 - $textHeight)/2;
		$(this).css({
			"padding-top": $padding,
			"padding-bottom": $padding
		});
	});
}
function wrapRows(){
	var results =[];
    var elements = $(".newsletterRow").children('.col28');
    $.map(elements, function(i,n){
		if(n%3 === 0){
            results.push(n);
        }
    });

    $.each(results, function(i,v){
            elements.slice(v,v+3).wrapAll('<div class="fLeft"></div>');
    });	
}
function disableFields() {
	$('input.req').attr("disabled",false);
	$('input.attending').attr("checked",true);
	$('input.attending').click(function(){
		if($(this).is(':checked')) {
			$('input.req').attr("disabled",false);
			$('input.req').css("background-color","#FFFFFF");
		} else {
			$('input.req').attr("disabled",true);
			$('input.req').css("background-color","#F2F1ED");
		}
	});
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

