function mouseClick(id) {
    document.getElementById(id).src="images/" + id + "_on.png";
}

function mouseHover(id) {
	if (selectedType != id) {
		document.getElementById(id).src="images/" + id + "_hover.png";
	}
}

var selectedType = "";

function clearLinks() {
	mouseOut('seventh_hill');
	mouseOut('menu');
	mouseOut('hours');
	mouseOut('contact');
	mouseOut('comment');
}

function setSelectedType(type) {
    selectedType = type;
	var content = '';
	if (type == 'hours') {
		content = 'Step right up to our bar or enjoy inside and outside seating. We offer carry our and you may call ahead if you wish to have your order ready when you arrive.<br><br><b>Lunch</b><br>Tuesday - Sunday 11am - 2:30pm<br><b>Dinner</b><br>Tuesday - Sunday 5pm - 11pm';
		//document.getElementById('div_content').innerHTML = content;
	}
	changeImage(type,"images/" + type + "_on.png");
}

function mouseOut(id) {
    if (selectedType != id) {
        document.getElementById(id).src="images/" + id + "_off.png";
    }
}

function initImage() {
    var timer = 4000;
	rotateImage(timer, 2);
    timer += 6000;
    rotateImage(timer, 3);
    timer += 6000;
    rotateImage(timer, 4);
    timer += 6000;
    rotateImage(timer, 5);
}

var fadeO = new Array();
var fadeI = new Array();
var cImage = new Array();
var mouseOv = new Array();
var mouseOu = new Array();

function rotateImage(delay, imageNum) {
    imageId = 'thephoto';
	image = document.getElementById(imageId);
	setOpacity(image, 100);
	image.style.visibility = "visible";
	fadeIn(imageId,0);
    fadeO[imageNum-1] = setTimeout("fadeOut(imageId,100);", delay);
    delay += 1300;
    cImage[imageNum-1] = setTimeout("changeImage('images/homepage_center_" + imageNum + ".jpg')", delay);
    delay += 300;
    mouseOv[imageNum-1] = setTimeout("mouseOver('center_" + imageNum + "', 'center_image_" + imageNum + "')", delay);
    if (imageNum == 1) {
        imageNum = 2;
    }
    mouseOu[imageNum-1] = setTimeout("mouseOut('center_" + (imageNum-1) + "', 'center_image_" + (imageNum-1) + "')", delay);
    delay+= 100;
    fadeI[imageNum-1] = setTimeout("fadeIn(imageId,0)", delay);
}

var stopped = false;

function stopChange() {
    stopped = true;
    clearDots();
    for (i=0; i < fadeO.length; i++) {
        clearTimeout(fadeO[i]);
    }
    for (i=0; i < cImage.length; i++) {
        clearTimeout(cImage[i]);
    }
    for (i=0; i < mouseOv.length; i++) {
        clearTimeout(mouseOv[i]);
    }
    for (i=0; i < mouseOu.length; i++) {
        clearTimeout(mouseOu[i]);
    }
    for (i=0; i < fadeI.length; i++) {
        clearTimeout(fadeI[i]);
    }
    snapIn('thephoto');
}

function changeImage(id, src) {
    document.getElementById(id).src = src;
}

function snapIn(objId) {
    if (document.getElementById) {
		obj = document.getElementById(objId);
        setOpacity(obj, 100);
	}
}

function fadeIn(objId,opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			setOpacity(obj, opacity);
			opacity += 5;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 50);
		}
	}
}

function fadeOut(objId,opacity) {
	if (document.getElementById) {
        if (!stopped) {
            obj = document.getElementById(objId);
            if (opacity >= 0) {
                setOpacity(obj, opacity);
                opacity -= 5;
                window.setTimeout("fadeOut('"+objId+"',"+opacity+")", 50);
            }
        } else {
            snapIn('thephoto');
        }
    }
}

function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}

function getMenu(admin, type) {
    var xmlhttp;
    if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        alert("Your browser does not support XMLHTTP!");
    }

    xmlhttp.onreadystatechange = function() {
        if(xmlhttp.readyState == 4) {
            document.getElementById('menu').innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","../getMenu.jsp?type=" + type + (admin ? "&admin=true" : ""), true);
    xmlhttp.send(null);
}
