var preloadImages = false;

var nav_home_out = new Image();
var nav_locations_out = new Image();
var nav_menu_out = new Image();
var nav_dining_out = new Image();
var nav_cards_out = new Image();
var nav_press_out = new Image();
var nav_team_out = new Image();
var nav_community_out = new Image();
var nav_contact_out = new Image();
var nav_blog_out = new Image();

nav_home_out.src = "images/nav_home.gif";
nav_locations_out.src = "images/nav_locations.gif";
nav_menu_out.src = "images/nav_menu.gif";
nav_dining_out.src = "images/nav_dining.gif";
nav_cards_out.src = "images/nav_cards.gif";
nav_press_out.src = "images/nav_press.gif";
nav_team_out.src = "images/nav_team.gif";
nav_community_out.src = "images/nav_community.gif";
nav_contact_out.src = "images/nav_contact.gif";
nav_blog_out.src = "images/nav_blog.gif";

var nav_home_over = new Image();
var nav_locations_over = new Image();
var nav_menu_over = new Image();
var nav_dining_over = new Image();
var nav_cards_over = new Image();
var nav_press_over = new Image();
var nav_team_over = new Image();
var nav_community_over = new Image();
var nav_contact_over = new Image();
var nav_blog_over = new Image();

nav_home_over.src = "images/nav_home_on.gif";
nav_locations_over.src = "images/nav_locations_on.gif";
nav_menu_over.src = "images/nav_menu_on.gif";
nav_dining_over.src = "images/nav_dining_on.gif";
nav_cards_over.src = "images/nav_cards_on.gif";
nav_press_over.src = "images/nav_press_on.gif";
nav_team_over.src = "images/nav_team_on.gif";
nav_community_over.src = "images/nav_community_on.gif";
nav_contact_over.src = "images/nav_contact_on.gif";
nav_blog_over.src = "images/nav_blog_on.gif";

preloadImages = true;

function changeImage(imgName, imgState) {

	if (preloadImages) {
	
		window.document.images[imgName].src = eval("nav_" + imgName + "_" + imgState + ".src");
		
	}
	
}

var topImages = new Array();
topImages[0] = '<img src="images/top1.jpg" width="229" height="111" alt="" />';
topImages[1] = '<img src="images/top2.jpg" width="229" height="111" alt="" />';
topImages[2] = '<img src="images/top3.jpg" width="229" height="111" alt="" />';
topImages[3] = '<img src="images/top4.jpg" width="229" height="111" alt="" />';
var T = topImages.length;
var whichTopImage = Math.round(Math.random() * (T - 1));

function showTopImage() {

	document.write(topImages[whichTopImage]);
	
}

var leftImages = new Array();
leftImages[0] = '<img src="images/left_chestnut.jpg" width="206" height="311" alt="" />';
leftImages[1] = '<img src="images/left_entrance.jpg" width="206" height="311" alt="" />';
leftImages[2] = '<img src="images/left_ceviche.jpg" width="206" height="311" alt="" />';
leftImages[3] = '<img src="images/left_dessert.jpg" width="206" height="311" alt="" />';
leftImages[4] = '<img src="images/left_drinks.jpg" width="206" height="311" alt="" />';
leftImages[5] = '<img src="images/left_chalkboard2.jpg" width="206" height="311" alt="" />';
leftImages[6] = '<img src="images/left_salmon.jpg" width="206" height="311" alt="" />';
leftImages[7] = '<img src="images/left_trio.jpg" width="206" height="311" alt="" />';
leftImages[8] = '<img src="images/left_sandwich.jpg" width="206" height="311" alt="" />';
leftImages[9] = '<img src="images/left_platters.jpg" width="206" height="311" alt="" />';
leftImages[10] = '<img src="images/left_sushi1.jpg" width="206" height="311" alt="" />';
leftImages[11] = '<img src="images/left_chalkboard.jpg" width="206" height="311" alt="" />';
leftImages[12] = '<img src="images/left_taco.jpg" width="206" height="311" alt="" />';
leftImages[13] = '<img src="images/left_sushi2.jpg" width="206" height="311" alt="" />';
var L = leftImages.length;
var whichLeftImage = Math.round(Math.random() * (L - 1));

function showLeftImage() {

	document.write(leftImages[whichLeftImage]);
	
}

var rightImages = new Array();
rightImages[0] = '<img src="images/right_chestnut.jpg" width="164" height="760" alt="" />';
rightImages[1] = '<img src="images/right_cm1.jpg" width="164" height="760" alt="" />';
rightImages[2] = '<img src="images/right_cmbar.jpg" width="164" height="760" alt="" />';
rightImages[3] = '<img src="images/right_cm3.jpg" width="164" height="760" alt="" />';
rightImages[4] = '<img src="images/right_cmbar2.jpg" width="164" height="760" alt="" />';
rightImages[5] = '<img src="images/right_cmbar3.jpg" width="164" height="760" alt="" />';
rightImages[6] = '<img src="images/right_9th.jpg" width="164" height="760" alt="" />';
var R = rightImages.length;
var whichRightImage = Math.round(Math.random() * (R - 1));

function showRightImage() {

	document.write(rightImages[whichRightImage]);
	
}

var menu1 = new Array();
menu1[0] = '<a href="locations_cm.html">Corte Madera</a>';
menu1[1] = '<a href="locations_na.html">San Francisco - 9th Ave</a>';
menu1[2] = '<a href="locations.html">San Francisco - Marina</a>';
menu1[3] = '<a href="locations_campbell.html">Campbell</a>';


var menu2 = new Array();
menu2[0] = '<a href="menu.html">San Francisco - Marina</a>';
menu2[1] = '<a href="menu_na.html">San Francisco - 9th Ave</a>';
menu2[2] = '<a href="menu_cm.html">Corte Madera</a>';
menu2[3] = '<a href="menu_campbell.html">Campbell</a>';

var menu3 = new Array();
menu3[0] = '<a href="dining.html">Corte Madera</a>';
menu3[1] = '<a href="dining.html">San Francisco - 9th Ave</a>';
menu3[2] = '<a href="dining_ch.html">San Francisco - Marina</a>';
menu3[3] = '<a href="dining.html">Campbell</a>';
		
var menuwidth = '164px';
var menubgcolor = '#FFFFFF';
var disappeardelay = 250;
var hidemenu_onclick = "yes";

var currentImgName = '';
var currentImgState = '';

var ie4 = document.all;
var ns6 = document.getElementById && !document.all;

if (ie4 || ns6)

	document.write('<div id="dropmenudiv" style="visibility:hidden; width:' + menuwidth + '; background-color:' + menubgcolor + '" onmouseover="javascript:clearhidemenu();" onmouseout="javascript:dynamichide(event);"></div>');
	
function getposOffset(what, offsettype) {

	var totaloffset = (offsettype == "left") ? what.offsetLeft : what.offsetTop;
	var parentEl = what.offsetParent;
	
	while (parentEl != null) {
	
		totaloffset = (offsettype == "left") ? totaloffset + parentEl.offsetLeft : totaloffset + parentEl.offsetTop;
		parentEl = parentEl.offsetParent;
		
	}
	
	return totaloffset;
	
}


function showhide(obj, e, visible, hidden, menuwidth) {

	if (ie4 || ns6)
	
		dropmenuobj.style.left = dropmenuobj.style.top = "-500px";
		
	if (menuwidth != "") {
	
		dropmenuobj.widthobj = dropmenuobj.style;
		dropmenuobj.widthobj.width = menuwidth;
		
	}
	
	if (e.type == "click" && obj.visibility == hidden || e.type == "mouseover")
	
		obj.visibility = visible;
		
	else if (e.type == "click")
	
		obj.visibility = hidden;
		
}

function iecompattest() {

	return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
	
}

function clearbrowseredge(obj, whichedge) {

	var edgeoffset = 0;
	
	if (whichedge == "rightedge") {
	
		var windowedge = ie4 && !window.opera ? iecompattest().scrollLeft + iecompattest().clientWidth - 15 : window.pageXOffset + window.innerWidth - 15;
		dropmenuobj.contentmeasure = dropmenuobj.offsetWidth;
		
		if (windowedge - dropmenuobj.x < dropmenuobj.contentmeasure)
		
			edgeoffset = dropmenuobj.contentmeasure - obj.offsetWidth;
			
	} else {
	
		var topedge = ie4 && !window.opera ? iecompattest().scrollTop : window.pageYOffset;
		var windowedge = ie4 && !window.opera ? iecompattest().scrollTop + iecompattest().clientHeight - 15 : window.pageYOffset + window.innerHeight - 18;
		dropmenuobj.contentmeasure = dropmenuobj.offsetHeight;
		
		if (windowedge - dropmenuobj.y < dropmenuobj.contentmeasure) {
		
			edgeoffset = dropmenuobj.contentmeasure + obj.offsetHeight;
			
			if ((dropmenuobj.y - topedge) < dropmenuobj.contentmeasure)
			
				edgeoffset = dropmenuobj.y + obj.offsetHeight - topedge;
				
		}
		
	}
	
	return edgeoffset;
	
}

function populatemenu(what) {

	if (ie4 || ns6)
	
		dropmenuobj.innerHTML = what.join("");
		
}


function dropdownmenu(obj, e, menucontents, menuwidth, imgName, imgState) {

	if (currentImgName != '')
	
		changeImage(currentImgName, 'out');
		
	changeImage(imgName, imgState);
	currentImgName = imgName;
	currentImgState = 'out';
	
	if (window.event)
	
		event.cancelBubble = true;
		
	else if (e.stopPropagation)
	
		e.stopPropagation();
		
	clearhidemenu();
	dropmenuobj = document.getElementById ? document.getElementById("dropmenudiv") : dropmenudiv;
	populatemenu(menucontents);
	
	if (ie4 || ns6) {
	
		showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth);
		dropmenuobj.x = getposOffset(obj, "left");
		dropmenuobj.y = getposOffset(obj, "top");
		dropmenuobj.style.left = dropmenuobj.x - clearbrowseredge(obj, "rightedge") + "px";
		dropmenuobj.style.top = dropmenuobj.y - clearbrowseredge(obj, "bottomedge") + obj.offsetHeight + "px";
		
	}
	
	return clickreturnvalue()

}

function clickreturnvalue() {

	if (ie4 || ns6)
	
		return false;
		
	else
	
		return true;
		
}

function contains_ns6(a, b) {

	while (b.parentNode)
	
		if ((b = b.parentNode) == a)
		
			return true;
			
	return false;
	
}

function dynamichide(e) {

	if (ie4 && !dropmenuobj.contains(e.toElement))
	
		delayhidemenu();
		
	else if (ns6 && e.currentTarget != e.relatedTarget && !contains_ns6(e.currentTarget, e.relatedTarget))
	
		delayhidemenu();
		
}

function hidemenu(e){

	if (currentImgName != '') {
	
		changeImage(currentImgName, currentImgState);
		currentImgName = '';
		currentImgState = '';
		
	}
	
	if (typeof dropmenuobj != "undefined") {
	
		if (ie4 || ns6)
		
			dropmenuobj.style.visibility = "hidden";
			
	}
	
}

function delayhidemenu() {

	if (ie4 || ns6)
	
		delayhide = setTimeout("hidemenu()", disappeardelay);
		
}

function clearhidemenu() {

	if (typeof delayhide != "undefined")
	
		clearTimeout(delayhide);
		
}

if (hidemenu_onclick == "yes")

	document.onclick = hidemenu;
