// JavaScript Document

function prepareNav() {
	var navBar = document.getElementById('nav');
	var menuOptions = navBar.getElementsByTagName('li');
	var subMenus;
	for (var i=0; i < menuOptions.length; i++) {
		subMenus = menuOptions[i].getElementsByTagName('ul');
		if (subMenus.length > 0) {
			activateSubMenu(menuOptions[i]);
		}
	}
}

function prepareClickableBoxes() {
	var leftBox = document.getElementById('leftContentBox');
	var rightBox = document.getElementById('rightContentBox');
	
	leftBox.onmouseover = function() {	changeState("over", this);}
	leftBox.onmouseout = function() {changeState("out", this);}
	leftBox.onclick = function() {window.location = "http://www.buysunsavvyplans.com/";}
	rightBox.onmouseover = function() {	changeState("over", this);}
	rightBox.onmouseout = function() {changeState("out", this);}
	rightBox.onclick = function() {window.location = "packages.php";}
}

function activateSubMenu(object) {
	object.onmouseover = function() {
		var links = this.getElementsByTagName('a');
		var subMenu = this.getElementsByTagName('ul');
		links[0].style.background = "#AF591E";
		subMenu[0].style.display = "block";
	}
	object.onmouseout = function() {
		var links = this.getElementsByTagName('a');
		var subMenu = this.getElementsByTagName('ul');
		links[0].style.background = "none";
		subMenu[0].style.display = "none";
	}
}

function changeState(state, object) {
	var box = object;
	var boxChild = box.getElementsByTagName("div");
	if (state == "over") {
		box.style.background = "#8C8E5F url(../images/contentBox_ov_bottom.jpg) 0 bottom no-repeat";
		boxChild[0].style.backgroundImage = "url(../images/contentBox_ov_top.jpg)"
		box.style.cursor = "pointer";
	} else {
		box.style.background = "#B2B87A url(../images/contentBox_bottom.jpg) 0 bottom no-repeat";
		boxChild[0].style.backgroundImage = "url(../images/contentBox_top.jpg)"
		box.style.cursor = "default";
	}
}
