

/**
* Any functions we want run after the page has loaded.
*/



/**
* hide the dropdown navs....
*/
$(document).ready(function() {

	$("#nav ul li > ul").css('display','none');

    $("#nav ul li").hover
    (
       	function(){
       		if( $.browser.msie )
       		{
       			$("ul", this).slideDown("slow");
       		}
       		else
       		{
        			$("ul", this).fadeIn("slow");
       		}
		},
        function() {

        	$("ul", this).fadeOut("fast");
        }
    );


	/**
	* see if we're on a news detail page
	*/
	if($('#downScrollLink').attr('id') != undefined && $('#downScrollLink').attr('id') != '' )
	{
		$(".sub_intro_bold").css("width","600px");
		$(".sub_intro_bold").css("clear","both");
		$(".sub_intro_bold").css("height","50px");

		/**
		* see if we need scroll up/down links
		*/
		if($('#newsContnet').height() > $('#newsContainer').height() )
		{
			$("#newsScroll").css("display","block");
		}
		$('#newsScroll').height($('#newsContainer').height());


		$("#newsContnet").css("width","470px");
		$("#newsContainer").css("overflow","hidden");

	}


	/**
	* Scrolling the news items.
	*/
	$("#downScrollLink").mouseover( function() {
		scrollDown('-');
		scrollDirectionNews = setInterval ( "scrollDown('-')", 1500 );
	 } );
	$("#upScrollLink").mouseover( function() {
		scrollUp('+');
		scrollDirectionNews = setInterval ( "scrollUp('+')", 1500 );
	 } );

	/**
	* reset the scrolling on mouse out.
	*/
	$("#downScrollLink,#upScrollLink").mouseout( function() {
		clearInterval(scrollDirectionNews);
	 } );
	/**
	* throw away the clicks...
	*/
	$("#downScrollLink,#upScrollLink").click( function() {
		return false;
	});

	/**
	* for the news list items
	*/
	$("#moreNewsLink").click(function() {

	    var curMarginLeft = parseInt($("#hot_jobs_list").css('margin-left'));
	    var totalWidth = parseInt($("#hot_jobs_list").width());

		if((curMarginLeft + totalWidth) > 310 )
		{
		 	$("#hot_jobs_list").animate( { marginLeft:"-=310px" } , 1000 );
		}
		return false;
	});

	$("#lessNewsLink").click(function() {

	    var curMarginLeft = parseInt($("#hot_jobs_list").css('margin-left'));
	    var totalWidth = parseInt($("#hot_jobs_list").width());

		if((curMarginLeft + totalWidth) < totalWidth )
		{
		 	$("#hot_jobs_list").animate( { marginLeft:"+=310px" } , 1000 );
		}
		return false;
	});
	/**
	* end for the news list items
	*/

});

	$.fn.hoverClass = function(c) {
    	return this.each(function(){
        	$(this).hover(
        	    function() { $(this).addClass(c);  },
        	    function() { $(this).removeClass(c); }
        	);
    });

};

	function scrollUp()
	{
		var top = parseInt($("#newsContnet").css('margin-top'));
		var height = parseInt($("#newsContnet").height());

		if(top < 0 )
		{
			$("#newsContnet").animate( { marginTop:"+=100px" } , 1000 )
		}
	}

	function scrollDown()
	{
		var top = parseInt($("#newsContnet").css('margin-top'));
		var height = parseInt($("#newsContnet").height());

		if( (top + height) > 200 )
		$("#newsContnet").animate( { marginTop:"-=100px" } , 1000 )
	}

	/**
	*
	*/
	function hideShowNav(ObjId,ObjDirection)
	{
		//alert( 'HERE' );

		ActiveDropDownId = ObjId;

		var aDropDowns = Array('about_us','about_the_role','what_we_offer');

		for(i=0; i<aDropDowns.length; i++)
		{
			//alert(aDropDowns[i]);
			if(ObjId != aDropDowns[i]) $("#"+aDropDowns[i]+"-ul").slideUp('slow');
		}

		if(ObjDirection == 'slideDown')
		{
			if( $("#"+ObjId+"-ul").css('display') != 'block' )
			$("#"+ObjId+"-ul").slideDown('slow');
		}
		else
		{

			$("#"+ObjId+"-ul").slideUp('slow');
		}

	}

/**
* Sets up the mouse sactions for the submit buttons on document load
*/
$(document).ready(function() {
	applySubmitButtons();
});


/**
* sets the click actions for the company values page
*/
$(document).ready(function() {
	setCompanyValuesClick();
});


/**
* Sets the mouseover/out for the value buttons
*/
$(document).ready(function() {
	setMouseFunctions();
});


function setMouseFunctions()
{

	//We're on the clients page so lets set up the mouse over/out functions for the 'tabs'
	// var 'aValues' is written in on the page through PHP

	if(window.aValues !== undefined)
	{

		for (key in aValues)
		{
			// For the axctual tab buttons

			$("#"+aValues[key]).mouseover(function() {
				fade_value_out(this.id);
			});

			$("#"+aValues[key]).mouseout(function() {
				fade_value_in(this.id);
			});

			// for the map over the initial image

			$("#map-link-"+aValues[key]).mouseover(function() {
				fade_value_out(this.className);
			});

			$("#map-link-"+aValues[key]).mouseout(function() {
				fade_value_in(this.className);
			});
		}
	}
}



/**
* Sets up the mouseover actions for the hot jobs & submit cv pages
*/
function applySubmitButtons() {

	if(document.getElementById('apply_button') != undefined)
	{
			/*
			$("#apply_button_href").click(function() {
			setApplyButton();
			// IMPORTANT
			return false;
			});
			*/

			$("#apply_button").mouseover(function() {
				swapimage('apply_btn_over.gif','apply_button');
			});

			$("#apply_button").mouseout(function() {
				swapimage('apply_btn.gif','apply_button');
			});
	}

	if(document.getElementById('submit_button') != undefined)
	{
			$("#submit_button_href").click(function() {
			setSubmitButton();
			/** IMPORTANT **/
			return false;
			});

			$("#submit_button").mouseover(function() {
				swapimage('submit_cv_btn_over.gif','submit_button');
			});

			$("#submit_button").mouseout(function() {
				swapimage('submit_cv_btn.gif','submit_button');
			});
	}
}


function swapimage(img,obj) {
	document.getElementById(obj).src = '/images/buttons/'+img;
}




/**
* Opens up the SCVA in a pop up.
*/
function setApplyButton(){
		var objRef = document.getElementById('apply_button_href').href;
		/**
		* open the pop-up
		*/
		window.open(objRef, 'HuxleyInternal', 'scrollbars=no,location=no,toolbar=no,status=no,width=500,height=368');
}

/**
* Opens up the SCVA in a pop up.
*/
function setSubmitButton(){
		var objRef = document.getElementById('submit_button_href').href;
		/**
		* open the pop-up
		*/
		window.open(objRef, 'HuxleyInternal', 'scrollbars=no,location=no,toolbar=no,status=no,width=500,height=368');
}

/**
* Fades an image OUT
* based on the ID of the image
*/
function fade_value_out(element_id) {
	element_id = "#"+element_id;
	$(element_id).fadeTo("fast", .6);
}

/**
* Fades an image IN
* based on the ID of the image
*/
function fade_value_in(element_id) {
	element_id = "#"+element_id;
	$(element_id).fadeTo("slow", 1);
}


function setCompanyValuesClick()
{

	//We're on the clients page so lets set up the mouse click functions for the 'tabs'
	/**
	* var 'aValues' is written in on the page through PHP
	*/
	if(window.aValues !== undefined)
	{
		for (key in aValues)
		{

			// for the actual tab buttons

			$("#"+aValues[key]).click(function() {
				swapMainImage(this.id);
				fadeOutCompanyValues(this.id);
				/** IMPORTANT **/
				return false;
			});

			// for the image map
			$("#map-link-"+aValues[key]).click(function() {
				swapMainImage(this.className);
				fadeOutCompanyValues(this.className);
				/** IMPORTANT **/
				return false;
			});

		}
	}
}


function swapMainImage(obj)
{
	var href = document.getElementById("link-"+obj);
	href.href = '#';

	// remove all the mouse over functions for the new object

	$("#"+obj).unbind();

	$("#"+obj).click(function() {
		swapMainImage(this.id);
		fadeOutCompanyValues(this.id);
		// IMPORTANT
		return false;
	});


	// set the color to 'bright' for the new current object.
	fade_value_in(obj);

	var cur_element_id = '#noFlash-sub-company_values';

	//remove the map from the spacer gif so the links nolonger work!!
	$("#company_values-map").html("");


	// change the image to the background required!!
	// for the div behind the current image div
	$("#company_values_1").css("background", "url(/images/values/value-"+obj+"-img.jpg)");


	// Slide down the current div to reveal the above image
	// When this has compleated we need to swap the above two divs around
	$("#company_values_1").slideDown(900,function(){ swapDivs(cur_element_id); });

	window.sCurrentValue = obj;

	// now change other value buttons behaviour - except for the current to fade out.

	for (key in aValues)
	{
		// if we're not the current 'value' button
		if( aValues[key] != window.sCurrentValue )
		{
			// set the color to 'fade'
			fade_value_out(aValues[key]);

			// mouse over: fade IN
			$("#"+aValues[key]).mouseover(function() {
				fade_value_in(this.id);
			});

			// mouse out: fade OUT
			$("#"+aValues[key]).mouseout(function() {
				fade_value_out(this.id);
			});
		}
	}

}


function fadeOutCompanyValues(obj)
{

	// fade out the existing text Bold Text
	// Then fade in the new content....
	$(".sub_intro_bold").fadeOut("slow",function(){ fadeInCompanyValues(obj); });

	// fade out the existing main text
	$(".sub_main_content").fadeOut("slow");

	// fade out the sub h1
	$("#main_H1").fadeOut("slow");


}

function fadeInCompanyValues(obj)
{

	//set the css from hidden to true;
	$("#values-sub-header").css("overflow", "visible");

	// get the existing h1 tag //
	var existingH1 = $("#main_H1").html();

	//put in the H1 tag for this page
	$("#values-sub-header").html('<h1 class="pageTitle header_company_values" title="Company Values">Company Values</h1>');

	//put in the H1 tag for this page
	$("#main_H1").html('<h1 class="pageTitle header_company_values-'+obj+'" title="Company Values: '+obj+'">Company Values: '+obj+'</h1>');


	// get the new text for the the selected 'value';
	var newText = $("#company_values_bold_text-"+obj).html();

	// put this into the bold holder
	$(".sub_intro_bold").html(newText);

	// get the new main content text for the the selected 'value';
	var newMainText = $("#company_values_main_contnet_text-"+obj).html();

	// put this into the main content  holder
	$(".sub_main_content").html(newMainText);

	// fade this text in....
	$(".sub_intro_bold").fadeIn("slow");

	// fade in the new H1 for this value
	$("#main_H1").fadeIn("slow");

	// fade out the existing main text
	$(".sub_main_content").fadeIn("slow");


	$("#link_holder").removeClass("hidden_content");

	// fade in the 'back to values' link
	//$("#link_holder").fadeIn("slow");


}

function swapDivs(obj)
{
	var cover_div = $("#company_values_1").css("background");

	// set the #noFlash-sub-company_values background image to match #company_values_1
	$("#noFlash-sub-company_values").css({"background":cover_div});

	// IMPORTANT !!
	// IE Will not allow you to set more than 1 Css attribute at a time!!
	// $("#company_values_1").css({"position":"relative;","margin":"0;","padding":"0;","display":"none;"});

	$("#company_values_1").css("position", "relative");
	$("#company_values_1").css("margin", "0");
	$("#company_values_1").css("display", "none");

	var cover_div = $("#company_values_1").css("background");
	var base_div = $(obj).css("background");
}


/*
-------------------------------------------------------
UNUSED - put back in later!!


function valueMouseState(element_id)
{

	// are we on a values page?

	if(window.sCurrentValue === undefined)
	{

		// no current value set so
		// fade this to .6 opacity


		var element = "#"+element_id;

		$(element).mouseover(function() {
			fade_value_out(element_id);
		});

		$(element).mouseout(function() {
			fade_value_in(element_id);
		});
	}
	else
	{

		// There is a current value
		// if this id is NOT the id of the current value fade it in

		if(window.sCurrentValue != element_id) {
			fade_value_in(element_id);
		}
	}

}

*/