var aboutButton, compButton;
var aboutMenu, compMenu;
var isOpen = false;
var imgLoader = [];

function createCookie(name,value,hours) {
	if (hours) {
		var date = new Date();
		date.setTime(date.getTime()+(hours*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function mouseOver(butt) {
	if(butt == aboutButton) {
		compButton.oldMouseOut();
		compMenu.style.display = 'none';
	} else if(butt == compButton) {
		aboutButton.oldMouseOut()
		aboutMenu.style.display = 'none';
	} else {
		aboutButton.oldMouseOut();
		compButton.oldMouseOut();
		aboutMenu.style.display = 'none';
		compMenu.style.display = 'none';
	}
}

window.onload = function() {
	var imagePath = "images/menu/";
	
	$A($("menu").getElementsByTagName("a")).each(function(ob) {
		ob.imgRef = ob.getElementsByTagName('img')[0];
		ob.oldSrc = ob.imgRef.getAttribute("src");
		ob.overSrc = imagePath + ob.imgRef.getAttribute("alt");
		
		var imgTemp = new Image();
		imgTemp.src = ob.overSrc;
		//imgLoader.push(imgTemp);
		
		ob.onmouseover = function () {
			this.imgRef.src = this.overSrc;
			this.style.backgroundColor = "#ff5206";
			mouseOver(this);
		}
		
		ob.onmouseout = function() {
			this.imgRef.src = this.oldSrc;
			this.style.backgroundColor = "#ff3d08";
		}
	});
	
	aboutButton = $("about_button");
	compButton = $("comp_button");
	
	compMenu = $("comp_submenu");
	aboutMenu = $("about_submenu");
	
	aboutButton.onmouseover = function() {
		aboutMenu.style.display = 'block';
		this.imgRef.src = this.overSrc;
		this.style.backgroundColor = "#ff5206";
		mouseOver(this);
	};
	
	compButton.onmouseover = function() {
		compMenu.style.display = 'block';
		this.imgRef.src = this.overSrc;
		this.style.backgroundColor = "#ff5206";
		mouseOver(this);
	};
	
	aboutButton.oldMouseOut = aboutButton.onmouseout;
	compButton.oldMouseOut = aboutButton.onmouseout;
	aboutButton.onmouseout = compButton.onmouseout = null;
	
	// I needed to cut 2 pixels off the actual width for IE here
	var so = new SWFObject("includes/flash/gsh_break3.swf", "slideshow", "250", "140", "7", "#ED3F0D");
	
	if(!(readCookie("guttSmokeStarted") == "yes")) {
		createCookie("guttSmokeStarted", "yes", 1);
	} else {
		so.addVariable("skipIntro", "yes");
	}
	
	so.write("smokeholder");
}

