// JavaScript Document
var myRotatingImage= new Array();
function defineSector(chooseSector) {
	if (chooseSector == 'Building & Civil Engineering and <br /><br /> Structural Steel & Building Envelope') {
	  document.getElementById('rotatingimageholder').style.backgroundImage="url('/images/sector_animation/blue_building_and_plans.jpg')"
	  myRotatingImage[0] = "/images/sector_animation/blue_building_and_plans.jpg";
	  myRotatingImage[1] = "/images/sector_animation/builder.jpg";
	  myRotatingImage[2] = "/images/sector_animation/building_and_cranes.jpg";
	  myRotatingImage[3] = "/images/sector_animation/two_builders.jpg";
	  myRotatingImage[4] = "/images/sector_animation/blue_building_and_plans.jpg";
	}

	if (chooseSector == 'Rail') {
	  document.getElementById('rotatingimageholder').style.backgroundImage="url('/images/sector_animation/fast_train_heading_right.jpg')"		
	  myRotatingImage[0] = "/images/sector_animation/fast_train_heading_right.jpg";
	  myRotatingImage[1] = "/images/sector_animation/rail_track.jpg";
	  myRotatingImage[2] = "/images/sector_animation/train_fast.jpg";
	  myRotatingImage[3] = "/images/sector_animation/train_heading_out.jpg";
	  myRotatingImage[4] = "/images/sector_animation/rail_track.jpg";
	}
	
	if (chooseSector == 'Medical Device, Pharma and Bio Tech') {
	  document.getElementById('rotatingimageholder').style.backgroundImage="url('/images/sector_animation/globe.jpg')"	
	  myRotatingImage[0] = "/images/sector_animation/globe.jpg";
	  myRotatingImage[1] = "/images/sector_animation/medical6.jpg";
	  myRotatingImage[2] = "/images/sector_animation/medical_utensils.jpg";
	  myRotatingImage[3] = "/images/sector_animation/globe.jpg";
	  myRotatingImage[4] = "/images/sector_animation/medical6.jpg";
	}
	
	if (chooseSector == 'Information Technology And Telecoms') {
	  document.getElementById('rotatingimageholder').style.backgroundImage="url('/images/sector_animation/it_computer.jpg')"	
	  myRotatingImage[0] = "/images/sector_animation/it_computer.jpg";
	  myRotatingImage[1] = "/images/sector_animation/it_telecoms_blue_building.jpg";
	  myRotatingImage[2] = "/images/sector_animation/hand_laptop.jpg";
	  myRotatingImage[3] = "/images/sector_animation/it_computer.jpg";
	  myRotatingImage[4] = "/images/sector_animation/it_telecoms_blue_building.jpg";
	}
	
	if (chooseSector == 'Sales And Commercial') {
	  document.getElementById('rotatingimageholder').style.backgroundImage="url('/images/sector_animation/women_man_sales.jpg')"	
	  myRotatingImage[0] = "/images/sector_animation/women_man_sales.jpg";
	  myRotatingImage[1] = "/images/sector_animation/stock_figure.jpg";
	  myRotatingImage[2] = "/images/sector_animation/glasses_calculator.jpg";
	  myRotatingImage[3] = "/images/sector_animation/call_centre_worker.jpg";
	  myRotatingImage[4] = "/images/sector_animation/glasses_calculator.jpg";
	}
	
	if (chooseSector == 'Utilities') {
	  document.getElementById('rotatingimageholder').style.backgroundImage="url('/images/sector_animation/utilities_man.jpg')"
  	
	  myRotatingImage[0] = "/images/sector_animation/utilities_man.jpg";
	  myRotatingImage[1] = "/images/sector_animation/utilities_telephone_lines.jpg";
	  myRotatingImage[2] = "/images/sector_animation/pipes_utilities.jpg";
	  myRotatingImage[3] = "/images/sector_animation/bridge.jpg";
	  myRotatingImage[4] = "/images/sector_animation/utilities_telephone_lines.jpg";
	}
	
	if (chooseSector == 'Executive Search And Selection') {
	  document.getElementById('rotatingimageholder').style.backgroundImage="url('/images/sector_animation/exec_handshake.jpg')"	
	  myRotatingImage[0] = "/images/sector_animation/exec_handshake.jpg";
	  myRotatingImage[1] = "/images/sector_animation/exec_sillouette.jpg";
	  myRotatingImage[2] = "/images/sector_animation/boardroom.jpg";
	  myRotatingImage[3] = "/images/sector_animation/telephone_globe.jpg";
	  myRotatingImage[4] = "/images/sector_animation/boardroom.jpg";
	}
	
	if (chooseSector == 'Engineering And Technical' ) {
		document.getElementById('rotatingimageholder').style.backgroundImage="url('/images/sector_animation/furnace.jpg')"	
	  myRotatingImage[0] = "/images/sector_animation/furnace.jpg";
	  myRotatingImage[1] = "/images/sector_animation/steel_pipes.jpg";
	  myRotatingImage[2] = "/images/sector_animation/cog.jpg";
	  myRotatingImage[3] = "/images/sector_animation/drill.jpg";
	  myRotatingImage[4] = "/images/sector_animation/factory.jpg";
	}
	
	if (chooseSector == 'Hospitality, Leisure and Sports (HLS)' ) {
		document.getElementById('rotatingimageholder').style.backgroundImage="url('/images/sector_animation/chefs.jpg')"	
	  myRotatingImage[0] = "/images/sector_animation/chefs.jpg";
	  myRotatingImage[1] = "/images/sector_animation/hotel_sign.jpg";
	  myRotatingImage[2] = "/images/sector_animation/restaurant.jpg";
	  myRotatingImage[3] = "/images/sector_animation/dining_tables.jpg";
	  myRotatingImage[4] = "/images/sector_animation/stadium.jpg";
	}
}
	
var currentImage = 0;
var currentLocation = 0;
var countNumber = 0;
var fadeIn=false;

function displayrandomImages() {
	$("#rotatingimageholder").fadeOut(0);
	changeImage();
	setInterval("changeImage()",2500);
	//setInterval("imagerandomiser()",3000);
	//changeImage(false);
}

function imagerandomiser() {
	if (countNumber != 4) {
	  countNumber = countNumber + 1
	} else {
	  countNumber = 0
	}
	//randomnumber=Math.floor(Math.random()*5);
}

function changeImage() {
	if(fadeIn) {
		fadeIn=false;
		$("#rotatingimageholder").fadeOut(2400);
	} else {
		fadeIn=true;
		$("#rotatingimageholder").css("background-image", "url(" + myRotatingImage[countNumber] + ")");
		$("#rotatingimageholder").fadeIn(2400);
		countNumber++;
		if(countNumber>4){
		  countNumber=0;
	  }
  }
}

/*
function animateSector() {
	//document.getElementById().
	//alert('test')
	// $('#imageContainer').hide("slide", { direction: "left" }, 5000);
	//$("#imageContainer").slideDown("slow");
	//alert('here')
	setInterval('triggerAnimation1()',3000 )
	}

function triggerAnimation1() {
	$("#imageContainer").fadeOut(3000, function() {   
	triggerAnimation2()
});
}
	
function triggerAnimation2() {
	$("#imageContainer2").fadeOut(3000, function() {
});
	document.getElementById('imageContainer').style.zIndex=
	$("#imageContainer").fadeIn(1, function() {   
	document.getElementById('imageContainer').style.backgroundImage="url('/images/sector_animation/two_builders.jpg')";
	});
	}	
*/

// JavaScript Document
function findLeft(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		while (obj = obj.offsetParent) curleft += obj.offsetLeft;			
	}
	return curleft;
}

function findTop(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {curtop += obj.offsetTop}
	}
	return curtop;
}
var StoreButtonpressed
function showGreyMenu(subID, menuItem,changeBgAndColour) {
		//StoreButtonpressed = changeBgAndColour
		//document.getElementById(changeBgAndColour).style.width='238px';
		//document.getElementById(changeBgAndColour).style.right='4px';
		//document.getElementById(changeBgAndColour).style.backgroundImage="url(/images/rightPanel/right_panelhighlighted.jpg)"
		//document.getElementById(changeBgAndColour).style.color="#FFFFFF"
		//var subMenu = document.getElementById(subID);
		//if(menuItem) {
		  //	document.getElementById(subID).style.left ='543px';
		  //	document.getElementById(subID).style.top = '177px';
		//}
		//subMenu.style.display = '';
}

function hideSubMenu(subID, changeBgAndColour) {
  document.getElementById(changeBgAndColour).style.backgroundImage="url(/images/rightPanel/right_panelunhighlighted.jpg)"
  document.getElementById(changeBgAndColour).style.color="#646464"
  document.getElementById(subID).style.display = 'none';
  document.getElementById(changeBgAndColour).style.width='234px';
  document.getElementById(changeBgAndColour).style.right='0px';
}

function showGreyMenu2(subID) {
	document.getElementById(subID).style.display = '';
	document.getElementById(StoreButtonpressed).style.backgroundImage="url(/images/rightPanel/right_panelhighlighted.jpg)"
	document.getElementById(StoreButtonpressed).style.color="#FFFFFF"
	document.getElementById(StoreButtonpressed).style.width='238px';
  document.getElementById(StoreButtonpressed).style.right='4px';
}

function hideSubMenu2(subID) {
  document.getElementById(subID).style.display = 'none';
  document.getElementById(StoreButtonpressed).style.backgroundImage="url(/images/rightPanel/right_panelunhighlighted.jpg)"
  document.getElementById(StoreButtonpressed).style.color="#646464"
}

//Image preloader
var newImage, imageList, preloadCount, preloadInterval;
	var preloadCount = 0;
	imageList = new Array();
	
	function addPreloadImage(url)
	{
		imageList[imageList.length] = url;
	}
	
	function startPreloading()
	{ 
		if(imageList.length != 0)
		{
			newImage = new Image;
			newImage.src = imageList[0]
			preloadInterval = setTimeout('preloadCheck()', 1000);
		}
	}
	
	function preloadCheck()
	{
		if (newImage.complete)
		{
			preloadCount += 1;
			if (preloadCount < imageList.length)
			{
				newImage.src = imageList[preloadCount];
				clearInterval(preloadInterval);
				preloadInterval = setTimeout('preloadCheck()', 1000);
			}
			else
			{
				clearInterval(preloadInterval);
			}
		}
	}
	
	function imageSwap(key, url)
	{
		eval('document.' + key + '.src = \'' + url + '\'');
	}
	
	
	
		var newImage, imageList, preloadCount;
	var preloadCount = 0;
	imageList = new Array();
	
	function addPreloadImage(url)
	{
		imageList[imageList.length] = url;
	}
	
	function startPreloading()
	{ 
		newImage = new Image;
		newImage.src = imageList[0]
		setInterval('preloadCheck()', 1000);
	}
	
	function preloadCheck()
	{
		if (newImage.complete)
		{
			preloadCount += 1;
			if (!preloadCount >= imageList.length)
			{
				newImage.src = imageList[preloadCount];
				setInterval('preloadCheck()', 1000);
			}
		}
	}
	
	function imageSwap(key, url)
	{
		eval('document.' + key + '.src = \'' + url + '\'');
	}

	function swapSky(key, mouseOn)
	{
		if (!mouseOn) eval('document.' + key + '.src = \'/images/services/' + key + '.gif\'');
		else eval('document.' + key + '.src = \'/images/services/' + key + 'Light.gif\'');
	}

	function mailto(recipient)
	{
		document.location.href = 'mailto:' + recipient + '@tekpersonnel.co.uk?subject=Website Enquiry';
	}
	
	function goTo(url)
	{
		document.location.href = url;
	}

	function openWindow(url, width, height, sizeable)
	{
		if (sizeable) sizeable = ',resizable,scrollbars'
		else sizeable = '';
		var openWin = window.open(url,'_blank','width=' + width + ',height=' + height + ',screenX=' + ((screen.availWidth-width)/2) + ',left=' + ((screen.availWidth-width)/2) + ',screenY=' + ((screen.availHeight-height)/2) + ',top=' + ((screen.availHeight-height)/2) + sizeable);
		openWin.focus();
	}
	
//#-- VARIABLE TO TRACK IF CURRENT FORM FIELD IS A TEXT AREA - IF SO, microsoftKeyPress SHOULDN'T RUN
var textArea = false;
//#-- FUNCTION TO HANDLE KEYPRESSES IN IE BROWSERS
	function microsoftKeyPress() 
	{	
		if (!textArea)
		{
	  	  if (window.event.keyCode == 13)
			{
				submitForm();
				window.event.returnValue = false;
			}
		}
	}
	
	
	
	
	function displayJobs(divtoHide)
	{
		document.getElementById(divtoHide).style.display = '';
		}
		
	function hideJobs(divtoHide)
	{
		document.getElementById(divtoHide).style.display = 'none';
		}
		
		
		
	function alternateJobsOnHomepage()
	{
		
		}
		
		
	function submitregisterform()
		{
		document.registration_form.action = '/jobs/register.asp';
		document.registration_form.submit();
		}
		
		function test(evt)
		{
			var keyCode = (evt.which) ? evt.which : event.keyCode

			if (keyCode == 13)
			{
				if (document.registration_form.name.value != '' || document.registration_form.email.value !='')
				{
				submitregisterform()
				}
		    }
		}	
		
		
		function hidetop20List(nameOfList)
		{
		document.getElementById(nameOfList).style.height='1px';
		document.getElementById(nameOfList).style.borderTop="solid 3px #FFFFFF";
		document.getElementById(nameOfList).style.borderLeft="solid 3px #FFFFFF";
		document.getElementById(nameOfList).style.backgroundColor="#FFFFFF";
		}
		
		function showtop20List(nameOfList)
		{
		document.getElementById(nameOfList).style.height='auto';
		document.getElementById(nameOfList).style.borderTop="solid 3px #BCBCBC";
		document.getElementById(nameOfList).style.borderLeft="solid 1px #BCBCBC";
		document.getElementById(nameOfList).style.backgroundColor="#F1F1F1";
		}
		
