function submit_form(form_id)
{
	if( form_id == undefined || form_id == null ) return false;
	$('form#'+form_id).submit();
	return true;
}
function load_link(href)
{
	window.location  = href;
	return true;
}

function submitCV(response_uri)
{
	window.open(response_uri,'cva','width=500,height=370');
}

function processAfterAnimation(imgRef,second)
{
	$(imgRef).remove();
	$(second).attr('id','');
	$(second).addClass(imgRef.replace('.',''));
	$('.imgNav').animate({opacity: "100"}, 1000);
}

function debug(what, clearText)
{
	/* ONLY ALLOW DEBUG ON DEV */
	if( window.location.href.indexOf('http://dev.') < 0 )
	{
		return true;
	}
	if( $('div#js_debug').attr('id') != 'js_debug' )
	{
		$('body').prepend('<div id="js_debug" style="height:300px;padding:2px;border:2px solid #ff6600;z-index:999999;position:absolute;background:#ffffff;color:#000000;width:200px; text-align:left;"><div id="debug_drag" style="background:#666666; color:#ffffff; padding:3px;"><h5 style="color:#ffffff;">Js Debug info</h5></div><div id="drag_content" style="overflow:auto;height:280px; color:#333333; font-size:.85em;"></div></div>');
		$('div#debug_drag').css('cursor','move');

		$('div#js_debug').dblclick(function()
		{
			$('div#js_debug').css('display','none');
		});

		$("#js_debug").draggable({
		    handle: "div#debug_drag"
		});
	}
	else if( $('div#js_debug').css('display') == 'none' )
	{
		$('div#js_debug').css('display','block');
	}
	var cContents = $('#js_debug #drag_content').html();

	if( typeof(clearText) != 'undefined' )
	{
		cContents = what+"<br />";
	}
	else
	{
		cContents = what+"<br />" + cContents;
	}

	$('#js_debug #drag_content').html(cContents);
}

function removeClass(obj,className)
{
	$(obj).removeClass(className);
}

function getMouseOverNavClass(oDom)
{
	var aClasses = oDom.split(' ');
	for(var i=0; i<aClasses.length; i++)
	{
		if( aClasses[i].indexOf('nav_') == 0 )
		{
			return aClasses[i];
		}
	}
}


function AddMouseOver(obj)
{

	/*If the clients news letter is active, HIDE IT*/
	if( $('#hiddenNewsLetter').css('display') == 'block' )
	{
		$('#hiddenNewsLetter').css('display','none');
		$('li.filler').remove();
	}

	$('ul#nav').removeClass();
	$('ul#subnav').removeClass();

	$('ul#nav').addClass(gActiveClass);
	$('ul#subnav').addClass('sn_'+gActiveClass);

	$('ul#subnav li.current_nav').css('opacity','0');
	$('ul#subnav li.current_nav').css('display','none');
	$('ul#subnav li').removeClass('current_nav');
	$('ul#subnav li.'+iNewSubnav).addClass('current_nav');
	$('ul#subnav li.'+iNewSubnav).css('opacity','0');
	$('ul#subnav li.'+iNewSubnav).css('display','block');
	$('ul#subnav li.'+iNewSubnav).css('opacity','1');
}

function RestoreMenuToDefault()
{
	gActiveClass = getMouseOverNavClass($('ul#nav li a.sel').parent().attr('class'));
	iNewSubnav = gActiveClass;

	$('#nav li a').removeClass('navHover');
	$('ul#nav,ul#subnav').removeClass();
	AddMouseOver(gActiveClass);
	$('ul#nav,ul#subnav').removeClass();


}

function clearTimeOutRotateHomeImage()
{
	if( typeof( tRestoreMenuToDefault ) == 'number' )
	{
		clearTimeout(tAnimateHomeImage);
	}
}

function rotateHomeImage (){
	$('#leftContent .jcarousel-next').click();
	tAnimateHomeImage = setTimeout("rotateHomeImage()",30000);
}


jQuery().ready(function(){

	//bookmark this site script
	$('li#bookmark a').click( function(){


		var url = window.location.href;
		var title = "Computer Futures";

		if (window.sidebar)
		{ // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"hh");
		}
		else if( window.external )
		{ // IE Favorite
			window.external.AddFavorite( url, title);
		}
		else if(window.opera && window.print)
		{ // Opera Hotlist
			return true;
		}

		return false
	})

	//show the print button....
	$('div#content ul.jobOptions li a.print').css('display','block');
	$('div#content ul.jobOptions li a.print').click( function()
	{
		window.print();
		return true;
	});

	$('#homeImg').jcarousel({
		start: 1,
		scroll: 1,
		animation: 'slow',
		easing: 'linear',
		buttonNextCallback: clearTimeOutRotateHomeImage,
		buttonPrevCallback: clearTimeOutRotateHomeImage
	});

	//set a timeout for 30 seconds to activate the sliding on the main menu
	tAnimateHomeImage = setTimeout("rotateHomeImage()",30000);



	$('#promo_1,#promo_2,#promo_3').jcarousel({
		start: 1,
		scroll: 1,
		animation: 'slow',
		easing: 'linear'
	});

	$('.jcarousel-skin-promo').each(function(){

		$(this).addClass( 'm_'+$('div div ul',this).attr('id') );
	})

	/**
	Resize random image left content
	*/
	if( $('#leftContent img#randImg').attr('id') == 'randImg' )
	{
		$('#leftContent').css('overflow','hidden');
		var sHeight = $('#content').height();
		if( sHeight < '340' ) sHeight = '340';
		$('#leftContent').css('height',sHeight+'px');
	}

	/**
	* for the showhide of the clients newsletter
	*/
	$('li.client_news_letter').mouseover(function()
	{

		if( $('div#hiddenNewsLetter').attr('id') != 'hiddenNewsLetter' )
		{
			//allows the menu item to work correctly when actuall on the newsletter page.
			return false;
		}

		/**
		* don't got to the page we'll handle it here.
		*/
		$('a',this).bind('click',function(){
			return false;
		})

		if( typeof( tRestoreMenuToDefault ) == 'number' )
		{
			clearTimeout(tRestoreMenuToDefault);
		}

		//Override the normal css for this hover
		$('li.client_news_letter a').css('background-position','92% 7px');
		$('li.client_news_letter a').css('background-color','#3198A8');


		// if the form isn't being displayed....
		if( $('#hiddenNewsLetter').css('display') == 'none' )
		{

			//add a new li to fix the color background issue
			var iNewLiWidth =	(($('#hiddenNewsLetter').width() - $('li.client_news_letter a').width())-32);
			$('li.client_news_letter').after('<li class="fr filler">&nbsp;</li>');
			$('li.filler').css('width',iNewLiWidth+'px');

			$('#hiddenNewsLetter,li.filler,#newsLetterClose').fadeIn('slow');

			$('#newsLetterClose a').bind('click',function(){
				$('#hiddenNewsLetter,li.filler').fadeOut('slow', function(){
					// hide the filler li
					$('li.filler').remove();
					// remove the error notice
					if( $('#hiddenNewsLetter form div.error' ).attr('class') == 'error' )
					{
						$('#hiddenNewsLetter form div.error').remove();
					}

					//restore the default menu...
					tRestoreMenuToDefault = setTimeout("RestoreMenuToDefault()",6000);

				});
				return false;
			});

			// process the clients newsletter submission
			$('#hiddenNewsLetter form').submit(function()
			{
				//check the email address
				if( $('#hiddenNewsLetter input[@name^=element_email]').val() == "" )
				{
					if( $('#hiddenNewsLetter div.error' ).attr('class') != 'error' )
					{
						$('#hiddenNewsLetter form').prepend('<div class="error" style="display:none">'+window.sEmailEmpty+'</div>');
						$('#hiddenNewsLetter form div.error').slideDown('200');
					}
					else
					{
						$('#hiddenNewsLetter form div.error' ).animate({ opacity: 0.7},200).animate( { opacity: 1} , 300 );
					}
					return false;
				}

				if( $('#hiddenNewsLetter form div.error' ).attr('class') == 'error' )
				{
					$('#hiddenNewsLetter form div.error' ).slideUp('200',function(){
						$('#hiddenNewsLetter form div.error' ).remove();

					})
				}

				//fade out the form for submission
				$('#hiddenNewsLetter form' ).animate({ opacity: 0.7},200);

				$.post('/index.php?Mode=page&page=clients_newsletter&casing=blank',{FromAjax:"true",element_email_clients_newsletter: $('input[@name=element_email_clients_newsletter]').val()},
				  function(data){
				  	if( data == 'success' )
				  	{
				  		//hide and remove the form....
				  		$('#hiddenNewsLetter form').fadeOut(400, function()
				  		{
				  			$('#hiddenNewsLetter form').remove();
				  			//show the success field...
				  			$('#hiddenNewsLetter').prepend('<div class="form_success">'+window.sFormSubmissionSuccess+'</div>');
				  		})
				  	}
				  	else if( data == 'fail' )
				  	{
				  		$('#hiddenNewsLetter form' ).animate({ opacity: 1},200);
				  		$('#hiddenNewsLetter form').prepend('<div class="error">'+window.sEmailInValid+'</div>');
				  	}
				  });

				return false;
			});
		}
	});

	if( $('#staff_start_date').attr('id') == 'staff_start_date' )
	{
		//add the date picker to start date on staff match page
		$("#staff_start_date").datepicker({
		    duration: "slow",
		    dateFormat: "dd/mm/yy"
		});
	}

	//hover the subnav...
	$('ul.subnav li a').hover(
		function(){
			if( typeof(iNewSubnav) != 'undefined' )
			{
				oLi = 'ul#nav li.'+iNewSubnav+' a';
			}
			else
			{
				oLi = 'ul#nav li a.sel';
			}
			$(oLi).addClass('mainNavOver');
			$('#nav').css("border-bottom-color", "#FF6600");

			if( typeof( tRestoreMenuToDefault ) == 'number' )
			{
				clearTimeout(tRestoreMenuToDefault);
			}
			//Global reset to the default menu display after 6 seconds
			tRestoreMenuToDefault = setTimeout("RestoreMenuToDefault()",6000);
		},
		function(){
			// we're on the current LIVE PAGE menu
			if( typeof(iNewSubnav) == 'undefined' || $('ul#nav li a.sel').parent().attr('class') == iNewSubnav )
			{
				$(oLi).removeClass('mainNavOver');
				$('#nav').css("border-bottom-color", "#3198A8");
			}
	})

	$('#nav li a').click(function()
	{
			if( typeof( tAddMouseOver ) == 'number' )
			{
				clearTimeout(tAddMouseOver);
			}
	});

	// hover the topnav
	$('#nav li a').hover(
		function(){

			if( typeof( tRestoreMenuToDefault ) == 'number' )
			{
				clearTimeout(tRestoreMenuToDefault);
			}

			//add the class to the nav and sub nav....
			gActiveClassNew = getMouseOverNavClass($(this).parent().attr('class'));

			if( $(this).attr('class').indexOf('sel') == 0 )
			{
				RestoreMenuToDefault();
				return true;
			}

			//Global reset to the default menu display after 6 seconds
			tRestoreMenuToDefault = setTimeout("RestoreMenuToDefault()",6000);

			iNewSubnav = gActiveClassNew;

			// if this item is not the current parent page, then add another np class
			if( $(this).attr('class').indexOf('sel') < 0 )
			{
				gActiveClassNew = gActiveClassNew+'_np';
				gNotDefaultPageMenu = true;
			}

			//remove any current class on the #nav and #subnav
			if( typeof(gActiveClass) != 'undefined' && gActiveClass != gActiveClassNew )
			{
				gOldClass = gActiveClass;
				$('#nav li a').removeClass('navHover');
			}

			gActiveClass = gActiveClassNew;
			$(this).addClass('navHover');
			tAddMouseOver = setTimeout("AddMouseOver('"+gActiveClass+"')",200);

			},
		function(){


			if( typeof( tAddMouseOver ) == 'number' )
			{
				clearTimeout(tAddMouseOver);
			}

			if( $(this).attr('class').indexOf('sel') >= 0 )
			{
				$(this).removeClass('navHover');
				$('ul#nav,ul#subnav').removeClass();
			}
	});

	//Get the current language of the site from the language menu
	var sSiteLang = $('ul.langbar li a.sel').html().toLowerCase();



	$('#OlrSearchResults td.olr_jt').click(function(){
		window.open($(this).children('a').attr('href'),'cand_cv', 'scrollbars=yes,width=700, height=600,resizable=yes');
	});


	// don't display the check boxes on the olr
	// use images instead.
	$('table input[@type=checkbox]').each(function(){
		 $(this).css('position', 'absolute');
		 $(this).css('marginTop', '-999em');
		 $(this).css('marginLeft', '-999em');

		// alert('img src="/img/lang/'+sSiteLang+'/btn/checkbox-off.gif');

	 $(this).parent('td').append('<img src="/img/lang/'+sSiteLang+'/btn/checkbox-off.gif" class="checkReplace">');
	});

	//check the hidden checkbox on td click
	//change the image to match
	$('#OlrSearchResults td.olr_ats').click(function(){
		if( $(this).attr('class') == 'olr_ats' )
		{
			switch( $(this).children('input').attr('checked') )
			{
				case true:
				$(this).find("input").attr('checked','');
				$(this).find("img").attr('src', $(this).find("img").attr('src').replace('-on.gif','-off.gif') )

				break;

				case false:
				$(this).find("input").attr('checked','checked');
				$(this).find("img").attr('src', $(this).find("img").attr('src').replace('-off.gif','-on.gif') )
				break;
			}
		}
		else
		{
		return true;
		}
	});


	//preload all mouseover form buttons
	$('form input[@type=image]').each(function(){
		if( $(this).attr('src').indexOf('spacer.gif') < 0 )
		{
			if( $('div#preLoad').attr('id') != 'preLoad' )
			{
				$('#wrapper').after('<div style="display:none;" id="preLoad"></div>');
			}
			$('#preLoad').prepend('<img width="1" height="1" src="'+$(this).attr('src').replace('-off.gif','-on.gif')+'"/>');
		}
	})


	//swap the form submission button[s] to over on mouseover
	$('form input[@type=image], img.click2animate').mouseover(function(){
		if( $(this).attr('src').indexOf('-on.gif') <= 0 )
		{
			var NewSubmit = $(this).attr('src').replace('-off.gif','-on.gif');
			$(this).attr('src',NewSubmit);
		}
	});

	$('form input[@type=image], img.click2animate').mouseout(function(){
		if( $(this).attr('src').indexOf('-off.gif') <= 0 )
		{
			var NewSubmit = $(this).attr('src').replace('-on.gif','-off.gif');
			$(this).attr('src',NewSubmit);
		}
	});


	//progress bar apply click
	$( 'ul#progressBar li#ps4 a, ul#subnav li.submit_cv a,a.submit_cv').click(function(){
		submitCV($(this).attr('href'));
		return false;
	});

	/*
	//swap the form submission button[s] to active on form submission
	$('form input[@type=image]').click(function(){

		if( $(this).attr('src').indexOf('img/spacer')> 0 )
		{
			return true;
		}

		if( $(this).attr('src').indexOf('_active.gif')> 0 ) return false;

		var NewSubmit = $(this).attr('src').replace('.gif','_active.gif');
		$(this).attr('src',NewSubmit.replace('-o_active.gif','_active.gif'));


		if( $(this).attr('class') == 'click2animate' && $(this).parent('a').attr('id') != 'apply_top' && $(this).parent('a').attr('id') != 'apply_bot' )
		{
			setTimeout('load_link("'+$(this).parent('a').attr('href')+'")',1);
			return false;
		}
		else if( $(this).parent('a').attr('id') == 'apply_top' || $(this).parent('a').attr('id') == 'apply_bot' )
		{
			submitCV($(this).parent('a').attr('href'));
			$(this).attr('restoreimage','yes');
			setTimeout('restorImg()',2000);
		}
		else
		{
			setTimeout('submit_form("'+$(this).parents().filter('form').attr('id')+'")',1);
			return false;
		}

	});
	*/

	//swap the icon image
	$('.selected_nav').parent().addClass('eleSelected');

	$('.iconChg').mouseover(function(){
		$(this).parent().addClass('eleHover');
	});

	$('.iconChg').mouseout(function(){
		$(this).parent().removeClass('eleHover');
	});

	//Apply button actions....
	$('#apply_top,#apply_bot,.scv, .bar_submit_cv').click(function(){
		submitCV($(this).attr('href'));
		return false;
	});

	//contact us page ONLY
	$("div.officeAddresses a").click(function(){

		var tCenter = $(this).attr('href').split('office=');
		aCenterLoc = tCenter[1].split('&');

		ZoomMap(aCenterLoc)

		return false;
	});
	///////////////////////////// end contact us page ////////////////

	sBackPos = '0px 0px';

	// Search Result page - style the whole row when mouseover.
	$(".tabularResults tbody tr").hover(function(){

		$(this).addClass('activeRowClick');
		sBackPos = $('.activeRowClick a.JobSearch_more').css('backgroundPosition');

		if( typeof(sBackPos) == 'undefined' )
		{
			sBackPos = '0px 0px';
		}

		$('.activeRowClick a.JobSearch_more').css('backgroundPosition','0px -100px');

	}, function(){
		$('.activeRowClick a.JobSearch_more').css('backgroundPosition',sBackPos);
		$(this).removeClass('activeRowClick');
	});

	$("#JobSearchResults tbody tr").click(function(){
		var sTheLink = $(this).find(".JobSearch_job_title a").attr('href');
		window.location = sTheLink;
	});

});

function restorImg()
{

	$('img').each(function(){
		if( $(this).attr('restoreimage') == 'yes' )
		{
			$(this).attr('src',$(this).attr('src').replace('-active.gif','-on.gif'));
			$(this).attr('restoreimage','');
		}
	})
}

function GotoContactPage(sLocation)
{
	var sLocation;
	var sCurLocation = window.location.href;
	if( sCurLocation.indexOf('?') >= 1 )
	{
		sLocation = sCurLocation+'&option='+sLocation;
	}
	else
	{
		sLocation = sCurLocation+sLocation+'/';
	}
	window.location = sLocation;
}

function ZoomMap(sLocation,iZoomOfficeLevel,oMarker)
{
		for (key in aOfficeLongLats)
		{
			if( key == sLocation )
			{
				var sOffice = key;
				aLatLong = aOfficeLongLats[key].split(',')
				var long = parseFloat(aLatLong[0]);
				var lat = parseFloat(aLatLong[1]);
			}
		}

		map.panTo(new GLatLng(long,lat));

		window.setTimeout(function() {
 				map.setCenter(new GLatLng(long,lat), iZoomOfficeLevel);
 				oMarker.setImage("/img/icons/google/pointer.png");
		}, 1000);

		/**
		* Now update the page to show the contact details....
		*/
		alert( sLocation.toLowerCase() );
		$('ul.officeList li ul li a.ol_'+sLocation.toLowerCase()).addClass('selected');


}
