//Simple spy: http://jqueryfordesigners.com/simple-jquery-spy-effect/ thanks to Remy Sharp and assistance from @karlswedberg
(function ($) {
  $.fn.simpleSpy = function (limit, interval) {
    	limit = limit || 3;
    	interval = interval || 6000;
	spyLimit = 3; 
    	return this.each(function () {
      		// 1. setup
      		// capture a cache of all the list items
      		// chomp the list down to limit li elements
      		var $list = $(this),
      		items = [], // uninitialised
      		currentItem = limit,
      		total = 0, // initialise later on
      		height = $list.children().eq(0).height();
      		// capture the cache
      		$list.children('li').each(function () {
      		  	items.push('<li>' + $(this).html() + '</li>');
      		});
      		total = items.length;
      		$list.wrap('<div class="spyWrapper" />').parent().css({ height : height * limit });
      		$list.children('li').filter(':gt(' + (limit - 1) + ')').remove();
      		// 2. effect        
      		function spy() {
			if(total > spyLimit){
				// insert a new item with opacity and height of zero
				var $insert = $(items[currentItem]).css({
					height : 0,
					opacity : 0,
					display:'none'
				}).prependTo($list);
				// fade the LAST item out
				$list.children('li:last').animate({opacity: 0}, 1000, function () {
				  	// increase the height of the NEW first item
				  	$insert.animate({ height : height }, 1000).animate({opacity: 1}, 1000).show();
				  	// AND at the same time - decrease the height of the LAST item
				  	// $(this).animate({ height : 0 }, 1000, function () {
				  	// finally fade the first item in (and we can remove the last)
				  	$(this).remove();
				  	// });
				});
        			currentItem++;
        			if (currentItem >= total) {
        	  			currentItem = 0;
        			}
        			setTimeout(spy, interval);
			}
      		}	
      		spy();
    	});
  };
})(jQuery);

$(document).ready(function(){
	if(postingDate != '' && postingDate != 'undefined' && postingDate != null){
		$(".postingdatelabel").html(postingDate);
	}
	if(moreJobOpportunity != '' && moreJobOpportunity != 'undefined' && moreJobOpportunity != null){
		$("#moreJobOpp").html(moreJobOpportunity);
	}
	var config = {
		sensitivity: 2, 
		interval: 50, 
		over: show, 
		timeout: 200, 
		out: hide
	};
	$("#topnav>li").hoverIntent( config );
	$("#mainnavigator>li").hoverIntent( config );
	var blackTeaserCount= $("div.largeimage div.career-areas:first div.unit").size();	
	if(blackTeaserCount==5){					
		$("div.career-areas:first div.line:first").addClass("fivecolumns");
	}
	else if(blackTeaserCount==4){
		$("div.career-areas:first div.line:first").addClass("fourcolumns");
	}	
	else if(blackTeaserCount==3){
		$("div.career-areas:first div.line:first").addClass("threecolumns");
	}
	else if(blackTeaserCount==2){
		$("div.career-areas:first div.line:first").addClass("twocolumns");
	}
	else if(blackTeaserCount==1){
		$("div.career-areas:first div.line:first").addClass("onecolumns");
	}
	var whiteTeaserCount= $("div.largeimage div.career-areas:last div.unit").size();
	if(whiteTeaserCount==5){					
		$("div.career-areas:last div.line:first").addClass("fivecolumns");
	}
	else if(whiteTeaserCount==4){
		$("div.career-areas:last div.line:first").addClass("fourcolumns");
	}
	else if(whiteTeaserCount==3){
		$("div.career-areas:last div.line:first").addClass("threecolumns");
	}
	else if(whiteTeaserCount==2){
		$("div.career-areas:last div.line:first").addClass("twocolumns");
	}
	else if(whiteTeaserCount==1){
		$("div.career-areas:last div.line:first").addClass("onecolumns");
	}		
	
	$("div.career-areas:first div.unit:last").addClass("lastUnit");
	$("div.career-areas:last div.unit:last").addClass("lastUnit");
	$('ul.spy').simpleSpy();
	if(window.whiteTeaserBGColor =='undefined'){var whiteTeaserBGColor='';}
	if(window.whiteTeaserBGColor == "Gray"){
		     $(".career-areas:last-child div.unit div.mod").addClass("gradlight man");
		} else{
		     $(".career-areas:last-child div.unit div.mod").addClass("translucent");
	}
	$("div.career-areas:first").addClass("contentspacer");
	if(window.loadProfile == "true")
	    { loadProfiles(); }
	$("#nav-staycon a.topnavdropdown").attr('href', '/GL/en/Home/Social-media');
    	
}); // close document.ready
function loginOnload() {			
	if(document.getElementById("nav-utilityonlinesignin")) {		
			if(document.getElementById("echannel_overlay_login_form")) {						
				var loginHtml = document.getElementById("echannel_overlay_login_form").innerHTML;						
				document.getElementById("nav-utilityonlinesignin").innerHTML = loginHtml ;
				$("#nav-utilityonlinesignin a#online_signin_off").remove();
				document.getElementById("echannel_overlay_login_form").innerHTML = "";
				document.getElementById("overlayError").style.display="none";
			}
	}
	showLoginForm();
	var accessType = getCookie('echannelLoginAccessType');
	var liveChatErrorCode = getCookie("ErrorCode");
	if(accessType == "overlay") {
		showLogin();
		loginShowHide("divLoginOverlay", "divRecollectOverlay", "overlayOnlyErroMsg", "frmLoginOverlay", "frmLoginOverlay", "overlayError", "overlayEmailErrorMsg", "overlayOnlyErroMsg", "idLoginOverlayForgotLink", "idLoginOverlayReturn");
	} else if (accessType == "page") {
		loginShowHide("idEchannelLogin", "idRecollect", "eyoLoginMsgiv", "frmEchannelLogin", "frmEchannelLogin", "Error", "EmailErrorMsg", "onlyErrorMsg", "idLoginForgotLink", "idLoginReturnToLogin");
	} 

	deleteCookie('echannelLoginAccessType', '/', cookieDomainName);
	deleteCookie('ErrorCode', '/', cookieDomainName);
	if(liveChatErrorCode == "95") {
			livechat();
	}
}

function contentLoaded(){
	addCountryData();	
	setHrefForList0();
}
/**
 * @author alexander.farkas
 * @version 1.0
 */
(function($){
	
	if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8 workaround
		var oldCurCSS = $.curCSS;
		$.curCSS = function(elem, name, force){
			var curStyle = elem.currentStyle, ret;
			if(name === 'font-size'){
				name = 'fontSize';
			}
			if((name !== 'clip' && name !== 'fontSize') || !curStyle){
				return oldCurCSS.apply(this, arguments);
			}
			var style = elem.style;
			if ( !force && style ){
				ret = style[ name ];
			}
			if(name === 'clip'){
				ret = ret || 'rect('+ (curStyle.clipTop || 'auto') +' '+ (curStyle.clipRight || 'auto') +' '+ (curStyle.clipBottom || 'auto') +' '+ (curStyle.clipLeft || 'auto') +')';
			} else {
				ret = ret || curStyle.fontSize;
				if(!(/px/.test(ret))){
					// Remember the original values
					var width = style.width, rsWidth = elem.runtimeStyle.width;
	
					// Put in the new values to get a computed value out
					elem.runtimeStyle.width = elem.currentStyle.width;
					style.width = '100em';
					ret = style.pixelWidth / 100 + "px";
					// Revert the changed values
					style.width = width;
					elem.runtimeStyle.width = rsWidth;
				}
			}
			return ret;
		};
	}
})(jQuery);

(function($){
	var calcClipAuto = [
						function(){
							return 0;
						},
						function(elem){
							return $(elem).outerWidth();
						},
						function(elem){
							return $(elem).outerHeight();
						},
						function(elem){
							return 0;
						}
					],
					
					calcNumClip = function(prop, elem){
						return ((/em/.test(prop))) ? 
								(parseFloat($.curCSS(elem, 'fontSize'), 10) || 1) * (parseFloat(prop, 10) || 0) :
								(parseInt(prop, 10) || 0)
						;
					}
	;
	
	var calcClip = function(css, fx, isEnd){
			var ret 	= [];
			if(css === 'auto'){
				css = 'rect(auto auto auto auto)';
			}
			
			css = css.replace(/rect\(|\)/g, '').split(/,\s*|\s/);
			if(isEnd){
				fx.endClipStyle = 'rect('+ css.join(' ') +')';
			}
			for(var i = 0; i < css.length; i++){
				ret[i] = (css[i] !== 'auto') ? 
							calcNumClip(css[i], fx.elem) : 
							calcClipAuto[i](fx.elem);
			}
			
			return ret;
		};
	
	jQuery.fx.step.clip = function(fx){
		if (!fx.clipInit) {
			
			fx.start = calcClip($.curCSS(fx.elem, 'clip'), fx);
			fx.end = calcClip(fx.end, fx, true);
			fx.elmStyle = fx.elem.style;
			fx.clipInit = true;
		}
		
		fx.elmStyle.clip = 'rect('+ ( fx.pos * (fx.end[0] - fx.start[0]) + fx.start[0] ) +'px '+ (fx.pos * (fx.end[1] - fx.start[1]) + fx.start[1]) +'px '+ (fx.pos * (fx.end[2] - fx.start[2]) + fx.start[2]) +'px '+ (fx.pos * (fx.end[3] - fx.start[3]) + fx.start[3]) +'px)';
		
		if(fx.pos === 1 && fx.endClipStyle){
			fx.elmStyle.clip = fx.endClipStyle;
		}
	};
})(jQuery);
function loadOverlay() {
	$('.homenavigation04link').colorbox({width:"680", inline:true, href:"#homenavigation04content"});
}
$.fn.equalHeights = function() {
		return this.height(Math.max.apply(null,
			this.map(function() {
				return $(this).height()
				}).get()
			));
	};
$(document).ready(function () {
    $('.career-areas .twocolumns .graddark .hd').equalHeights();
    $('.career-areas .twocolumns .gradlight .hd').equalHeights();
    $('.career-areas .threecolumns .graddark .hd').equalHeights();
    $('.career-areas .threecolumns .gradlight .hd').equalHeights();
    $('.career-areas .fourcolumns .graddark .hd').equalHeights();
    $('.career-areas .fourcolumns .gradlight .hd').equalHeights();
    $('.career-areas .fivecolumns .graddark .hd').equalHeights();
    $('.career-areas .fivecolumns .gradlight .hd').equalHeights();
    $('.career-areas .twocolumns .graddark .bd').equalHeights();
    $('.career-areas .twocolumns .gradlight .bd').equalHeights();
    $('.career-areas .threecolumns .graddark .bd').equalHeights();
    $('.career-areas .threecolumns .gradlight .bd').equalHeights();
    $('.career-areas .fourcolumns .graddark .bd').equalHeights();
    $('.career-areas .fourcolumns .gradlight .bd').equalHeights();
    $('.career-areas .fivecolumns .graddark .bd').equalHeights();
    $('.career-areas .fivecolumns .gradlight .bd').equalHeights();
});
