// ---------------------------------[ variable declarations ]-------------------------------------------	
var undefined;
current_sidenavitem_set = false;
current_topnavitem_set = false;
submenu_built = false;
var subnav_selected;

url = location.href;
urldetermine = url.substring(url.lastIndexOf("/")+1);
urlend = url.substring(url.lastIndexOf("/")+1, url.length-4);
urlextract = urlend.split("_");
//if(urldetermine.substring(urldetermine.lastIndexOf(".")) != ".php" || urlextract[0] == "index"){
if(urlextract[0] == "index"){
	urlextract[0] = "home"; 
}

var browsercheck = navigator.userAgent.toLowerCase();
var is_mac = (browsercheck.indexOf("mac")!=-1); 
if (browsercheck.indexOf("safari") != -1) {
	the_browser = "safari";
}else if (browsercheck.indexOf("netscape") != -1) {
	the_browser = "ns";
}else {
	the_browser = "other";
}
/*
window.moveTo(0,0);
if (the_browser == "safari") {   
	window.resizeTo(screen.availWidth,screen.availHeight-10); 
}else if (the_browser == "ns") {   
	window.outerHeight = screen.availHeight-30;   
	window.outerWidth = screen.availWidth; 
}else {   
	window.resizeTo(screen.availWidth,screen.availHeight-30); 
}
*/

function orderform(){
	this.location.replace("../menus/menus_sandwiches.php");
	openNewWindow('https://web0.lightlink.com/~ramseyny/pages/order/orderform.php',the_browser,is_mac);
}

function feedbackform(){
	openFBWindow('feedbackform.php',the_browser,is_mac);
}

function imagepop(section,targetpic){
	w = 800;
	h = screen.height;
	winl = (screen.width - w) / 2;
	wint = (screen.height - h) / 2;
	settins = "toolbar=no,width="+w+",height="+h+",left="+winl+",top="+wint+",directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no,location=no,copyhistory=no";
	popWin = window.open("","popWin",settins);
	//window.focus();
	/*
	popWin.document.write("<HTML><HEAD><TITLE>Image Enlargement<\/TITLE><link rel=\"stylesheet\" type=\"text\/css\" href=\"butes.css\"><\/HEAD>");
	popWin.document.write("<BODY><table border='0' cellpadding='0' cellspacing='0' height=\"100%\" width='100%'><tr><td valign='middle' align='center' height=\"100%\" width='100%'>");
	popWin.document.write("<img src='..\/images\/" + section + "\/" + targetpic + "_l.jpg' name=\"bigpic\" border='0' \/>");
	popWin.document.write("<\/td><\/tr><\/table><\/BODY><\/HTML>");
	*/
	var addtext = "<HTML><HEAD><TITLE>Image Enlargement<\/TITLE><link rel=\"stylesheet\" type=\"text\/css\" href=\"butes.css\"><\/HEAD>";
	addtext += "<BODY><table border='0' cellpadding='0' cellspacing='0' height=\"100%\" width='100%'><tr><td valign='middle' align='center' height=\"100%\" width='100%'>";
	addtext += "<img src='..\/..\/images\/gifts\/" + section + "\/" + targetpic + "_l.jpg' name=\"bigpic\" border='0' \/>";
	addtext += "<\/td><\/tr><\/table><\/BODY><\/HTML>";
	popWin.document.write(addtext);
	popWin.document.close();
	popWin.focus();
}


function imagepop2(section,targetpic){
	if (section == "gear"){
		w = 800;
		h = screen.height;
	}else{
		w = 600;
		h = 700;
	}
	winl = (screen.width - w) / 2;
	wint = (screen.height - h) / 2;
	settins = "toolbar=no,width="+w+",height="+h+",left="+winl+",top="+wint+",directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no,location=no,copyhistory=no";
	popWin = window.open("http://www.ithacabakery.com/pages/gifts/gifts_img_pop.php?section="+section+"&id="+targetpic,"popWin",settins);
	/*var addtext = "<HTML><HEAD><TITLE>Image Enlargement<\/TITLE><link rel=\"stylesheet\" type=\"text\/css\" href=\"butes.css\"><\/HEAD>";
	addtext += "<BODY><table border='0' cellpadding='0' cellspacing='0' height=\"100%\" width='100%'><tr><td valign='middle' align='center' height=\"100%\" width='100%'>";
	addtext += "<img src='..\/..\/images\/gifts\/" + section + "\/" + targetpic + "_l.jpg' name=\"bigpic\" border='0' \/>";
	addtext += "<\/td><\/tr><\/table><\/BODY><\/HTML>";
	popWin.document.write(addtext);
	popWin.document.close();*/
	popWin.focus();
}



function imagepop3(section,targetpic,image_filename){
	if (section == "gear"){
		w = 800;
		h = screen.height;
	}else{
		w = 600;
		h = 700;
	}
	winl = (screen.width - w) / 2;
	wint = (screen.height - h) / 2;
	settins = "toolbar=no,width="+w+",height="+h+",left="+winl+",top="+wint+",directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no,location=no,copyhistory=no";
	popWin = window.open("http://www.ithacabakery.com/pages/gifts/gifts_img_pop.php?section="+section+"&id="+targetpic+"&image_filename="+image_filename,"popWin",settins);
	popWin.focus();
}


function openNewWindow(theURL,the_browser, is_mac) {
	if (the_browser == "safari") {
		//alert(is_mac);
	//if(is_mac){
		w = 500;
		h = 474;
	}else {
		w = 500;
		h = 459;
	}
	launchCenter(theURL,w,h);
}

function openFBWindow(theURL,the_browser, is_mac) {
	if (the_browser == "safari") {
		//alert(is_mac);
	//if(is_mac){
		w = 457;
		h = 665;
	}else {
		w = 457;
		h = 638;
	}
	launchCenter(theURL,w,h);
}

function openNewWindow2(theURL) {
	newURL = theURL + ".php";
	w = 500;
	h = 300;
	launchCenter(newURL,w,h);
}

function openSignUp()
{
	newURL = "http://www.ithacabakery.com/pages/home/signup_pop.php";
	w = 500;
	h = 300;
	launchCenter(newURL,w,h);
}

function launchCenter(url, width, height) {
	//theurl = "..\/
	var str = "height=" + height + ",innerHeight=" + height;
	str += ",width=" + width + ",innerWidth=" + width;
	if (window.screen) {
		var ah = screen.availHeight - 30 ;
		var aw = screen.availWidth - 10 ;
		var xc = (aw - width) / 2;
		var yc = (ah - height) / 2;

 	   str += ",left=" + xc + ",screenX=" + xc;
 	   str += ",top=" + yc + ",screenY=" + yc;
 	   str += ",status=yes,scrollbars=yes,resizable=yes";
	}
	sitepopped = window.open(url,'sitepopped',str);
}

// ---------------------------------[ set up navigation arrays ]-------------------------------------------	
sidenav_array = [
	
	['menus','29'],
	['catering','31'],
	['gifts','32'],
	['careers','32'],
	['about','32'],
	['events','36'],
	['fun','35'],
	['contact','35']
	
];
nav_preloader('sidenav'); // calls nav image preloader function

menus_array = [
	
	['feature','58'],
	['sandwiches','86'],
	['soups','105'],
	['entrees','60'],
	['breads','111'],
	['drinks','54'],
	['dessert','57']
	
];
nav_preloader('menus');

gifts_array = [
	
	['cards','99'],
	['baskets','104'],
	['gear','107']
	
];
nav_preloader('gifts');

about_array = [
	
	['locations','87'],
	['newsletter','99']
	
];
nav_preloader('about');

fun_array = [
	
	['qtvr','133'],
	['coloring','181']
	
];
nav_preloader('fun');

catering_array = [
	
	['horsdoeuvres','102'],
	['bbq','45'],
	['breakfast','72'],
	['entrees','60'],
	['soups','142'],
	['breads','54'],
	['dessert','56']
	
];
nav_preloader('catering');


// ---------------------------------[ runs through each item in targeted nav array and calls setup function to preload images ]-------------------------------------------	
function nav_preloader(array_target){
	for (i=0; i<=this[array_target + "_array"].length-1; i++){
		setup(array_target, this[array_target + "_array"][i][0],1);
	}
}
		
// ---------------------------------[ preload nav element images ]-------------------------------------------			
function setup(type, arg1, toggle) {
	if(toggle == 1){
		if(type == "sidenav"){
			var path = "..\/..\/images\/sidenav\/";
			this[arg1 + "_off"] = new Image();
			this[arg1 + "_off"].src = path + arg1 + "_off.gif";
			this[arg1 + "_over"] = new Image();
			this[arg1 + "_over"].src = path + arg1 + "_over.gif";
			this[arg1 + "_on"] = new Image();
			this[arg1 + "_on"].src = path + arg1 + "_on.gif";
		}else{
			var path = "..\/..\/images\/submenus\/";
			this[type + "_" + arg1 + "_off"] = new Image();
			this[type + "_" + arg1 + "_off"].src = path + type + "_" + arg1 + "_off.gif";
			this[type + "_" + arg1 + "_over"] = new Image();
			this[type + "_" + arg1 + "_over"].src = path + type + "_" + arg1 + "_over.gif";
			this[type + "_" + arg1 + "_on"] = new Image();
			this[type + "_" + arg1 + "_on"].src = path + type + "_" + arg1 + "_on.gif";
		}
	}else {
		var path = "..\/..\/images\/subsubnav\/";
		this[type + "_" + arg1 + "_off"] = new Image();
		this[type + "_" + arg1 + "_off"].src = path + type + "_" + arg1 + "_off.gif";
		this[type + "_" + arg1 + "_over"] = new Image();
		this[type + "_" + arg1 + "_over"].src = path + type + "_" + arg1 + "_over.gif";
	}
}

sand_subsub_array = [
	
	['deli','160'],
	['bagel','150'],
	['specialty','145']
	['panini','145']
	
];
subsubnav_preloader('sand');

feasts_subsub_array = [
	
	['breakfast','160'],
	['lunch','150'],
	['dinner','145'],
	['barbeques','145']
	
];
subsubnav_preloader('feasts');

gear_subsub_array = [
	
	['gear','132'],
	['wear','132'],
	['kids','93']
	
];
subsubnav_preloader('gear');

events_subsub_array = [
	
	['exhibits','160'],
	['music','150'],
	['tastings','145'],
	['special','145']
	
];
subsubnav_preloader('events');

function subsubnav_preloader(array_target){
	for (i=0; i<=this[array_target + "_subsub_array"].length-1; i++){
		setup(array_target, this[array_target + "_subsub_array"][i][0]);
	}
}

// --------------------[ rollover ]---------------------------------------------
function change(target, imgName) {
	if(target == "nav"){
		document[target + "_" + imgName].src = eval(imgName + "_over.src");
	}else {
		document[target + "_" + imgName].src = eval(target + "_" + imgName + "_over.src");
	}
}

function subsubchange(target, imgName) {
	document[target + "_" + imgName].src = eval(target + "_" + imgName + "_over.src");
}
function subsubchange2(target, imgName) {
	document[target + "_" + imgName].src = "../../images/subsubnav/" + target + "_" + imgName + "_over.gif";
}
// --------------------[ rollout ]---------------------------------------------
function back(target, imgName) {
	if(target == "nav"){
		document[target + "_" + imgName].src = eval(imgName + "_off.src");
	}else {
		document[target + "_" + imgName].src = eval(target + "_" + imgName + "_off.src");
	}
}

function subsubback(target, imgName) {
	document[target + "_" + imgName].src = eval(target + "_" + imgName + "_off.src");
}
function subsubback2(target, imgName) {
	document[target + "_" + imgName].src = "../../images/subsubnav/" + target + "_" + imgName + "_off.gif";
}
// --------------------[ iteratively builds out the navigation table for targeted group ]---------------------------------------------
function activate(group){
	if(group == "sidenav"){
		for (i=0; i<=this[group +  "_array"].length-1; i++){
			build_nav(sidenav_array[i][0], sidenav_array[i][1]);
		}
		document.close();
	}else {
		var the_topnav = "";
		for (i=0; i<=this[group + "_array"].length-1; i++){
			the_topnav += build_nav(this[group + "_array"][i][0], this[group + "_array"][i][1], group);
		}
		return the_topnav;
	}
}

// --------------------[ function that sets up structure for navigation ]---------------------------------------------
function build_nav(name, d_size, page) {
	if(page == undefined){
		var navmaker = "<div id=\"sidenav_" + page + "\">";
		if(name != urlextract[0]){
			navmaker += "<a href=\"..\/" + name + "\/" + name + ".php\" onFocus=\"this.blur()\" onMouseOver=\"change('nav','" + name + "'); return true\" onMouseOut=\"back('nav','" + name + "'); return true\"><img src=\"..\/..\/images\/sidenav\/" + name + "_off.gif\" name=\"nav_" + name + "\" width=\"119\" height=\"" + d_size + "\" alt=\"" + name + "\" border=\"0\" \/><\/a>";
		}else{
			navmaker += "<img src=\"..\/..\/images\/sidenav\/" + name + "_on.gif\" name=\"nav_" + name + "\" width=\"119\" height=\"" + d_size + "\" alt=\"" + name + "\" border=\"0\" \/>";
		}
		navmaker += "<\/div>";
		document.write(navmaker);
	}else{
		var navmaker = "<span id=\"" + page + "_" + name + "\">";
		if(name != urlextract[1]){
			navmaker += "<a href=\"" + page + "_" + name + ".php\" onFocus=\"this.blur()\" onMouseOver=\"change('" + page + "','" + name + "'); return true\" onMouseOut=\"back('" + page + "','" + name + "'); return true\"><img src=\"..\/..\/images\/submenus\/" + page + "_" + name + "_off.gif\" name=\"" + page + "_" + name + "\" width=\"" + d_size + "\" height=\"50\" alt=\"" + name + "\" border=\"0\" \/><\/a>";
		}else{
			navmaker += "<img src=\"..\/..\/images\/submenus\/" + page + "_" + name + "_on.gif\" name=\"" + page + "_" + name + "\" width=\"" + d_size + "\" height=\"50\" alt=\"" + name + "\" border=\"0\" \/>";
		}
		navmaker += "<\/span>";
		return navmaker;
	}
}

// --------------------[ puts up header graphic or sub-navigation for targeted page ]---------------------------------------------
function build_contentheader(){
	var page = urlextract[0];
	current_topnavitem_set = false;
	if(page == "menus" || page == "about" || page == "fun" || page == "catering" || page == 'gifts'){
		var c_header = activate(page);
	}else if (page == "home") {
		var c_header = maketitle(0,page,page,'Welcome to the Bakery',1);
	}
	return c_header;
}

// --------------------[ puts up the top image on the tan box, sets up the content area for the box ]---------------------------------------------
function build_subheader(){
	var subhead = "<tr>";
		subhead += "<td valign=\"top\" align=\"center\" width=\"531\" height=\"50\">";
		subhead += "<img src=\"..\/..\/images\/global\/spacer.gif\" width=\"531\" height=\"1\" alt=\"\" border=\"0\" /><br\/>";
		subhead += build_contentheader();
		subhead += "<\/td>";
		subhead += "<\/tr>";
	document.write(subhead);
}

function build_tantop(headertoggle){
	var tantopcont = "<tr>";
	if(headertoggle == 1){
		tantopcont += "<td valign=\"top\" align=\"center\" width=\"531\" class=\"tantop\">";
		tantopcont += build_contentheader();
	}else {
		tantopcont += "<td valign=\"top\" align=\"center\" width=\"531\" class=\"tantop2\">";
		tantopcont += "<img src=\"..\/..\/images\/global\/spacer.gif\" width=\"531\" height=\"22\" alt=\"\" border=\"0\" \/>";
	}
		tantopcont += "<\/td>";
		tantopcont += "<\/tr>";
		tantopcont += "<tr>";
		tantopcont += "<td class=\"tancontent\" width=\"519\">";
	document.write(tantopcont);
}

// --------------------[ closes the tan box content area and puts up the bottom image for the box ]---------------------------------------------
function build_tanbottom(){
	var tanbotcont = "<\/td>";
		tanbotcont += "<\/tr>";
		tanbotcont += "<tr>";
		tanbotcont += "<td>";
		tanbotcont += "<img src=\"..\/..\/images\/global\/tanslab_bottom.gif\" width=\"531\" height=\"20\" alt=\"\" border=\"0\" \/>";
		tanbotcont += "<\/td>";
		tanbotcont += "<\/tr>";
	document.write(tanbotcont);
}

function maketitle(toggle, filename, id, alt,toggle2){
	the_title = "<img src=\"..\/..\/images\/titles\/" + filename + ".gif\" id=\"" + id + "\" width=\"462\" height=\"50\" border=\"0\" alt=\"" + alt + "\" \/>";
	if(toggle == 1){
		the_title += "<a href=\"#top\" onFocus=\"this.blur()\"><img src=\"..\/..\/images\/global\/backtotop.gif\" id=\"deli\" width=\"69\" height=\"50\" border=\"0\" alt=\"back to top\" \/><\/a>";
	}else {
		the_title += "<img src=\"..\/..\/images\/global\/spacer.gif\" id=\"" + id + "\" width=\"69\" height=\"50\" border=\"0\" alt=\"" + alt + "\" \/>";
	}
	if(toggle2 == 1){
		return the_title;
	}else{
		document.write(the_title);
	}
}