
//used for timed menus
var ignoresub="";
var ignorebutton ="";
var timed;
var menudelay=2000;

function cleanItems(includeNormal,includeMouseover,includeSubs,fadeoutsub){
	
	if (includeMouseover){
		var mouseovers=$(".menupoint_highlighted");
		mouseovers.hide();
	}
	
	if (includeNormal){
		var nonmouseovers=$(".menupoint");
		nonmouseovers.show();
	}
	if (includeSubs){
		var submenus=$(".menu_subpoint_background");
		if (fadeoutsub){
			submenus.fadeOut("fast");
		}else{
			submenus.hide();
		}
	}
}

function timedClear(){
	if(ignoresub==""){
		//clean subs
		cleanItems(false,false,true,false);
		
		if (ignorebutton==""){
			//clean buttons
			cleanItems(true,true,false,false);
		}
	}	
	timed=null;
}
function toggleSubmenu(evt,elem){
	//submenu mouseout
	ignoresub="";
	ignorebutton="";
	//if (timed==null) timed=setTimeout("timedClear()",menudelay);
	timed=setTimeout("timedClear()",menudelay);
}

function menuOut(){
	//submenu item, mouseout (seperate event if something needs changing)
	ignoresub="";
	ignorebutton="";
	//if (timed==null) timed=setTimeout("timedClear()",menudelay);
	timed=setTimeout("timedClear()",menudelay);
}


function toggleItem(evt,elem,noSubs){
	if (noSubs){
		//toggling something that has no submenu, only clean up
		//cleanItems(true,true,true);
		ignoresub="";
		ignorebutton="";
		timed=setTimeout("timedClear()",menudelay);
	}else{
		//toggling something that has submenu, clean up + open relevant stuff
		cleanItems(true,true,true);
		var theid="#"+elem.id;
		
		$(theid).hide(); //hide nonhighlight
		$(theid+"_highlight").fadeIn("fast"); //fade in highlight
		$(theid+"_sub").fadeIn("fast"); //fade in submenu of highlight
		ignoresub = theid+"_sub";
		ignorebutton= theid+"_highlight";
	}	
 }
 

function log(text){
	console.log(text);
}

function subLightOn(elem){
	//Get container
	var donthide= elem.parentNode.parentNode.parentNode.id;
	//put on ignore list
	ignoresub=donthide;
	ignorebutton=donthide.replace("_sub","_highlight");
	//highlight the item
	elem.src = elem.src.replace(".gif", "_highlight.gif");
}

function subLightOff(elem){
	//remove highlight image
	elem.src = elem.src.replace("_highlight.gif", ".gif");
}


/*********************************************/

function replaceAll(Source,stringToFind,stringToReplace){
	var temp = Source;
	var index = temp.indexOf(stringToFind);
	while(index != -1){
		temp = temp.replace(stringToFind,stringToReplace);
	    index = temp.indexOf(stringToFind);
	}
	return temp;
}
function fbs_click() {
	u=location.href;
	t=document.title; window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+ encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');       
	return false;      
}
function tip_click() {
	u="'"+window.location+"'";
	t=document.title;
	o='toolbar=0,status=0,width=500,height=450';
	window.open(window.location+'/tip','Tip',o);
	return false;
}