//all javascripts that are SITE SPECIFIC, and probably cannot be reused in other site, go in this file

//KPSEAFOOD SPECIFIC FUNCTIONS

function toggleRecipeMenu(){
	if($('#rSearchMenu').is(":hidden")){
		$('#rSearchMenuBtnTxt').html('CLOSE SEARCH&nbsp;&nbsp;X');
	}else{
		$('#rSearchMenuBtnTxt').html('NEW SEARCH&nbsp;&nbsp;+');
	}
	$('#rSearchMenu').slideToggle(600);
}

function searchRecipes(){
	//package any selected menuparts into an array, which then gets URL encoded and stored in the rMPs hidden input
	mpString="";
	for(mpRef in mpArray){
		mpSrc=$('#'+mpArray[mpRef]).attr('src');
		if(mpSrc.substr(mpSrc.length-8,4)=='over'){
			if(mpString!=""){mpString+="|";}
			mpString+=$('#'+mpArray[mpRef]).attr('id');
		}
	}
	//alert(mpString);
	document.rSearchForm.rMPs.value=mpString;
	document.rSearchForm.submit();
}

function toggleMenuPart(mpRef){
	//alert(mpRef.src);
	//stringReplace(modifyString,findString,replaceString)
	switch(mpRef.src.substr(mpRef.src.length-8,4)){
		case 'norm':
			mpRef.src = stringReplace(mpRef.src,'_norm','_over');
		break;
		case 'over':
  			mpRef.src = stringReplace(mpRef.src,'_over','_norm');
		break;
	}
}

function updateRecipeContent(id){
	if(id!=openRecipe){
		if(openRecipe!=""){$('#recipeTitle_'+openRecipe).removeClass('KPblue');}
		openRecipe=id;
		$('#recipeTitle_'+id).addClass('KPblue');
	}
	//location.hash='top';
	jqueryScroll('top');
	//now fade up the loading animation and retrieve the data
	$("#loadingAnim").css({display:'block',opacity:0}).fadeTo(150,.90,function(){
		//ajaxCall('/support/recipe.php?id='+id,'GET','','pContent')
	   $.get('/support/recipe.php?id='+id,{},function(htmlRet){$("#pContent").html(htmlRet);$("#loadingAnim").fadeOut(200);});
	});
}

/*AJAX functions*/
function ajaxStart(){
	/*//alert('in ajaxProcess');
	doneCall=String(ajaxDoneCalls.slice(0,1));
	//alert('doneCall='+doneCall);
	switch(doneCall){
		case "pContent":); break;
	}*/
}

function ajaxProcess(){}

function ajaxDone(doneCall){
	alert('in ajaxDone, doneCall='+doneCall);
	//if(xmlHttp.responseText!=null && xmlHttp.responseText!=""){}
	//alert(xmlHttp.responseText);
	//alert('doneCall='+doneCall);
	switch(doneCall){
		case "pContent": $("#pContent").html(xmlHttp.responseText);/*$("#pContent").css('z-index',1);*/ $("#loadingAnim").fadeOut(200); break;
	}
}

function updateProdContent(type,id){
	//alert(type+' '+id);
	switch(type){
		case 'recipe':
			//if the type is prod, then first update the hilighted product in the left list
			
		break;
		case 'prod':
			//if the type is prod, then first update the hilighted product in the left list
			if(id!=openProd){
				if(openProd!=""){$('#prodTitle_'+openProd).removeClass('KPblue');}
				openProd=id;
				$('#prodTitle_'+id).addClass('KPblue');
			}
		break;
		case 'desc':
			//remove any product list item hilights
			if(openProd!=""){$('#prodTitle_'+openProd).removeClass('KPblue');}
			openProd="";
			//close the open description div, open the new one and update the openDesc variable
			if(id!=openDesc){
				$('#descTitle_'+id).addClass('KPblue');
				toggleContDiv(openDesc,'image','','','',0);
				$('#descTitle_'+openDesc).removeClass('KPblue');
				toggleContDiv(id,'image','','','',0);
				openDesc=id;
			}
		break;
	}
	//now fade up the loading animation and retrieve the data
	$("#loadingAnim").css({display:'block',opacity:0}).fadeTo(150,.90,function(){
	   //ajaxCall('/products/specsheet.php?type='+type+'&id='+id,'GET','','pContent')
	   $.get('/products/specsheet.php?type='+type+'&id='+id,{},function(htmlRet){$("#pContent").html(htmlRet);$("#loadingAnim").fadeOut(200);});
	});
}

function toggleSite(){
	location.href=togglePg;
}

function portalLogout(){
	window.location.href="/index.php?pLogout=1";
}

function togglePswdRecover(dir){
	//dim the regular login and show the password recovery box
	//$("#loginDiv").fadeTo(400,.25);
	switch(dir){	
		case 'show':$("#pswdRecoverDiv").fadeIn(400);break;
		case 'hide':$("#pswdRecoverDiv").fadeOut(400);break;
	}
}
regionChanged=0;
function displayRegion(newRegion,oldRegion){
	//alert(newRegion+" "+oldRegion);
	//show the new region div and hide the old one if applicable
	if(oldRegion!=""){$("#"+oldRegion+"Div").css({display:'none'});}
	if(newRegion!=""){$("#"+newRegion+"Div").css({display:'block'});}
	//setTimeout(function(){jqueryScroll('regionResults');},200);
	//now scroll to the region results - ONLY if the new div height is LARGER than the old, otherwise just jump to the anchor to avoid wierd screen refresh
	//NOTE ALSO THAT WE ONLY ALLOW IE6 TO SCROLL TO THE REGIONS THE FIRST TIME - and after that it cannot - because of an apparent IE6 bug that kills the browser
	if(regionChanged==0 || isIE6==0){
		if(oldRegion=="" || ($("#"+oldRegion+"Div").height() < $("#"+newRegion+"Div").height())){
			jqueryScroll('regionResults');
		}else{
			location.hash='regionResults';
			//scrollToAnchor('regionResults')
		}
		regionChanged=1; 
	}
}

var curBrokerLoc=0;
function showBrokerResults(location,openPage){
	//alert(location);
	if(location!=""){
		if(openPage==1){
			//if the openPage argument was sent, we need to go to the results page and show the current results
			window.location.href="/shared/broker-locator.php?loc="+location;
		}else{
			//otherwise just show the appropriate div - and hide any open div
			if(curBrokerLoc!=0){$("#"+curBrokerLoc+"Div").css({display:'none'});}
			if(location!=""){$("#"+location+"Div").css({display:'block'});}
			//update the curBrokerLoc variable
			curBrokerLoc=location;
		}
	}
}

var curCareerID="overviewP";
function showCareer(newID){
	//fade out the old posting if it exists
	if(curCareerID){
		oldID=curCareerID;curCareerID="";
		$("#"+oldID).fadeOut(350,function(){showCareer(newID);});
	}else{
		curCareerID=newID;
		//fade up the new career & make sure we scroll to show it
		$("#"+newID).fadeIn(350);
		//jqueryScroll('postings');
	}
}

























