var oPlayVideo = null;//global Variable for the movieEnd function.
var loadVideoPath = null;
var playVideoTitle = null;
var documentTitle = document.title;
function getPageNav(isRefresh)
{
	var panelCount = jQuery(".panelContainer .panel").size();
	if(panelCount>1)
	{
		var hashValue = location.hash;
		var hashIndex = hashValue.substr(1);
		hashIndex = isRefresh || hashIndex==""? 1: hashIndex;
		jQuery("#fpeoplepagenum").html("Page "+hashIndex +" of "+panelCount);
	}
	document.title = documentTitle;
}
function getMouseXY(e) {
  if (jQuery.browser.msie) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
   return {mouseX:tempX,mouseY:tempY};
}
function getSelectedImage()
{
	var param = getUrlParam('selectedpeople');
	var obj = null;
	var oImages = null;
	if(param != null)
	{
		oImages = jQuery(".panel .fpeoplepic .divpeopleimage img[oPeopleID="+param+"]");
		if(oImages.size()>0){
				obj = oImages.get(0);initSettings(obj);
			}
	}
	if(obj == null){
			oImages = jQuery(".panel .fpeoplepic .divpeopleimage img[oDefaultVideo=True]");
			var oDefaultImages = jQuery(".panel .fpeoplepic .divpeopleimage img");
			var oImagesCount = oImages.size();
			if(oImagesCount >0){
				var objRandomIndex =  Math.floor(Math.random()*oImagesCount);
				obj = oImages.get(objRandomIndex);
			}
			else{
				if(oDefaultImages.size()>0){
					obj = oDefaultImages.get(0);
				}
			}
		}
	return obj;
}
function loadFirstPeopleVideo(){
	var obj = getSelectedImage();
	oPlayVideo = obj;//Add for the movieEnd function
	if(obj != null){
		loadVideoPath = jQuery(obj).attr("oVideo");
		playVideoTitle = jQuery(obj).attr("oTitle");
		var param = getUrlParam('selectedpeople');
		if (jQuery(obj).attr("oTitle") != null)
	  	{  	
	  		jQuery("#v_people_name").html(jQuery(obj).attr("oTitle"));  	
	  	}
	  	
	  	if (jQuery(obj).attr("oJobRole") != null)
	  	{  	
	  		jQuery("#v_people_jobrole").html(jQuery(obj).attr("oJobRole"));  	
	  	}
	
	  	if (jQuery(obj).attr("oLocation") != null)
	  	{  	
	  		jQuery("#v_people_loc").html(jQuery(obj).attr("oLocation"));  	
	  	}
	  	if (jQuery(obj).attr("oPreviewImage") != null)
	  	{  	
	  		jQuery("#videoplayercontent").css("background-image","url("+jQuery(obj).attr("oPreviewImage")+")"); 
	  	}
	  	else
	  	{
	  		jQuery("#videoplayercontent").css("background-image","url('/careers/images/People1.jpg')");
	  	}
	  	if (jQuery(obj).attr("oVideo") != null)
	  	{  	
	  		if(param != null)
	  		{
				document.getElementById("singlePlayer").playPeopleVideo(jQuery(obj).attr("oVideo"));
			}
			else
	  			document.getElementById("singlePlayer").loadPeopleVideo(jQuery(obj).attr("oVideo"));
		}	  	
	}
}
/*When the user selects the professional,craft,or collge, if the all section is selected,the all should be unchecked*/
function jobTypeOnchange(obj)
{
	var isFromAll = jQuery(obj).attr("name") == "All";
	var jobTypes = "";
	var checkedCount = 0;
	jQuery(".jobtypeitem").each(function(){
			if(jQuery(this).attr("checked") != undefined){
			checkedCount++;
			jobTypes+=jQuery(this).attr("name")+",";
		}
	});
	if(jQuery.trim(jobTypes).toLowerCase().indexOf("all")>=0 && checkedCount>1){
		if(isFromAll)
			jQuery(".jobtypeitem").not(jQuery(obj)).attr("checked",false);
		else
			jQuery("input[name=All]").attr("checked",false);
	}	
}
function resetOptions()
{
	var jobTypes = "";
	jQuery(".jobtypeitem").each(function(){if(jQuery(this).attr("checked")!=undefined&&jQuery(this).attr("checked")!=false){
				jobTypes+=jQuery(this).attr("name")+",";
			}
		});
	if(jQuery.trim(jobTypes)==""){
		jQuery("#ddlJobRole").html("<option value=''>(Select)</option>");
		jQuery("#ddlLocation").html("<option value=''>(Select)</option>");
		jQuery("#ddlTopic").html("<option value=''>(Select)</option>");
	}

}
function initCodaSlider()
{
	var csws=jQuery('div.csw');
	var order=10;
	var ordercount,btndisable,btnenable,sliderindex,btnPreviousDisabled,btnPreviousEn,btnNextDisabled,btnNextEn,omnitureButtonType;		    
	var omnitureType = "peoplebuttons";
	for(var i=0;i<=csws.length-1;i++)
	{
	    order+=i;
	    var settings={	ordercount:order, 
	    				sliderindex:i,
	    				btndisable:'/SiteCollectionImages/Pag_Box_2.gif',
	    				btnenable:'/SiteCollectionImages/Pag_Box_1.gif',
	    				btnPreviousDisabled:'/SiteCollectionImages/Pag_Left_Arrow_1.gif',
	    				btnPreviousEn:'/SiteCollectionImages/Pag_Left_Arrow_2.gif',	
	    				btnNextDisabled:'/SiteCollectionImages/Pag_Right_Arrow_1.gif',
	    				btnNextEn:'/SiteCollectionImages/Pag_Right_Arrow_2.gif',
	    				omnitureButtonType:omnitureType};
	    				
	    jQuery("div#"+csws[i].id).codaSlider(settings);
	    
	}	
}
function getJobTypes()
{
	var jobTypes = "";
	jQuery(".jobtypeitem").each(function(){if(jQuery(this).attr("checked")!=undefined&&jQuery(this).attr("checked")!=false){
				jobTypes+=jQuery(this).attr("name")+",";
			}
		});
	if(jobTypes.substr(jobTypes.length-1,jobTypes.length)==","){
		jobTypes=jobTypes.substr(0,jobTypes.length-1);
	}
	if(jobTypes.length>0)
		jobTypes = "&jobType="+jobTypes;
	return jobTypes;	
}
function getConditions(){
	var para = "";
	var re=/&/g;
	if(jQuery.trim(jQuery('#ddlJobRole').attr("value"))!="" && jQuery.trim(jQuery('#ddlJobRole').attr("value"))!="(Select)")
		para+="&jobRole="+jQuery.trim(jQuery('#ddlJobRole').attr("value").replace(re,'%26'));
	if(jQuery.trim(jQuery('#ddlLocation').attr("value"))!="" && jQuery.trim(jQuery('#ddlLocation').attr("value"))!="(Select)")
		para+="&location="+jQuery.trim(jQuery('#ddlLocation').attr("value").replace(re,'%26'));
	if(jQuery.trim(jQuery('#ddlTopic').attr("value"))!="" && jQuery.trim(jQuery('#ddlTopic').attr("value"))!="(Select)")
		para+="&topics="+jQuery.trim(jQuery('#ddlTopic').attr("value").replace(re,'%26'));
	return para;
}

//Function Update The JobRole, Location,Topics
function getOptionsByJobType(){
	var jobTypes = getJobTypes();
	if(jobTypes.length>0){
		jQuery.ajax({url:"/_layouts/css/PeopleSectionDataSource.aspx?getoption=1"+jobTypes,
					type:"get",
					async: false,
					success:function(data){
					var optionTypes = data.split("##");
							jQuery("#ddlJobRole").html(optionTypes[0]);
							jQuery("#ddlLocation").html(optionTypes[1]);
							jQuery("#ddlTopic").html(optionTypes[2]);
						}
				});
		}
}
function getPeopleByConditions(isClear){
	var jobTypes = getJobTypes();
	var others = getConditions();
	var para = isClear==true? jobTypes:jobTypes+others;
	if(para.length>0){
	jQuery("div#hr_peoplevideo").html("<div style='margin-left:110px;margin-top:110px;'><img src='/careers/PublishingImages/ajax-loader.gif' alt='loading...'/ ></div>");
	jQuery.get("/_layouts/css/PeopleSectionDataSource.aspx?addition=1"+para,function(data){
			jQuery("div#hr_peoplevideo").html(data);
			initCodaSlider();getPageNav(true);
		}
	);
	}
}
jQuery(document).ready(function(){
		//initCodaSlider();
		getOptionsByJobType();
		getPageNav(true);
		jQuery("#ddlJobRole").bind("change",function(){getPeopleByConditions(false);});
		jQuery("#ddlLocation").bind("change",function(){getPeopleByConditions(false);});
		jQuery("#ddlTopic").bind("change",function(){getPeopleByConditions(false);});
		jQuery(".jobtypeitem").each(function(){
			jQuery(this).bind("click",function(){
				resetOptions();jobTypeOnchange(this);getOptionsByJobType(true);getPeopleByConditions(true);
				if(jQuery(this).attr("checked")!=undefined&&jQuery(this).attr("checked")!=false){
					if(TrackCustomLink){TrackCustomLink(this,'checkbox | '+jQuery(this).attr('name'));}
				}
			});
		});
		jQuery("#projectspreviouse1 img").bind("click",function(){getPageNav(false);});
		jQuery("#projectsnext1 img").bind("click",function(){getPageNav(false);});
		jQuery(".projectseachpanel img").each(function(){jQuery(this).bind("click",function(){getPageNav(false);})});
		//Play the first one video
		loadFirstPeopleVideo();
});
function setVideoPlayer(){
AC_FL_RunContent(
			"src", "/SiteCollectionImages/swf/singlePlayer",
			"width", "100%",
			"height", "100%",
			"align", "middle",
			"id", "singlePlayer",
			"quality", "high",
			"bgcolor", "#869ca7",
			"name", "singlePlayer",
			"allowScriptAccess","sameDomain",
			"allowFullScreen","true",
			"wmode","transparent",
			"type", "application/x-shockwave-flash",
			"pluginspage", "http://www.adobe.com/go/getflashplayer"
	);
}
function playPeopleVideo(url,obj){
		oPlayVideo = obj;//Add for the movieEnd function.
		if(obj != null){
			loadVideoPath = jQuery(obj).attr("oVideo");
			playVideoTitle = jQuery(obj).attr("oTitle"); 
			playVideoPreviewImage =  jQuery(obj).attr("oPreviewImage");
			if (jQuery(obj).attr("oTitle") != null)
		  	{  	
		  		jQuery("#v_people_name").html(jQuery(obj).attr("oTitle"));  	
		  	}
		  	
		  	if (jQuery(obj).attr("oJobRole") != null)
		  	{  	
		  		jQuery("#v_people_jobrole").html(jQuery(obj).attr("oJobRole"));  	
		  	}
		
		  	if (jQuery(obj).attr("oLocation") != null)
		  	{  	
		  		jQuery("#v_people_loc").html(jQuery(obj).attr("oLocation"));  	
		  	}
		  	if(playVideoPreviewImage != null && typeof playVideoPreviewImage != 'undefined'){
		  		jQuery("#videoplayercontent").css("background-image","url("+playVideoPreviewImage+")");
		  	}
		  	else{
		  		jQuery("#videoplayercontent").css("background-image","url(/careers/images/video_end.jpg)");
		  	}
		  	if (jQuery(obj).attr("oVideo") != null)
		  	{	
		  		document.getElementById("singlePlayer").playPeopleVideo(jQuery(obj).attr("oVideo"));	  		
		  	}
		  	if(typeof Omniture_AddNameAttribute != undefined){
		  	//alert("aa");
		  	Omniture_AddNameAttribute(obj,"people thumbnail | "+jQuery(obj).attr("oTitle"));
		  	//TrackCustomLink(obj,"people thumbnail | "+jQuery(obj).attr("oTitle"));
		  	}

		}
}


var isHidePeople;
var selectedimg;
var selectedimgId;

var hasShowBox = "false";
var hTimer;
function peopleonmouseover(obj)
{
	if (hTimer!=null){window.clearTimeout(hTimer);}
	if( hasShowBox == "false" )
	{
		//alert( "mouseover");
		if (selectedimg != null)
		{
			if (selectedimg.src != null)
			{	
				if (selectedimg != obj)
				{
					isHidePeople = "true";
					hide_people();	
				}
			}
		}
	
	    isHidePeople = "false";
	    var people_box_bg = document.getElementById("people_box_bg");
	
	    if (people_box_bg.style.display == "none")
	    {    		
	        selectedimg = obj;
	    
	        var pos = WebForm_GetElementPosition(selectedimg);
	        //var people_box = document.getElementById("people_box");
	        
	        initPeopleBox();
	        
	        people_box_bg.style.top = pos.y - 196 + "px";
	        people_box_bg.style.left = pos.x - 42 + "px";
	        people_box_bg.style.border = "none";
	        people_box_bg.style.display = "";
	        
	        selectedimg.className = "fpeopleimage_selected";
	        
	        
	        //selectedimg.style.border = "3px solid #005ed7";
	    }
	    selectedimgId = jQuery(selectedimg).attr("id");//donie add the selected id for the popup
	    hasShowBox = "true";
	 }
}

function initPeopleBox()
{
	if (selectedimg != null)
  {  	
  	var people_img = document.getElementById("people_img");
  	var people_name = document.getElementById("people_name");
  	var people_title = document.getElementById("people_jobrole");
  	var people_loc = document.getElementById("people_loc");
  	var video_desc = document.getElementById("video_desc");
  	
  	if(jQuery(people_img).attr("src")!="")
  		jQuery(people_img).attr("src","");
  	if (jQuery(selectedimg).attr("oTitle") != null)
  	{  	
  		jQuery("#people_name").html(jQuery(selectedimg).attr("oTitle"));  	
  	}else{
  		jQuery("#people_name").html('');
  	}  	
  	if (jQuery(selectedimg).attr("oJobRole") != null)
  	{  	
  		jQuery("#people_jobrole").html(jQuery(selectedimg).attr("oJobRole"));  	
  	}else{
  		jQuery("#people_jobrole").html('');
  	}

  	if (jQuery(selectedimg).attr("oLocation") != null)
  	{  	
  		jQuery("#people_loc").html(jQuery(selectedimg).attr("oLocation"));  	
  	}else{
  		jQuery("#people_loc").html('');
  	}
  	
  	if (jQuery(selectedimg).attr("oDescription") != null)
  	{  	
  		jQuery("#video_desc").html(jQuery(selectedimg).attr("oDescription"));  	
  	}else{
  		jQuery("#video_desc").html('');
  	}
  	
  	if (jQuery(selectedimg).attr("oLargeImage") != null)
  	{  	
  		jQuery(".people_img_bg").html("<img src='"+jQuery(selectedimg).attr("oLargeImage")+"' alt=''/>");  	
  	}
  	else
  	{
  		jQuery(".people_img_bg").html("<img src='/careers/PublishingImages/no_pic_107_128.jpg' alt=''/>");
  	}
  }
}
var index = 0;

function peopleonmouseout(e)
{
	/*-------------------------------*/
	var isMouseOut = true;
	
	/*
	if(selectedimg!=null)
	{
		var pos = WebForm_GetElementPosition(selectedimg);
		var mousePos = getMouseXY(e);
		if(mousePos.mouseX>=pos.x-3 && mousePos.mouseX<=pos.x+49 && mousePos.mouseY>=pos.y-3 && mousePos.mouseY<=pos.y+49)
		{
			isMouseOut = false;
		}
	}
	/*-------------------------------*/
	
	if(isMouseOut==true){
	    isHidePeople = "true";
		hasShowBox = "false";
		hide_people();

		/*
		if (hTimer!=null) window.clearTimeout(hTimer);
	   	hTimer = setTimeout("hide_people()", 300);    
	   	*/
    }
    

}

function hide_people()
{
	window.clearTimeout(hTimer);
    if (isHidePeople == "true")
    {
        if (selectedimg != null)
        {
            selectedimg.className = "fpeopleimage";        
            document.getElementById("people_box_bg").style.display = "none";
            isHidePeople = "false";
            selectedimg = null; 
        }
    }
}

/*--------------donie-----------------------------*/
function divonmouseover(obj,e){
	return;
	selectedimg = document.getElementById(selectedimgId);
	peopleonmouseout(e);
}
function largeImageClick(e)
{
	return;
	selectedimg = document.getElementById(selectedimgId);
	if(selectedimg  != null){
		var pos = WebForm_GetElementPosition(selectedimg);
		var mousePos = getMouseXY(e);
		//alert(mousePos.mouseX);
		if(mousePos.mouseX>=pos.x-3 && mousePos.mouseX<=pos.x+49 && mousePos.mouseY>=pos.y-3 && mousePos.mouseY<=pos.y+49)
		{
			if (jQuery(selectedimg).attr("oVideo") != null)
		  	{  	
		  		playPeopleVideo(jQuery(selectedimg).attr("oVideo"),selectedimg);
		  	}
		}
	}
}
function videoNoFoundFile()
{
	//alert("No  Video File Found");
}
function movieEnd()
{
	if(oPlayVideo !=null && typeof oPlayVideo!='undefined'){
		var attrPreviewImage = jQuery(oPlayVideo).attr('oPreviewImage');
		if(attrPreviewImage !=null && typeof attrPreviewImage !='undefined')
			jQuery("#videoplayercontent").css("background-image","url("+attrPreviewImage+")");
		else
			jQuery("#videoplayercontent").css("background-image","url(/careers/images/video_end.jpg)"); 
	}
	else
		jQuery("#videoplayercontent").css("background-image","url(/careers/images/video_end.jpg)"); 
	document.title = documentTitle;
}
function resetTitle()
{
	document.title = documentTitle;
}
function getVideoPath()
{
	return loadVideoPath;
}
function getVideoTitle(){
	return  playVideoTitle;
}
function initSettings(obj){
	var oJobType =getUrlOrgParam('jobtype');
	var oJobRole =getUrlOrgParam('jobrole');
	var oLocation =getUrlOrgParam('location');
	var oTopic =getUrlOrgParam('topic');
	var isUnchecked = false;
	var conditions = "";
	if(oJobType!=null){
		jQuery("input[name="+oJobType+"]").attr("checked",true);
		if(jQuery("input[name="+oJobType+"]").size()>0){
			jQuery("input[name=All]").attr("checked",false);
			isUnchecked = true;
		}
	}
	if(isUnchecked==false){
		conditions+="&jobType=All";
	}else{
		if(oJobType!=null){
			conditions+="&jobType="+oJobType;
		}
	}
	if(oJobRole!=null){
		selectedOption("ddlJobRole",unescape(oJobRole));
		conditions+="&jobRole="+oJobRole;
	}
	if(oLocation!=null){
		selectedOption("ddlLocation",unescape(oLocation));
		conditions+="&location="+oLocation;
	}
	if(oTopic!=null){
		selectedOption("ddlTopic",unescape(oTopic));
		conditions+="&topics="+oTopic;
	}
	if(conditions.length>0&&conditions!="&jobType=All")
	initPeople(conditions);
}
function selectedOption(objId,text){
	try{
		jQuery(obj).val(text);
	}catch(ex){
		setTimeout("jQuery('#"+objId+"').val('"+text+"')",1);
	}
}
function initPeople(para){
jQuery("div#hr_peoplevideo").html("<div style='margin-left:110px;margin-top:110px;'><img src='/careers/PublishingImages/ajax-loader.gif' alt='loading...'/ ></div>");
	jQuery.get("/_layouts/css/PeopleSectionDataSource.aspx?addition=1"+para,
			 	function(data){
					jQuery("div#hr_peoplevideo").html(data);
					initCodaSlider();getPageNav(true);
				}
	);
}
function getUrlOrgParam(name, url) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS,"ig");
    if (url == null) {url = window.location.href;}
    var results = regex.exec(url);
    if (results == null)
        return null;
    else
        return results[1];
}
