// Menu Drop Down / Random Image on Homepage
// ------------------------------------------------------
function initMenu(){
	var nodes = document.getElementById("menu").getElementsByTagName("li");
	for (var i=0; i<nodes.length; i++){
		nodes[i].onmouseover = function(){
			this.className += " hover";
		}
		nodes[i].onmouseout = function(){
			this.className = this.className.replace(" hover", "");
		}
	}
}

function initMenuPadd() {
	var _nav = document.getElementById("menu");
	if (_nav)
	{
		var _temp_span;
		var _a_width;
		var _dropul = _nav.getElementsByTagName("div");
		for (var j = 0; j < _dropul.length; j++)
		{
			if (_dropul[j].className.indexOf('menu')!=-1) {
				_dropul[j].style.width = _dropul[j].parentNode.offsetWidth + 8+"px";
			}
		}
	}
}

function randomLoad() {
	var _list = [
		'home_leadership.jpg',
		'home_kickball.jpg',
		'home_greenbean.jpg',
		'home_grasshoppers.jpg',
		'home_centercity.jpg',
		'home_ontap.jpg',
		'home_bikers.jpg'
	];
	var _url = '/custom/images_content/'
	var _img = document.getElementById('main-img');
	if(_img){
		var _r = Math.floor(Math.random() * _list.length);
		_img.src = _url + _list[_r];
		_img.style.display = 'block';
	}
}

// Size the img to the browser dimensions on the homepage
// ------------------------------------------------------
function initResizeImg()
{
	// We only want to set this up on the homepage
	var location = window.location.pathname;
	var locationArr = location.split('/');
	
	//if( ( locationArr[1] == 'index.php' && (locationArr[2] == '' || locationArr[2] == null) ) || locationArr[1] == '')
	
	var body = document.getElementsByTagName("body")[0];
	
	if (window.addEventListener) {
		window.addEventListener("resize", resizeMainImg, false);
	}
	else if (document.all && !window.opera){
		window.attachEvent("onresize", resizeMainImg);
	}
    
	// Set the initial size
	resizeMainImg();
}


function resizeMainImg()
{
	// Calculate the width for different browsers
	var browserWidth = 0;
	if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
	  //IE 6+ in 'standards compliant mode'
	  browserWidth = document.documentElement.clientWidth;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
	  //IE 4 compatible
	  browserWidth = document.body.clientWidth;
	}
	
	// Resizing the main-img on the homepage
	var img = document.getElementById('main-img');
	if(img)
	{
		// Now make the image the same size as the browser
		if(browserWidth > 980)
			img.width = browserWidth;
		else
			img.width = 980;

		img.style.display = 'block';
	}
		
	// Smart Float - text only wraps around img at a certain width
	var smartImg = document.getElementById('smart_float');
	if(smartImg)
	{
		// Standards Browsers
	
			if(browserWidth > 1100)
			{
				smartImg.style.cssFloat = "left";
				smartImg.style.styleFloat = "left";
			}
			else
			{
				smartImg.style.cssFloat = "none";
				smartImg.style.styleFloat = "none";
			}
				
		
		// // IE
		// if(smartImg.style.styleFloat)
		// {
		// 	if(browserWidth > 1100)
		// 		smartImg.style.styleFloat = "left";
		// 	else
		// 		smartImg.style.styleFloat = "none";
		// }
	}
}

// Open a new window for certain movies
// ------------------------------------------------------
// function initPopupVideo()
// {
// 	var videoLink = document.getElementById('popup_video');
// 	if(videoLink)
// 	{
// 		videoLink.href = "";
// 		videoLink.addEventListener("click", videoLinkClickHandler, false);
// 	}
// }
// 
// function videoLinkClickHandler(event)
// {
// 	openNewWindow('/custom/images_content/logo_city_academy.jpg', 300, 200, "video");
// 	return false;
// }

function openNewWindow (url,wid,hei,ty)
{
	settings="toolbar=no, location=no, directories=no,"+"statusbar=no, menubar=no, personalbar=no, scrollbars=no,"+"resizable=no, width="+wid+", height="+hei;
	window.open(url, ty, settings);
}


// Init Event Listeners 
// ------------------------------------------------------
if (window.addEventListener){
	//window.addEventListener("load", randomLoad, false);
	window.addEventListener("load", initResizeImg, false);
	window.addEventListener("load", initMenuPadd, false);
	//window.addEventListener("load", initPopupVideo, false);
}
else if (document.all && !window.opera){
	//window.attachEvent("onload", randomLoad);
	window.attachEvent("onload", initResizeImg);
	window.attachEvent("onload", initMenuPadd);
	window.attachEvent("onload", initMenu);
	//window.attachEvent("onload", initPopupVideo);
}