
var div_obj;
var previous_menu = "";
var close_menu = "";

function showMenu(menu_id) {
	if (theme != "accessible") {
		// show a sub-menu now
		submenu_id = menu_id + "_sub";
		if (document.getElementById(submenu_id)) {
			document.getElementById(submenu_id).style.display = "block";
			changeClass(menu_id, "_h");
			//close_menu = setTimeout("hideMenu('" + submenu_id + "')", 1000);
		}
		if ((previous_menu != "")&&(previous_menu != submenu_id)) {
			hideMenu(previous_menu);
			if(previous_menu == submenu_id) {
				submenu_id = "";	
			}
		}
		previous_menu = submenu_id;
	}
}

function stopHideMenu(menu_id) {
	// stop a previously scheduled sub-menu from hiding
	if (theme != "accessible") {
		clearTimeout(close_menu);
	}
}

function reHideMenu(submenu_id) {
	// hide the sub-menu in a second
	if (theme != "accessible") {
		close_menu = setTimeout("hideMenu('" + submenu_id + "')", 1000);
	}
}

function hideMenu(submenu_id) {
	// hide a sub-menu now
	if (theme != "accessible") {
		menu_id = submenu_id.substring(0, submenu_id.length - 4);
		clearTimeout(close_menu);
		document.getElementById(submenu_id).style.display = "none";
		changeClass(menu_id, "_n");
	}
}

function changeClass(div_obj, state) {
	class_name = document.getElementById(div_obj).className;
	class_name = class_name.substring(0, class_name.length - state.length) + state;
	document.getElementById(div_obj).className = class_name;	
}


/* code from mnk3 - check it's still needed */

function imagechange(image,id) {
	document.images[id].src = image + ".jpg";
}

function imageCaptionChange(image,id,caption) {
	document.images[id].src = "large/" + image + ".jpg";
	document.getElementById(id + "Caption").innerHTML = caption;
}
	var myurl;

windowopened=false;

function openWindow(myid, mywidth, myheight) {
	myurl = "images/" + myid + ".jpg";
	if ((windowopened==true) && (win.closed==false)) {
		win.close();
	}
	setTimeout("openWindow2("+mywidth+","+myheight+")",300);
}

function openWindow2(mywidth,myheight){
	win = window.open (myurl, "picwindow","width="+(mywidth+20)+",height=" +(myheight+25));
	windowopened=true;
}

function openWindowPortrait(myid) {
	myurl = "images/" + myid + ".jpg";
	if ((windowopened==true) && (win.closed==false)) {
		win.close();
	}
	setTimeout("openWindowPortrait2()",300);
}

function openWindowPortrait2(){
	win = window.open (myurl, "picwindow", "width=435, height=635, scrollbars=yes, 	resizable");
	windowopened=true;
}

function maillink(subject) {
	document.location = "/contact/";
}

function changeUnit(unit){
	var divs=document.getElementsByTagName('div');
	for(i in divs){
		if(divs[i].className==unit){
			divs[i].style.display='inline';
		}else if(divs[i].className=='met' || divs[i].className=='imp' || divs[i].className=='cup'){
			divs[i].style.display='none';
		}
	}
}

function changeTemp(temp){
	var divs=document.getElementsByTagName('div');
	for(i in divs){
		if(divs[i].className==temp){
			divs[i].style.display='inline';
		}else if(divs[i].className=='cel' || divs[i].className=='far' || divs[i].className=='gas'){
			divs[i].style.display='none';
		}
	}
}

function convertUnits(from_amount,from_unit,to_unit,to_amount){
		switch(from_unit){
			case 'ml':
					switch(to_unit){
						case 'fl_oz': changeUnit =from_amount/28.4; break;
						case 'ml': changeUnit =from_amount; break;
					}
				 break;
			case 'fl_oz':
					switch(to_unit){
						case 'ml': changeUnit =from_amount*28.4; break;
						case 'fl_oz': changeUnit =from_amount; break;
					}
				 break;
			case 'cent':
					switch(to_unit){
						case 'fahr': changeUnit =(9/5*(from_amount))+32; break;
						case 'cent': changeUnit =from_amount; break;
					}
				 break;
			case 'fahr':
					switch(to_unit){
						case 'cent': changeUnit =(from_amount-32)*5/9; break;
						case 'fahr': changeUnit =from_amount; break;
					}
				 break;
			case 'cm':
					switch(to_unit){
						case 'in': changeUnit =from_amount/2.54; break;
						case 'cm': changeUnit =from_amount; break;
					}
				 break;
			case 'in':
					switch(to_unit){
						case 'cm': changeUnit =from_amount*2.54; break;
						case 'in': changeUnit =from_amount; break;
					}
				 break;
			case 'g':
					switch(to_unit){
						case 'oz': changeUnit =from_amount/28.4; break;
						case 'g': changeUnit =from_amount; break;
					}
				 break;
			case 'oz':
					switch(to_unit){
						case 'g': changeUnit =from_amount*28.4; break;
						case 'oz': changeUnit =from_amount; break;
					}
				 break;
		}
		to_amount.innerHTML = roundAccuracy(changeUnit,2)+'  ';
}

function roundAccuracy(num, accuracy){
   var factor=Math.pow(10,accuracy);
   return Math.round(num*factor)/factor;
}

function convertCups(unit, gram_weight,to_amount){
	switch(unit){
			case 'g':
				to_amount.innerHTML = gram_weight;
				break;
			case 'oz':
				convertUnits(gram_weight,"g","oz",to_amount);
				break;
	}
}

function closewindowreload() {
  opener.location.reload(true);
  self.close();
}

function showHide(sID) {
	objDiv = document.getElementById(sID);
	if (objDiv) {
		if (objDiv.style.display != "none") {
			objDiv.style.display = "none";
		} else {
			objDiv.style.display = "block";
		}
	}
}