// JavaScript Document

//Manpower.com

//jQuery(document).ready(onDocumentReady);
var localeCountry = null;
var localeLanguage = null;

//function onDocumentReady(){

	var cLink = checkCookie();
	if(cLink!=null){
		//alert(cLink);
		redirect(cLink);
	}else{
		detectLocale();
		jQuery('#country1').ready(onCountryReady1);			
		jQuery('#country2').ready(onCountryReady2);			
  	}
//} // onDocumentReady

function onCountryReady1(){
		jQuery('select#country1 option[value=' + localeCountry + ']').attr('selected', 'selected');
		jQuery('#country1').change(onCountryChange1);			
		loadLanguage1(localeCountry);
		$('#country1').mouseleave(function(event) { event.stopPropagation(); });
} // onCountryReady

function onCountryReady2(){
		jQuery('select#country2 option[value=' + localeCountry + ']').attr('selected', 'selected');
		jQuery('#country2').change(onCountryChange2);			
		loadLanguage2(localeCountry);
		$('#country2').mouseleave(function(event) { event.stopPropagation(); });
} // onCountryReady

function checkCookie(){
		var cLink = jQuery.cookie("Manpower");
		return cLink;
}

function setCookie(strLink ){
	var isChecked  = jQuery('#rememberChk').is(':checked');
		if(isChecked==true){
			jQuery.cookie("Manpower", strLink,{expires:30,path:'/',domain:'.manpower.com'});
		}		
}

function onCountryChange1(){
	var countryCode = jQuery('#country1').val(); 	
//	jQuery('select#country2 option[value=' + localeCountry + ']').attr('selected', 'selected');
	loadLanguage1(countryCode);
} // onCountryChange1

function onCountryChange2(){
	var countryCode = jQuery('#country2').val(); 	
//	jQuery('select#country1 option[value=' + localeCountry + ']').attr('selected', 'selected');
	loadLanguage2(countryCode);
} // onCountryChange2


function loadLanguage1(countryCode){
	jQuery('#language1').load('select-boxes-' + countryCode + '.html');	
	$('#language1').mouseleave(function(event) { event.stopPropagation(); });
}
function loadLanguage2(countryCode){
	jQuery('#language2').load('select-boxes-' + countryCode + '.html');	
	$('#language2').mouseleave(function(event) { event.stopPropagation(); });
}

function onLanguageReady(){

} // onLanguageReady

function onButtonClick1(){
	var candidateCountry = jQuery('#country1 option:selected').text();
	var candidateLanguage = jQuery('#language1 option:selected').text();
	var candidateLinkValue = jQuery.trim(candidateCountry) + ', ' + jQuery.trim(candidateLanguage);
	_gaq.push(['_trackEvent', 'Candidate', 'Candidate Go Button Click', candidateLinkValue, 1]);
	
	var link = jQuery("#language1 option:selected").attr("candidateLink");
	setCookie(link);
	redirect(link);
}
function onButtonClick2(){
	var clientCountry = jQuery('#country2 option:selected').text();
	var clientLanguage = jQuery('#language2 option:selected').text();
	var clientLinkValue = jQuery.trim(clientCountry) + ', ' + jQuery.trim(clientLanguage);
	_gaq.push(['_trackEvent', 'Client', 'Client Go Button Click', clientLinkValue, 1]);
	
	var link = jQuery("#language2 option:selected").attr("clientLink");
	setCookie(link);
	redirect(link);
}

function detectLocale(){
		// detect Language works IE/SAFARI/CHROME/FF
		var strLocale = window.navigator.userLanguage || window.navigator.language;
		if(strLocale.length>=2){
			localeLanguage=strLocale.substring(0,2).toLowerCase();
		}
		if(strLocale.length>=4){
			localeCountry=strLocale.substring(3).toUpperCase();
		}
		//alert("Locale:"+strLocale+" country:"+localeCountry+" language:"+localeLanguage); 
}
function redirect(link){
 jQuery(window.location).attr('href', link);
}



// KWICKS
$().ready(function() {
	$('.kwicks').kwicks({
		max : 920,
		spacing : 6,
		duration: 300,  
        easing: 'easeOutExpo'  
	});
});

// DATE
$(document).ready(function () {
	// SET COPYRIGTH TO CURRENT YEAR
 		$('#spanYear').html(new Date().getFullYear());
	});
