var $lnkAward = "";

function getCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == c_name) {
            return unescape(y);
        }
    }
}

function setCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value;
}

function setDivHeight() {
    if (parseInt(navigator.appVersion) > 3) {
        if (window.innerHeight) {
            h = window.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) {
            h = document.documentElement.clientHeight;
        } else if (document.body) { // other Explorers
            h = document.body.clientHeight;
        }
        if ((h - 447) < 292) {
            h = 292;
        } else {
            h = h - 447;
        }
        if (document.getElementById("rotatingBox")) {
            document.getElementById("rotatingBox").style.height = h + "px";
        }
    }

}
function assignTitle() {
    var i;
    for (i = 1; i < 5; i++) {
        $('.bgstretcher UL LI:nth-child(' + i + ')').attr('title', 'tab' + i + '');
    }
}

function getQueryStr( name ){
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return null;
  else
    return results[1];
}
function chkQuery(){

	var vQuery=null;
	var thisHash = null;
	var vQuery=getQueryStr('y');
	if(vQuery!=null)
	{
	$lnkAward = "active";

	$(".yearFilter select").val(vQuery);
	$(".yearFilter select").trigger('change');
	$('html, body').animate({ scrollTop: ($("#" + getQueryStr('id')).offset().top - 61)});
	$("#" + getQueryStr('id')).find("div.newsItemDate").trigger('click');
	$lnkAward = "";
	}
}
function checkBookmark () {
	var cur_url = window.location.href;
	var cur_parts = cur_url.split("#");
	if(cur_parts[1]){
	var trgt = cur_parts[1];
	var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top - 61;
		$('html, body').animate({scrollTop:target_top}, 500);	
	}
}

$(window).bind("unload", function() { 
 $(".navContainer ul.level1 li").each(function () {
        $(this).removeClass("hover");
    });								  
});

$(document).ready(function () {

//Main Navigation
if (sectionName!='')
{
	$('ul.level1 li.' + sectionName + ' a:first').addClass('selected');
}
	
							
							
// Dropdown Navigation

    $(".navContainer ul.level1 li").mouseenter(function () {  $(this).addClass("hover"); });
    $(".navContainer ul.level1 li").mouseleave(function () {  $(this).removeClass("hover"); });

// Set Background Image 
	var bgImage = getCookie("bgImage");
	if((bgImage!=null) && (bgImage!=""))
		{
			 $("body").css("background", "#000 url('" + bgImage + "') no-repeat fixed center top");
		}	

// Post your resume form  hover
    $(".postResumeContentForm .textareaBG textarea").focus(function () { $(this).parent().addClass("hover"); });
    $(".postResumeContentForm .textareaBG textarea").blur(function () {  $(this).parent().removeClass("hover"); });
	

// Core Values page

   if($(".coreValues")) {
		$(".coreValuesRight .thumb li a").click(function () {
		tempImg = $(this).parent().attr("class")
		$(".coreValuesLeft div.show").removeClass('show');
		$(".coreValuesRight div.show").removeClass('show');
		$(".coreValuesRight .thumb li a.active").removeClass('active');
		$ ("#" + tempImg+ "Img").addClass('show')
		$ ("#" + tempImg+ "Content").addClass('show')
		$(this).addClass("active");
			
    });	   
}


// News section Expand Collapse


	if($(".newsItem")) 
	{	$prev = $(".newsItem:first");
		$prev.find("div.newsItemContent").slideDown("fast");
		$prev.find("div.newsItemDate").find("a").html("");
		$(".newsItem .newsItemDate").click(function (){
			if($(this).parent().find("div.newsItemContent").is(":visible"))
			{
					if ($lnkAward=="")
					{
						$(this).parent().find("div.newsItemContent").slideUp("fast");
						$(this).find("a").html("Read more");
					}

			}
			else
			{

				$prev.find("div.newsItemContent").slideUp(500);
				$prev.find("div.newsItemDate").find("a").html("Read more");
				$(this).parent().find("div.newsItemContent").slideDown(500);
				$(this).find("a").html("");
				$prev = $(this).parent();
				
						setTimeout(function(){
								if (($('html, body').height() - ($prev.offset().top-61)) > ($(window).height()))
					{			

											$('html, body').animate({ scrollTop: ($prev.offset().top - 61)});
					}
											}, 600)

			}
			
		});	   
	 }

// News section Year selection filter

if($(".yearFilter select")) 
	 {	
	 	$(".yearFilter select option").each(function(){ $(".newsItemsContainer" + $(this).val()).hide(); });
		$(".yearFilter select option").eq(0).attr("selected", "selected");
		$(".newsItemsContainerCurrent").show();
		$(".yearFilter select").change(function () {
			if ($lnkAward=="")
					{
				$prev.find("div.newsItemContent").slideUp("fast");
				$prev.find("div.newsItemDate").find("a").html("+");	
					}
				$(".yearFilter select option").each(function(){
				$(".newsItemsContainer" + $(this).val()).hide();
		})
		$(".newsItemsContainer" + $(this).val()).show();
		if ($lnkAward=="")
					{
		$(".newsItemsContainer" + $(this).val() + " .newsItem:first .newsItemContent").css("display", "block");
		$(".newsItemsContainer" + $(this).val() + " .newsItem:first .newsItemDate").find("a").html("")
		$prev = $(".newsItemsContainer" + $(this).val() + " .newsItem:first");
					}
		});	   
	 }	

// News Landing page Video

if($("#video")) 
	{
		$("#video img").click(function () { $(this).fadeOut(); $("#video div").fadeIn(); });	   
	}
	

// Services section scroll to book mark

$(".scroll").click(function(event){
		event.preventDefault();
		var full_url = this.href;
		var cur_url = window.location.href;
		var parts = full_url.split("#");
		var cur_parts = cur_url.split("#");
		var trgt = parts[1];
	if(parts[0]==cur_parts[0])
	{
		
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top - 61;
		$('html, body').animate({scrollTop:target_top}, 500);
		$(".navContainer ul.level1 li").removeClass("hover");
	}
	else if (parts[1]=='top')
	{	
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top - 61;
		$('html, body').animate({scrollTop:target_top}, 500);
			
	}
	else 
	{	
		window.location.href = full_url;
		//window.location.replace(full_url);
		
	}
	
	});
	
	checkBookmark();
	
});


function showDiv(id) {
	document.getElementById(id).style.display = "block";
}
function hideDiv(id) { 
	document.getElementById(id).style.display = "none";
}
