﻿function addLoadEvent(func){
	var oldonload = window.onload;
	if(typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function newImage( imgSrc ){
 
	var imgName = new Image();
	imgName.src = imgSrc;
	
	return imgName;

}

function preloadPics() {
	if (document.images)
	{
	
		defaultImage = newImage("images/toppic-default.jpg");
		cateringImage = newImage("images/toppic-catering.jpg");
		dinnerImage = newImage("images/toppic-dinner.jpg");
		drinksImage = newImage("images/toppic-drinks.jpg");
		lunchImage = newImage("images/toppic-lunch.jpg");
		specialsImage = newImage("images/toppic-specials.jpg");

/*	sets default top image - not necessary because set in CSS	
		if (!document.getElementById("top")) return false;
		if (!document.getElementsByTagName("body")) return false;
	
	
		var body = document.getElementsByTagName("body");
		var bodyClass = body[0].className;
		var topImage = document.getElementById("top");
		topImage.style.backgroundImage = "url('images/toppic-" + bodyClass + ".jpg')";
*/
	}

}

function prepLinks(){
	if (!document.getElementById) return false;
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById("menu")) return false;
	if (!document.getElementsByTagName("body")) return false;

	/* preps menu links */
	var menu = document.getElementById("menu");
	var links = menu.getElementsByTagName("a");
	for ( var i=0; i < links.length; i++) {
		links[i].onmouseover=function(){
			change(this);
			return false;
		}
		links[i].onmouseout=function(){
			changeback();
			return false;
		}
	}
	
}

function change(imgid){

	if (!document.getElementById("top")) return false;
	var title = imgid.getAttribute("title");
	var imgsource = "images/toppic-" + title + ".jpg";
	var topImage = document.getElementById("top");
	topImage.style.backgroundImage = "url('" + imgsource + "')";
}

function changeback(){
	if (!document.getElementById("top")) return false;
	if (!document.getElementsByTagName("body")) return false;
	var body = document.getElementsByTagName("body");
	var bodyClass = body[0].className;
	var topImage = document.getElementById("top");
	topImage.style.backgroundImage = "url('images/toppic-" + bodyClass + ".jpg')";
}


addLoadEvent(preloadPics);
addLoadEvent(prepLinks);