var currentFooter=0;

$(document).ready(function(){
	jQuery.easing.def = 'easeOutCubic';
	//var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	//var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
	var isie = navigator.appName == "Microsoft Internet Explorer";
	var dontOpaque = isie; //(jQuery.browser.msie && (ie55 || ie6));

	$("#navSec #navSec_items li").hover(
		function () {
			if ( !$(this).hasClass("active"))
			{
				$(this).css("background", "#F9F9F9 url(/images/navSec_bg_hv.gif) repeat-y top left");
				if (!dontOpaque)
					$(this).find("img").css({'opacity' : '0.7' , 'filter' : 'alpha(opacity=70)'});
			}
		}, 
		function () {
			if ( !$(this).hasClass("active"))
			{
				$(this).css("background", "#F2F2F2 url(/images/navSec_bg_off.gif) repeat-y top left");
				if (!dontOpaque)
					$(this).find("img").css({'opacity' : '0.3' , 'filter' : 'alpha(opacity=30)'});
			}
		}
	);
	$("#navSec #navSec_items li").click(
		function () {
			if ( !$(this).hasClass("active") )
			{
				if ($(this).find("a:first").attr("target") == "_blank")
					window.open($(this).find("a:first").attr('href'));
				else
					if ($(this).find("a:first").attr("href") != "")
						window.location = $(this).find("a:first").attr('href');
			}
		}
	);
	
	var priNav = new Array(10);
	priNav[0] = new navPriItem("/content/construction-services/civil/", "/images/primnav_civil2.jpg");
	priNav[1] = new navPriItem("/content/construction-services/materials/", "/images/primnav_materials2.jpg");
	priNav[2] = new navPriItem("/content/construction-services/environmental/", "/images/primnav_environmental2.jpg");
	priNav[3] = new navPriItem("/content/construction-services/drilling/", "/images/primnav_drilling2.jpg");
	priNav[4] = new navPriItem("/content/construction-services/consulting/", "/images/primnav_consulting2.jpg");
	priNav[5] = new navPriItem("/content/construction-services/development/", "/images/primnav_development2.jpg");
	priNav[6] = new navPriItem("/content/about-us/", "/images/primnav_aboutus2.jpg");
	priNav[7] = new navPriItem("/content/contact-us/", "/images/primnav_contact2.jpg");
	priNav[8] = new navPriItem("/content/safety/", "/images/primnav_healthsafety2.jpg");
	priNav[9] = new navPriItem("/content/news/", "/images/primnav_news2.jpg");

	if (window.location.pathname == "/")
		$("#wrapper").css("background-image", "url(/images/primnav_homepage2.jpg)");
	else
	{
		for (var x = 0; x < priNav.length; x++)
		{
			if (window.location.pathname.indexOf(priNav[x].url) == 0)
				$("#wrapper").css("background-image", "url(" + priNav[x].image + ")");
		}
	}



	if ( $(".footer_teaser_row").length != 2 )
	{
		$("#chTsr_link").css("background-image", "/images/blank.gif");
		$("#chTsr_link").removeClass("footerTsr_ch_onup");
	}
	else
	{
		$(".footer_teaser_row").hide(0);
		$(".footer_teaser_row:first").show(0);
		$("#chTsr_link").click
		(
			function () 
			{
				if ( !$(".footer_teaser_row").is(':animated') )
				{
					currentFooter = $("#chTsr_link").hasClass("footerTsr_ch_onup") ? 0 : 1;
					var hideDir = (currentFooter == 0 ? "up" : "down");
					var showDir = (currentFooter == 0 ? "down" : "up");
					
					$(".footer_teaser_row").each( function () {
						if( $(this).css("display") == "block" )
							$(this).hide("slide", { direction: hideDir }, 1000);
					} );
					$(".footer_teaser_row:eq(" + Math.abs(currentFooter-1) + ")").show("slide", { direction: showDir }, 1000);
					$("#chTsr_link").toggleClass("footerTsr_ch_onup");
					$("#chTsr_link").toggleClass("footerTsr_ch_ondown");
				}
				
				return false;
			}
		);
	}



	// search box
	$("#sq").focus(
		function ()
		{
			$(this).css('background', '#ffffff');
		}
	);
	
	$("#sq").blur(
		function ()
		{
			if (this.value == '') {
				$(this).css('background', '#FFFFFF url(http:\x2F\x2Fwww.google.com\x2Fcse\x2Fintl\x2Fen\x2Fimages\x2Fgoogle_custom_search_watermark.gif) left no-repeat');
			}
		}
	);
	
});



var navSecPager={
	init:function(config){
		jQuery(document).ready(function($){
			var count = config.count;
			var pages = Math.ceil($("#navSec_items ul li").length / count);
			
			// get the current page of active link
			var current = Math.ceil(($("#navSec_items ul li").index($("#navSec_items ul li.active:first"))+1) / count) - 1;
			if (current < 0)
				current = 0;
			
			// insert necessary html for the paging elements
			$("#navSec_items").after("<div id='navSec_paging'><ul></ul></div>");
		
			// generate the page number links
			for (var x = 0; x < pages; x++)
				$("#navSec_paging ul").append("<li>" + (x+1) + "</li>");

			// display only the top [count] items
			$("#navSec_items ul li:gt(" + (count-1) + ")").css("display", "none");
			
			// change the item list when page number is clicked
			$("#navSec_paging ul li").click(function(){
				// index of page click
				var index = $("#navSec_paging ul li").index(this);
				
				// set all items to hidden
				$("#navSec_items ul li").css("display", "none");
				
				// set upper and lower bounds
				var iLow = index * count - 1;
				
				// display only required items
				if (iLow < 0)
					$("#navSec_items ul li:lt(" + count + ")").css("display", "list-item");
				else
					$("#navSec_items ul li:gt(" + iLow + "):lt(" + count + ")").css("display", "list-item");
					
				// set the current page link to the active class
				$("#navSec_paging ul li").removeClass("active");
				$("#navSec_paging ul li").removeClass("hover");
				$("#navSec_paging ul li:eq(" + index + ")").addClass("active");
			});

			$("#navSec_paging ul li").hover(
				function(){
					if (!$(this).hasClass("active"))
						$(this).addClass("hover");
				},
				function(){
					if (!$(this).hasClass("active"))
						$(this).removeClass("hover");
				}
			);

			// set the current page to match the current active link
			$("#navSec_paging ul li:eq(" + current + ")").addClass("active");
			$("#navSec_paging ul li:eq(" + current + ")").click();
		});
	}
}


function navPriItem(url, image)
{
	this.url = url;
	this.image = image;
}