var imgs = imgs_path + "menubar/",
	curr = 0,
	mnuSt = false,
	mnuCurr = 40,
	mnuMin = 0,
	mnuMax = 250,
	mnuInc = 5,
	mnuInt = 10,
	menuVisible = false,
	xmlhttp;

var tab1, tab2, tab3, tab4, tab5, tab6, tab7, tab8;
var tab12, tab23, tab34, tab45, tab56, tab67, tab78, on_on, on_off, off_on, off_off;
var tab_1_on, tab_1_off, tab_2_on, tab_2_off, tab_3_on, tab_3_off, tab_4_on, tab_4_off, tab_5_on, tab_5_off, tab_6_on, tab_6_off, tab_7_on, tab_7_off, tab_8_on, tab_8_off;
var MenuP, MenuPB, IntMenu;

function init() {
	tab1 = document.getElementById("menu_1");
	tab2 = document.getElementById("menu_2");
	tab3 = document.getElementById("menu_3");
	tab4 = document.getElementById("menu_4");
	tab5 = document.getElementById("menu_5");
	tab6 = document.getElementById("menu_6");
	tab7 = document.getElementById("menu_7");
	tab8 = document.getElementById("menu_8");
	
	tab12 = document.getElementById("menu_12");
	tab23 = document.getElementById("menu_23");
	tab34 = document.getElementById("menu_34");
	tab45 = document.getElementById("menu_45");
	tab56 = document.getElementById("menu_56");
	tab67 = document.getElementById("menu_67");
	tab78 = document.getElementById("menu_78");
	
	MenuP = document.getElementById("MenuPanel");
	MenuPB = document.getElementById("MenuPanelBody");
	
	getxmlhttp();
}

function getxmlhttp(){	
	if (window.XMLHttpRequest)
	{xmlhttp=new XMLHttpRequest();}
	else
  	{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
}

function menuDo(tab,wat)
{
	switch(wat){
	case 0:	
		//resetMnu();
		break;
	case 1:	
		//resetMnu();
		//doTab(tab);
		break;
	case 2:
		if(tab==1){
			jumpToURL("../recipes/portal.php");
			return true;
		}
		else{
			if(curr!=tab){
				//doTab(tab);
				curr = tab;	
				doMenuP(true);
			}
			else{
				curr = 0;
				doMenuP(false);
			}	
			//resetMnu();
		}
		break;
	}	
}

function doTab(tab){
	/*var objTab = eval("tab"+tab);
 	objTab.src = eval("tab_"+tab+"_on.src");
		
	switch(tab){
	case 1:
		tab12.src = (curr==2)?on_on.src:on_off.src;
		break;
	case 2:
		tab12.src = (curr==1)?on_on.src:off_on.src;
		tab23.src = (curr==3)?on_on.src:on_off.src;
		break;
	case 3:
		tab23.src = (curr==2)?on_on.src:off_on.src;
		tab34.src = (curr==4)?on_on.src:on_off.src;
		break;
	case 4:
		tab34.src = (curr==3)?on_on.src:off_on.src;
		tab45.src = (curr==5)?on_on.src:on_off.src;
		break;
	case 5:
		tab45.src = (curr==4)?on_on.src:off_on.src;
		tab56.src = (curr==6)?on_on.src:on_off.src;
		break;
	case 6:
		tab56.src = (curr==5)?on_on.src:off_on.src;
		tab67.src = (curr==7)?on_on.src:on_off.src;
		break;
	case 7:
		tab67.src = (curr==6)?on_on.src:off_on.src;
		tab78.src = (curr==8)?on_on.src:on_off.src;
		break;
	case 8:
		tab78.src = (curr==7)?on_on.src:off_on.src;
		break;	
	}
	*/
}

function resetMnu(){
		/*
		tab12.src = off_off.src;
		tab23.src = off_off.src;
		tab34.src = off_off.src;
		tab45.src = off_off.src;
		tab56.src = off_off.src;
		tab67.src = off_off.src;
		tab78.src = off_off.src;
		
		switch(curr){
		case 1:
			tab12.src = on_off.src;
		break;
		case 2:
			tab12.src = off_on.src;
			tab23.src = on_off.src;
		break;
		case 3:
			tab23.src = off_on.src;
			tab34.src = on_off.src;
		break;
		case 4:
			tab34.src = off_on.src;
			tab45.src = on_off.src;
		break;
		case 5:
			tab45.src = off_on.src;
			tab56.src = on_off.src;
		break;
		case 6:
			tab56.src = off_on.src;
			tab67.src = on_off.src;
		break;
		case 7:
			tab67.src = off_on.src;
			tab78.src = on_off.src;
		break;
		case 8:
			tab78.src = off_on.src;
		break;
		}
	
		if(curr!=1){
			tab1.src = tab_1_off.src;
		}
		if(curr!=2){
			tab2.src = tab_2_off.src;
		}					
		if(curr!=3){
			tab3.src = tab_3_off.src;
		}						
		if(curr!=4){
			tab4.src = tab_4_off.src;
		}
		if(curr!=5){
			tab5.src = tab_5_off.src;
		}
		if(curr!=6){
			tab6.src = tab_6_off.src;
		}
		if(curr!=7){
			tab7.src = tab_7_off.src;
		}
		if(curr!=8){
			tab8.src = tab_8_off.src;
		}		
		*/
}

function doMenuP(show){
	
	if(show){
		 $('#MenuPanel').show();
		 $('#MenuPanel').animate({
			height: 250
		  }, 500, function() {
				loadMenu(true);
				menuVisible=true;
		  });  		 
	}
	else{
		loadMenu(false);
		$('#MenuPanel').animate({
			height: 0
		  }, 500, function() {
				// Animation complete.
				$('#MenuPanel').hide(); 
				menuVisible=false;
		  }); 		
		}
}

function loadMenu(show){
	if(show){
		 curr;
		 xmlhttp.onreadystatechange=function()
		  {
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				MenuPB.innerHTML=xmlhttp.responseText;
				$('#MenuPanelBody').fadeIn("fast");
			}
			else{
				$('#MenuPanelBody').hide();
				MenuPB.innerHTML = "loading....";
			}
		  }
		xmlhttp.open("GET","menusrc.php?tab="+curr,true);
		xmlhttp.send();
	}
	else{
		$('#MenuPanelBody').fadeOut("fast");
		MenuPB.innerHTML = "";
	}
}

function hideMenu(e){
	if(!menuVisible){return;}
	
	var e=e? e : window.event;
	var event_element=e.target? e.target : e.srcElement;
	var tg = document.getElementById("TopMenu");	
	
	var msg = "";	
	msg = msg + "ID: "+ event_element.id +"\n";
	msg = msg + "Tag: "+ event_element.nodeName  +"\n";
	msg = msg + "Par ID: "+ event_element.parentNode.id +"\n";
	msg = msg + "Par Tag: "+ event_element.parentNode.nodeName +"\n";
	//alert(msg);
	
	while (event_element != tg && event_element.nodeName != 'BODY'){
		event_element= event_element.parentNode
	}
	if (event_element!=tg){
		doMenuP(false);
	}		
}

/* ********************************************** */
/*
$(document).ready(function() {

	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});

});
*/

var xmlhttp, meTimer, findVisible = false;

function setXMLhttp(){
	if (window.XMLHttpRequest)
	{return new XMLHttpRequest();}
	else{return new ActiveXObject("Microsoft.XMLHTTP");}
} 

function efxOver(obj){
	obj.className = "itemover";
} 
function efxOut(obj){
	obj.className = "item";
} 

function searchNow(fld){
	var recipesDiv = document.getElementById("recipesDiv");
	var statsDiv = document.getElementById("statsDiv");
	var umeantDiv = document.getElementById("umeantDiv");
	cancelmeTimer();
	if(fld.value.length > 1)
	{
		xmlhttp = setXMLhttp();
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
			xmlDoc=xmlhttp.responseXML;
			var txt="";
			var umeant="";
			var recipe=xmlDoc.getElementsByTagName("recipe");
			var stats=xmlDoc.getElementsByTagName("stats");
			var didyoumean=xmlDoc.getElementsByTagName("youmean");				
			var r_count = parseInt(stats[0].getElementsByTagName("count")[0].childNodes[0].nodeValue);
			
			for (i=0;i<didyoumean.length;i++){
			  	if(didyoumean[i].hasChildNodes()){
					umeant = umeant + "<a href='javascript:void(0);' onclick='uMeant(\""+ didyoumean[i].firstChild.nodeValue +"\")'>" + didyoumean[i].firstChild.nodeValue + "</a>, ";				
			  	}
			}
			
			if(umeant!=''){  
			  umeant = umeant.slice(0, -2);
			  if(didyoumean.length>1){
				umeant = umeant  + " ...";
			  }
			}			
			
			for (i=0;i<recipe.length;i++){
				iid=recipe[i].getElementsByTagName("id")[0].firstChild.nodeValue;
				type=recipe[i].getElementsByTagName("type")[0].firstChild.nodeValue;
				title=recipe[i].getElementsByTagName("title")[0].firstChild.nodeValue;
				descr=recipe[i].getElementsByTagName("description")[0].firstChild.nodeValue;
				image=recipe[i].getElementsByTagName("image")[0].firstChild.nodeValue;
				poster=recipe[i].getElementsByTagName("poster")[0].firstChild.nodeValue;
				category=recipe[i].getElementsByTagName("category")[0].firstChild.nodeValue;
				rating=recipe[i].getElementsByTagName("rating")[0].firstChild.nodeValue;
				views=recipe[i].getElementsByTagName("views")[0].firstChild.nodeValue;
				votes=recipe[i].getElementsByTagName("votes")[0].firstChild.nodeValue;
				comments=recipe[i].getElementsByTagName("comments")[0].firstChild.nodeValue;
		  
				txt=txt + '<div class="item" onMouseover="efxOver(this);" onMouseout="efxOut(this);" onClick="gotoItem(\''+type+'\',\''+iid+'\')">';
				txt=txt + '<div class="itempic">';
				txt=txt + '<table id="reciPicture" width="110" border="0" cellpadding="0" cellspacing="0"><tr>';
				txt=txt + '    <td class="picFrame1"><img src="images/spacer.gif" width="10" height="10" alt=""></td>';
				txt=txt + '    <td class="picFrame2"><img src="images/spacer.gif" width="10" height="10" alt=""></td>';
				txt=txt + '    <td class="picFrame3"><img src="images/spacer.gif" width="10" height="10" alt=""></td>';
				txt=txt + '  </tr><tr>';
				txt=txt + '    <td class="picFrame4">&nbsp;</td>';
				txt=txt + '    <td class="picFrame5"><img src="'+image+'" class="itemimg"></td>';
				txt=txt + '    <td class="picFrame6">&nbsp;</td>';
				txt=txt + '  </tr><tr>';
				txt=txt + '    <td class="picFrame7"><img src="images/spacer.gif" width="10" height="10" alt=""></td>';
				txt=txt + '    <td class="picFrame8"><img src="images/spacer.gif" width="10" height="10" alt=""></td>';
				txt=txt + '    <td class="picFrame9"><img src="images/spacer.gif" width="10" height="10" alt=""></td>';
				txt=txt + '  </tr><tr>';
				txt=txt + '    <td colspan="3" class="itemrating"><img src="'+ imgs_path +'ratings_'+ parseInt(rating) +'.png"></td>';
				txt=txt + '  </tr></table>';
				txt=txt + '</div>';
				
				txt=txt + '<div class="itemdet">';
				txt=txt + '<div class="itemtitle">'+title+'</div>';
				txt=txt + '<div class="itemtxt">'+descr+'</div>';
				txt=txt + '	<div class="itemstats">';
				txt=txt + '		<img src="'+ imgs_path +'button_view.png" title="Viewed" />'+views+'&nbsp;&nbsp;&nbsp;';
				txt=txt + '		<img src="'+ imgs_path +'button_vote.png" title="Voted" />'+votes+'&nbsp;&nbsp;&nbsp;';
				txt=txt + '		<img src="'+ imgs_path +'button_comment.png" title="Commented" />'+comments;
				txt=txt + '	</div>';
				txt=txt + '</div>';
				txt=txt + '</div>';

			  }
				//recipesDiv.style.display="block"; 
				if(txt!=""){
					recipesDiv.scrollTop=0;
					recipesDiv.innerHTML=txt;
					
					if(r_count==1){
						statsDiv.innerHTML="Found "+ r_count +" recipe";
					}
					else if(r_count==51){
						statsDiv.innerHTML="Found more than "+ (r_count-1) +" recipes";
					}
					else{
						statsDiv.innerHTML="Found "+ r_count +" recipes";
					}
				
					if(umeant!="")
					{
						umeantDiv.innerHTML="Did you mean: "+ umeant;
					}
					else{
						umeantDiv.innerHTML="Search for: "+ fld.value;
					}
					if(!findVisible)
						show();					
				}
				else
				{
					if(findVisible)
						hide();
				}
			}
		  }
		xmlhttp.open("GET","srchrslts.php?q="+fld.value,true);
		xmlhttp.send();		
	}
	else
	{
		recipesDiv.innerHTML="";
		statsDiv.innerHTML="";
		umeantDiv.innerHTML="";
		//recipesDiv.style.display="none"; 
		if(findVisible)
			hide();
	}
}

function show(){
 if(findVisible)
	return;
	
 $('#resultDiv').animate({
    opacity: 1.0,
    height: 'show'
  }, 500, function() {
    // Animation complete.
	findVisible = true;
	doTest("State - Show: " + findVisible);
  });  
}

function hide(){
 if(!findVisible)
	return;
 
 $('#resultDiv').animate({
    opacity: 0.00,
    height: 'hide'
  }, 500, function() {
    // Animation complete.
	findVisible = false;
	doTest("State - Hide: " + findVisible);
  });  
}

function doHide(e){
	if(!findVisible){return;}
	var evt = e||event;
	var toElement = evt.relatedTarget || evt.toElement;
	if(toElement != null){
		//if(toElement.id!=""){doTest("Hide: "+toElement.id);}
		if(toElement.id == "content" || toElement.id == "resultDiv"){
			cancelmeTimer();
			meTimer = setTimeout(function() 
			{ 
				hide(); 
			}, 750); 			
		}
	}
}

function doShow(e){
	cancelmeTimer();
	if(findVisible){return;}

	if(meTimer){
		var evt = e||event;
		var toElement = evt.relatedTarget || evt.fromElement;
		
		if(toElement != null){
			//if(toElement.id!=""){doTest("Show: "+toElement.id);}
			if (toElement.id == "content"){
				cancelmeTimer();
				//show();		
			}
		}
	}
}

// cancel close timer
function cancelmeTimer()
{
	if(meTimer)
	{
		window.clearTimeout(meTimer);
		meTimer = null;
	}
}

function onclickHide(e){
	if(!findVisible){return;}
	
	var e=e? e : window.event;
	var event_element=e.target? e.target : e.srcElement;
	var tg = document.getElementById("hitareaDiv");	
	
	var msg = "";	
	msg = msg + "ID: "+ event_element.id +"\n";
	msg = msg + "Tag: "+ event_element.nodeName  +"\n";
	msg = msg + "Par ID: "+ event_element.parentNode.id +"\n";
	msg = msg + "Par Tag: "+ event_element.parentNode.nodeName +"\n";
	//alert(msg);
	
	while (event_element != tg && event_element.nodeName != 'BODY')
	{
		event_element= event_element.parentNode
	}
	if (event_element!=tg){
		hide();	
	}
}

function loadSrchBoxDefault(){
	(function(pElementId,pSearchText) {
			var el = document.getElementById(pElementId);
			if(el!=null){
			
			el.value = pSearchText;
			el.style.color="#999";
			
			el['onfocus'] = function() {
				if(el.value == pSearchText) {
					el.value = '';
					el.style.color="";
				}			
				else if(el.value!="" && el.value!= pSearchText){
					cancelmeTimer();
					searchNow(el);
				}			
			}		
			el['onblur'] = function() {
				if(el.value=='') {
					el.value = pSearchText;
					el.style.color="#999";
				}
			}
		}
	})('srchbox','Enter Recipe Name to Search...');
}

function uMeant(str){
	var el = document.getElementById("srchbox")
	el.value = str;
	searchNow(el);
	//alert(str);
}

function gotoItem(type, iid){
	switch (type)
	{
		case "R":
			jumpToURL("../recipes/recipes.php?rid="+iid);
		break;
		case "V":
			jumpToURL("../recipes/videos.php?vid="+iid);
		break;
		case "T":
			jumpToURL("../recipes/tipsntricks.php?tid="+iid);
		break;
		case "M":
			jumpToURL("../recipes/meals.php?mid="+iid);
		break;		
	}
}

function doTest(str){
	//document.getElementById("test").value = document.getElementById("test").value +str+"\n"
}

/* *********************************************** */
function rateItem(rate, item_type, item_id){

	xmlhttp = setXMLhttp();
	var url = "item_rating.php?"+item_type+"="+item_id+"&r="+rate;
	
	if (xmlhttp!=null)
	{
	  xmlhttp.onreadystatechange=showRateStatus;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.send(null);
	}
	else{
		alert('xmlhttp is null');
	}
}

function showRateStatus(){	
	if (xmlhttp.readyState==4){// 4 = "loaded"
		var rateMsg = document.getElementById("rateMsg");
		if (xmlhttp.status==200)
		{// 200 = "OK"
			rateMsg.innerHTML= xmlhttp.responseText;

		}
		else
		{
			rateMsg.innerHTML= "Problem Rating Item";
		}
		
		 $('#rateMsg').animate({
			opacity: 1.00,
			height: 'show'
		  }, 500, function() {
			// Animation complete.
			setTimeout('hideRater()', 3000);
		  });  
	}
}

function hideRater(){
	$('#rateMsg').animate({
		opacity: 0.00,
		height: 'hide'
	  }, 500, function() {
			// Animation complete.
			document.getElementById("rateMsg").innerHTML= "";
	 });  
}

function rateIt(rating){
	document.getElementById('item_rater').style.width = Math.round((rating/5)*100)+"%";
}
/* ********************************************* */

function mySortMe(the_url){
	var the_o = document.getElementById('o').value;
	var the_ad = document.getElementById('ad').value;
	window.location = the_url + "&o=" + the_o + "&ad=" + the_ad;
}

function validateEmail(email){   
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;   
   return emailPattern.test(email);   
} 

olddivName = "";
function showHideLeftMenuHead(divName){
	theDiv = document.getElementById('d'+divName);
	theImg = document.getElementById('img'+divName);

	if(theDiv.style.display =="none")
	{
	theDiv.style.display = "block";
	theImg.src = "../images/icon_expanded.gif";
		if(olddivName!=divName && olddivName!=""){
			showHideLeftMenuHead(olddivName)
		}
		olddivName = divName;
	}
	else
	{
	theDiv.style.display = "none";
	theImg.src= " ../images/icon_collapsed.gif";
		olddivName = "";
	}	
}

function verifyComment(frm){
	if (frm.cmnt_name.value ==""){
		alert("Your Name field is empty. Please enter your name.");
		return false;
	}
	if(frm.cmnt_notify.checked && frm.cmnt_email.value==""){
		alert("You have opted to receive comment updates but the email address is missing.");
		return false;
	}
	if(frm.cmnt_notify.checked && !validateEmail(frm.cmnt_email.value)){
		alert("You have opted to receive comment updates but the email address is invalid.");
		return false;
	}	
	if(frm.cmnt_txt.value==""){
		alert("Comments field is empty. Please enter your comments.");
		return false;
	}
	if(frm.cmnt_cpcha.value==""){
		alert("Code field is empty. Please enter the code as it appears on screen.");
		return false;
	}
	return true;
}

function getEmail4Cmnt(objFld){
	objDiv = document.getElementById('cmnt_div');
	if(objFld.checked){
		objDiv.style.display = "inline";
	}
	else{
		objDiv.style.display = "none";
	}
}

scrollStep=5;				
timerLeft="";
timerRight="";

function toLeft(id){
  document.getElementById(id).scrollLeft=0;
}

function scrollDivLeft(id){
  clearTimeout(timerRight) ;
  document.getElementById(id).scrollLeft+=scrollStep;
  timerRight=setTimeout("scrollDivLeft('"+id+"')",10);
}

function scrollDivRight(id){
  clearTimeout(timerLeft);
  document.getElementById(id).scrollLeft-=scrollStep;
  timerLeft=setTimeout("scrollDivRight('"+id+"')",10);
}

function toRight(id){
  document.getElementById(id).scrollLeft=document.getElementById(id).scrollWidth;
}

function stopMe(){
  clearTimeout(timerRight) ;
  clearTimeout(timerLeft);
}

function showCategory(id, cat){
	objDiv = document.getElementById(id);
	tabAllOff();
	if(cat=="recipe"){
		objDiv.scrollTop=0;
		document.getElementById("recipeTab").className="tabON";
	}
	if(cat=="video"){
		objDiv.scrollTop=120;
		document.getElementById("videoTab").className="tabON";
	}
	if(cat=="tips"){
		objDiv.scrollTop=240;
		document.getElementById("tipsTab").className="tabON";	
	}
	objDiv.scrollLeft=0;				
}

function tabAllOff(){
	document.getElementById("recipeTab").className="tabOFF";
	document.getElementById("videoTab").className="tabOFF";
	document.getElementById("tipsTab").className="tabOFF";				
}

function relatedItemTab(cat){	
	if(cat=="recipe"){
		document.getElementById("rel_recipeTAB").className="tabON";
		document.getElementById("rel_videoTAB").className="tabOFF";
		document.getElementById("rel_recipeDIV").style.display="block";
		document.getElementById("rel_videoDIV").style.display="none";
	}
	if(cat=="video"){
		document.getElementById("rel_videoTAB").className="tabON";
		document.getElementById("rel_recipeTAB").className="tabOFF";
		document.getElementById("rel_videoDIV").style.display="block";
		document.getElementById("rel_recipeDIV").style.display="none";
	}			
}

function selectedURL(fld){
	if(fld.selectedIndex > 0){
		jumpToURL(fld.options[fld.selectedIndex].value);
	}	
}

function jumpToURL(url){
	if(!url==""){
		window.location=url;
	}
}

$(document).ready(function() {
	init();
	//$('#MenuPanel').hide();	
	document.onclick  = docOnClick;
	loadSrchBoxDefault();
	loadNavigationBar();
	
	loadConnections();
})

function docOnClick(e){
	hideMenu(e);
	onclickHide(e);
}

function loadNavigationBar(){	
	/*
	$('#menu_1').bind({
		  click:function(){menuDo(1,2);},mouseover:function(){menuDo(1,1);},mouseout:function(){menuDo(1,0);}
	 });
	$('#menu_2').bind({
		  click:function(){menuDo(2,2);},mouseover:function(){menuDo(2,1);},mouseout:function(){menuDo(2,0);}
	 });
	$('#menu_3').bind({
		  click:function(){menuDo(3,2);},mouseover:function(){menuDo(3,1);},mouseout:function(){menuDo(3,0);}
	 });
	$('#menu_4').bind({
		  click:function(){menuDo(4,2);},mouseover:function(){menuDo(4,1);},mouseout:function(){menuDo(4,0);}
	 });
	$('#menu_5').bind({
		  click:function(){menuDo(5,2);},mouseover:function(){menuDo(5,1);},mouseout:function(){menuDo(5,0);}
	 });
	$('#menu_6').bind({
		  click:function(){menuDo(6,2);},mouseover:function(){menuDo(6,1);},mouseout:function(){menuDo(6,0);}
	 });
	$('#menu_7').bind({
		  click:function(){menuDo(7,2);},mouseover:function(){menuDo(7,1);},mouseout:function(){menuDo(7,0);}
	 });
	$('#menu_8').bind({
		  click:function(){menuDo(8,2);},mouseover:function(){menuDo(8,1);},mouseout:function(){menuDo(8,0);}
	 });
	
	on_on = new Image();
	on_off = new Image();
	off_on = new Image();
	off_off = new Image();
	
	on_on.src = imgs+"on_on.png";
	on_off.src = imgs+"on_off.png";
	off_on.src = imgs+"off_on.png";
	off_off.src = imgs+"off_off.png";
	
	tab_1_on = new Image();
	tab_1_off = new Image();
	tab_2_on = new Image();
	tab_2_off = new Image();
	tab_3_on = new Image();
	tab_3_off = new Image();
	tab_4_on = new Image();
	tab_4_off = new Image();
	tab_5_on = new Image();
	tab_5_off = new Image();
	tab_6_on = new Image();
	tab_6_off = new Image();
	tab_7_on = new Image();
	tab_7_off = new Image();
	tab_8_on = new Image();
	tab_8_off = new Image();
	
	tab_1_on.src = imgs+"1_on.png";
	tab_1_off.src = imgs+"1_off.png";
	tab_2_on.src = imgs+"2_on.png";
	tab_2_off.src = imgs+"2_off.png";
	tab_3_on.src  = imgs+"3_on.png";
	tab_3_off.src = imgs+"3_off.png";
	tab_4_on.src = imgs+"4_on.png";
	tab_4_off.src = imgs+"4_off.png";
	tab_5_on.src = imgs+"5_on.png";
	tab_5_off.src = imgs+"5_off.png";
	tab_6_on.src = imgs+"6_on.png";
	tab_6_off.src = imgs+"6_off.png";
	tab_7_on.src = imgs+"7_on.png";
	tab_7_off.src = imgs+"7_off.png";
	tab_8_on.src = imgs+"8_on.png";
	tab_8_off.src = imgs+"8_off.png";
	*/
	$('#TopMenu').fadeIn("slow");
}

function loadConnections()
{
	(function(d, s, id) {
	  var js, fjs = d.getElementsByTagName(s)[0];
	  if (d.getElementById(id)) {return;}
	  js = d.createElement(s); js.id = id;
	  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=113539727832";
	  fjs.parentNode.insertBefore(js, fjs);
	}(document, 'script', 'facebook-jssdk'));
	
	(function() {
		var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
		s.type = 'text/javascript';
		s.async = true;
		s.src = 'http://widgets.digg.com/buttons.js';
		s1.parentNode.insertBefore(s, s1);
	})();
	
	!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
	
	(function() {
		var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
		po.src = 'https://apis.google.com/js/plusone.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
	})();
	
	(function() { 
		var li = document.createElement('script'); li.type = 'text/javascript'; li.async = true; 
		li.src = 'https://platform.stumbleupon.com/1/widgets.js'; 
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(li, s); 
	})(); 
	
	adDelay.swapOut('connectionsholder','connectionbox');

}
/* ************************************************ */

/*
 * Name: Ad Delay v0.1 
 * License:  GNUv2 (www.gnu.org/licenses/gpl-2.0.txt)
 * Auther: Brian Gardner <getsnappy@ymail.com>
 * Usage:
 *
 * adDelay.swapOut(arg1, arg2)
 *     arg1 - the id of the placeholder div (in our example, skypePlaceholder)
 *     arg2 - the id of the dummy div (in our example, skypeDummy) 
 *
 */
var adDelay = {
  swapOut: function(placeholderId,dummyId) {
    var dummy = document.getElementById(dummyId);
    var placeholder = document.getElementById(placeholderId);
    if (!dummy) {
      alert("element with id " + dummyId + " does not exist");
    }
    if (!placeholder) {
      alert("element with id " + placeholderId + " does not exist");
    }

    /* loop through dummy nodes removing any JS nodes, preventing double execution */
    for (index = dummy.childNodes.length - 1; index >= 0; index--)
    {
      var element = dummy.childNodes[index];
      if ((element.nodeName == 'SCRIPT') || (element.nodeName == 'NOSCRIPT'))
              dummy.removeChild(element);
    }

    dummy.parentNode.removeChild(dummy);
    placeholder.parentNode.replaceChild(dummy, placeholder);
    dummy.style.display = 'block';
  }
};

/***** *** lightbox js ********/

 /**
 * jQuery Lightbox
 * Version 0.5 - 11/29/2007
 * @author Warren Krewenki
 *
 * Changes by:
 * @author Krzysztof Kotowicz <koto at webworkers dot pl>:
 *  - bugfix: multiple instances of Lightbox galleries allowed
 *    (using opts variable instead of $.fn.lightbox.defaults)
 *  - bugfix: use var for local variables in a few functions
 *  - added support for navbarOnTop setting
 *  - added support for displayTitle setting
 *  - added support for slideNavBar setting (with slideNavBarSpeed)
 *  - added support for displayHelp setting
 *  - added support for fitToScreen setting (ported Lightbox VinDSL hack)
 *    (see http://www.huddletogether.com/forum/comments.php?DiscussionID=307)
 *  - plugin now uses jQuery.width() and jQuery.height()
 *  - removed eval() calls
 *  - removed destroyElement - uses jQuery.remove()
 *  - use of prevLinkText, nextLinkText and help
 *  - all strings are now placed in opts.strings to allow for customization/translation
 *
 * Based on Lightbox 2 by Lokesh Dhakar (http://www.huddletogether.com/projects/lightbox2/)
 * Originally written to make use of the Prototype framework, and Script.acalo.us, now altered to use jQuery.
 *
 **/

(function($){
	var opts;

	$.fn.lightbox = function(options){
		// build main options
		opts = $.extend({}, $.fn.lightbox.defaults, options);

		// initalize the lightbox
		$.fn.lightbox.initialize();
		return this.each(function(){
			$(this).click(function(){
				$(this).lightbox.start(this);
				return false;
			});
		});
	};

	// lightbox functions
	$.fn.lightbox.initialize = function(){
		$('#overlay').remove();
		$('#lightbox').remove();
		opts.inprogress = false;
		var outerImage = '<div id="outerImageContainer"><div id="imageContainer"><img id="lightboxImage"><div id="hoverNav"><a href="javascript://" title="' + opts.strings.prevLinkTitle + '" id="prevLink"></a><a href="javascript://" id="nextLink" title="' + opts.strings.nextLinkTitle + '"></a></div><div id="loading"><a href="javascript://" id="loadingLink"><img src="'+opts.fileLoadingImage+'"></a></div></div></div>';
		var imageData = '<div id="imageDataContainer" class="clearfix"><div id="imageData"><div id="imageDetails"><span id="caption"></span><span id="numberDisplay"></span></div><div id="bottomNav">'

		if (opts.displayHelp)
			imageData += '<span id="helpDisplay">' + opts.strings.help + '</span>';

		imageData += '<a href="javascript://" id="bottomNavClose" title="' + opts.strings.closeTitle + '"><img src="'+opts.fileBottomNavCloseImage+'"></a></div></div></div>';

		var string;

		if (opts.navbarOnTop) {
		  string = '<div id="overlay"></div><div id="lightbox">' + imageData + outerImage + '</div>';
		  $("body").append(string);
		  $("#imageDataContainer").addClass('ontop');
		} else {
		  string = '<div id="overlay"></div><div id="lightbox">' + outerImage + imageData + '</div>';
		  $("body").append(string);
		}

		$("#overlay").click(function(){ $.fn.lightbox.end(); }).hide();
		$("#lightbox").click(function(){ $.fn.lightbox.end();}).hide();
		$("#loadingLink").click(function(){ $.fn.lightbox.end(); return false;});
		$("#bottomNavClose").click(function(){ $.fn.lightbox.end(); return false; });
		$('#outerImageContainer').width(opts.widthCurrent).height(opts.heightCurrent);
		$('#imageDataContainer').width(opts.widthCurrent);
	};

	$.fn.lightbox.getPageSize = function(){
		var xScroll, yScroll;

		if (window.innerHeight && window.scrollMaxY) {
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}

		var windowWidth, windowHeight;

		if (self.innerHeight) { // all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth;
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}

		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else {
			pageHeight = yScroll;
		}


		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){
			pageWidth = xScroll;
		} else {
			pageWidth = windowWidth;
		}

		var arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
		return arrayPageSize;
	};


	$.fn.lightbox.getPageScroll = function(){
		var xScroll, yScroll;

		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
			xScroll = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){  // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
			xScroll = document.documentElement.scrollLeft;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
			xScroll = document.body.scrollLeft;
		}

		var arrayPageScroll = new Array(xScroll,yScroll);
		return arrayPageScroll;
	};

	$.fn.lightbox.pause = function(ms){
		var date = new Date();
		var curDate = null;
		do{curDate = new Date();}
		while( curDate - date < ms);
	};

	$.fn.lightbox.start = function(imageLink){

		$("select, embed, object").hide();
		var arrayPageSize = $.fn.lightbox.getPageSize();
		$("#overlay").hide().css({width: '100%', height: arrayPageSize[1]+'px', opacity : opts.overlayOpacity}).fadeIn();
		opts.imageArray = [];
		imageNum = 0;

		var anchors = document.getElementsByTagName( imageLink.tagName);

		// if image is NOT part of a set..
		if(!imageLink.rel || (imageLink.rel == '')){
			// add single image to Lightbox.imageArray
			opts.imageArray.push(new Array(imageLink.href, opts.displayTitle ? imageLink.title : ''));
		} else {
		// if image is part of a set..
			$("a").each(function(){
				if(this.href && (this.rel == imageLink.rel)){
					opts.imageArray.push(new Array(this.href, opts.displayTitle ? this.title : ''));
				}
			})


			for(i = 0; i < opts.imageArray.length; i++){
				for(j = opts.imageArray.length-1; j>i; j--){
					if(opts.imageArray[i][0] == opts.imageArray[j][0]){
						opts.imageArray.splice(j,1);
					}
				}
			}
			while(opts.imageArray[imageNum][0] != imageLink.href) { imageNum++;}
		}

		// calculate top and left offset for the lightbox
		var arrayPageScroll = $.fn.lightbox.getPageScroll();
		var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 10);
		var lightboxLeft = arrayPageScroll[0];
		$('#lightbox').css({top: lightboxTop+'px', left: lightboxLeft+'px'}).show();


		if (!opts.slideNavBar)
			$('#imageData').hide();

		$.fn.lightbox.changeImage(imageNum);

	};

	$.fn.lightbox.changeImage = function(imageNum){
		if(opts.inprogress == false){
			opts.inprogress = true;
			opts.activeImage = imageNum;	// update global var

			// hide elements during transition
			$('#loading').show();
			$('#lightboxImage').hide();
			$('#hoverNav').hide();
			$('#prevLink').hide();
			$('#nextLink').hide();

			if (opts.slideNavBar) { // delay preloading image until navbar will slide up
				// $('#imageDataContainer').slideUp(opts.navBarSlideSpeed, $.fn.doChangeImage);
				$('#imageDataContainer').hide();
				$('#imageData').hide();
				$.fn.doChangeImage();
			} else {
			    $.fn.doChangeImage();
			}
		}
	};

	$.fn.doChangeImage = function(){

		imgPreloader = new Image();

		// once image is preloaded, resize image container
		imgPreloader.onload=function(){
		    var newWidth = imgPreloader.width;
		    var newHeight = imgPreloader.height;


			if (opts.fitToScreen) {
		        var arrayPageSize = $.fn.lightbox.getPageSize();
				var ratio;
				var initialPageWidth = arrayPageSize[2] - 2 * opts.borderSize;
				var initialPageHeight = arrayPageSize[3] - 200;

				if (imgPreloader.height > initialPageHeight)
				{
					newWidth = parseInt((initialPageHeight/imgPreloader.height) * imgPreloader.width);
					newHeight = initialPageHeight;
				}
				else if (imgPreloader.width > initialPageWidth)
				{
					newHeight = parseInt((initialPageWidth/imgPreloader.width) * imgPreloader.height);
					newWidth = initialPageWidth;
				}
			}

			$('#lightboxImage').attr('src', opts.imageArray[opts.activeImage][0])
							   .width(newWidth).height(newHeight);
			$.fn.lightbox.resizeImageContainer(newWidth, newHeight);
		}

		imgPreloader.src = opts.imageArray[opts.activeImage][0];
	}
	
	$.fn.lightbox.end = function(){
		$.fn.lightbox.disableKeyboardNav();
		$('#lightbox').hide();
		$('#overlay').fadeOut();
		$('select, object, embed').show();
	};

	$.fn.lightbox.preloadNeighborImages = function(){
		if((opts.imageArray.length - 1) > opts.activeImage){
			preloadNextImage = new Image();
			preloadNextImage.src = opts.imageArray[opts.activeImage + 1][0];
		}
		if(opts.activeImage > 0){
			preloadPrevImage = new Image();
			preloadPrevImage.src = opts.imageArray[opts.activeImage - 1][0];
		}
	};

	$.fn.lightbox.keyboardAction = function(e){
		if (e == null) { // ie
			var keycode = event.keyCode;
			var escapeKey = 27;
		} else { // mozilla
			var keycode = e.keyCode;
			var escapeKey = e.DOM_VK_ESCAPE;
		}

		var key = String.fromCharCode(keycode).toLowerCase();

		if((key == 'x') || (key == 'o') || (key == 'c') || (keycode == escapeKey)){ // close lightbox
			$.fn.lightbox.end();
		} else if((key == 'p') || (keycode == 37)){ // display previous image
			if(opts.activeImage != 0){
				$.fn.lightbox.disableKeyboardNav();
				$.fn.lightbox.changeImage(opts.activeImage - 1);
			}
		} else if((key == 'n') || (keycode == 39)){ // display next image
			if(opts.activeImage != (opts.imageArray.length - 1)){
				$.fn.lightbox.disableKeyboardNav();
				$.fn.lightbox.changeImage(opts.activeImage + 1);
			}
		}
	};

	$.fn.lightbox.resizeImageContainer = function(imgWidth, imgHeight){
		// get current width and height
		opts.widthCurrent = document.getElementById('outerImageContainer').offsetWidth;
		opts.heightCurrent = document.getElementById('outerImageContainer').offsetHeight;

		// get new width and height
		var widthNew = (imgWidth  + (opts.borderSize * 2));
		var heightNew = (imgHeight  + (opts.borderSize * 2));

		// scalars based on change from old to new
		opts.xScale = ( widthNew / opts.widthCurrent) * 100;
		opts.yScale = ( heightNew / opts.heightCurrent) * 100;

		// calculate size difference between new and old image, and resize if necessary
		wDiff = opts.widthCurrent - widthNew;
		hDiff = opts.heightCurrent - heightNew;

		$('#imageDataContainer').animate({width: widthNew},opts.resizeSpeed,'linear');
		$('#outerImageContainer').animate({width: widthNew},opts.resizeSpeed,'linear',function(){
			$('#outerImageContainer').animate({height: heightNew},opts.resizeSpeed,'linear',function(){
				$.fn.lightbox.showImage();
			});
		});


		// if new and old image are same size and no scaling transition is necessary,
		// do a quick pause to prevent image flicker.
		if((hDiff == 0) && (wDiff == 0)){
			if (jQuery.browser.msie){ $.fn.lightbox.pause(250); } else { $.fn.lightbox.pause(100);}
		}

		$('#prevLink').height(imgHeight);
		$('#nextLink').height(imgHeight);
	};

	$.fn.lightbox.showImage = function(){
		$('#loading').hide();
		$('#lightboxImage').fadeIn("fast");
		$.fn.lightbox.updateDetails();
		$.fn.lightbox.preloadNeighborImages();

		opts.inprogress = false;
	};

	$.fn.lightbox.updateDetails = function(){

		if(opts.imageArray[opts.activeImage][1]){
			$('#caption').html(opts.imageArray[opts.activeImage][1]).show();
		}

		// if image is part of set display 'Image x of x'
		if(opts.imageArray.length > 1){
			var nav_html;

			nav_html = opts.strings.image + (opts.activeImage + 1) + opts.strings.of + opts.imageArray.length;

			// display previous / next text links
			if ((opts.activeImage) > 0) {
				nav_html = '<a title="' + opts.strings.prevLinkTitle + '" href="#" id="prevLinkText">' + opts.strings.prevLinkText + "</a>" + nav_html;
			}

			if ((opts.activeImage + 1) < opts.imageArray.length) {
				nav_html += '<a title="' + opts.strings.nextLinkTitle + '" href="#" id="nextLinkText">' + opts.strings.nextLinkText + "</a>";
			}

			$('#numberDisplay').html(nav_html).show();
		}

		if (opts.slideNavBar) {
		    $("#imageData").slideDown(opts.navBarSlideSpeed);
		} else {
			$("#imageData").show();
		}

		var arrayPageSize = $.fn.lightbox.getPageSize();
		$('#overlay').height(arrayPageSize[1]);
		$.fn.lightbox.updateNav();
	};

	$.fn.lightbox.updateNav = function(){
		$('#hoverNav').show();

		// if not first image in set, display prev image button
		if(opts.activeImage != 0){
			$('#prevLink,#prevLinkText').show().click(function(){
				$.fn.lightbox.changeImage(opts.activeImage - 1); return false;
			});
		}

		// if not last image in set, display next image button
		if(opts.activeImage != (opts.imageArray.length - 1)){
			$('#nextLink,#nextLinkText').show().click(function(){

				$.fn.lightbox.changeImage(opts.activeImage +1); return false;
			});
		}

		$.fn.lightbox.enableKeyboardNav();
	};


	$.fn.lightbox.enableKeyboardNav = function(){
		document.onkeydown = $.fn.lightbox.keyboardAction;
	};

	$.fn.lightbox.disableKeyboardNav = function(){
		document.onkeydown = '';
	};

	$.fn.lightbox.defaults = {
		fileLoadingImage : 'images/loading.gif',
		fileBottomNavCloseImage : 'images/closelabel.gif',
		overlayOpacity : 0.8,
		borderSize : 10,
		imageArray : new Array,
		activeImage : null,
		inprogress : false,
		resizeSpeed : 350,
		widthCurrent: 250,
		heightCurrent: 250,
		xScale : 1,
		yScale : 1,
		displayTitle: true,
		navbarOnTop: false,
		slideNavBar: false, // slide nav bar up/down between image resizing transitions
		navBarSlideSpeed: 350,
		displayHelp: false,
		strings : {
			help: ' \u2190 / P - previous image\u00a0\u00a0\u00a0\u00a0\u2192 / N - next image\u00a0\u00a0\u00a0\u00a0ESC / X - close image gallery',
			prevLinkTitle: 'previous image',
			nextLinkTitle: 'next image',
			prevLinkText:  '&laquo; Previous',
			nextLinkText:  'Next &raquo;',
			closeTitle: 'close image gallery',
			image: 'Image ',
			of: ' of '
		},
		fitToScreen: false		// resize images if they are bigger than window
	};
})(jQuery);



/******************************************************************/
