//______________________  BEGIN HOMEPAGE TAKEOVER _______________________//




// TOPNAV HOVER FOR IE
tnHover = function() {
	var topNav = document.getElementById("topnav");
	if (topNav == null) return;
	
	var tnEls = topNav.getElementsByTagName("LI");
	if (tnEls == null) return;
	
	for (var i=0; i<tnEls.length; i++) {
		tnEls[i].onmouseover=function() {
			this.className+=" tnhover";
		}
		tnEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" tnhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", tnHover);


// TOOLTIP HOVER FOR IE
ttHover = function() {
    var topNav = document.getElementById("ttroll");
    if (topNav == null) return;

    var tnEls = topNav.getElementsByTagName("A");
    if (tnEls == null) return;

    for (var i = 0; i < tnEls.length; i++) {
        tnEls[i].onmouseover = function() {
            this.className += " tthover";
        }
        tnEls[i].onmouseout = function() {
            this.className = this.className.replace(new RegExp(" tthover\\b"), "");
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", ttHover);



// SIMPLE HIDE/SHOW DIV FUNCTION
// MUST SUPPLY DIV ID 
function hidediv(div_id) {
	document.getElementById(div_id).style.display = 'none';
}
function showdiv(div_id) {
	document.getElementById(div_id).style.display = 'block';
}



//POPUP FOR GAMES
function gamepop(url, width, height) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height+"');");
}

//called from flash to popup new windows
function openNewWindow(URLtoOpen, windowName, windowFeatures) { 

  newWindow=window.open(URLtoOpen, windowName, windowFeatures);

}


// JAVASCRIPT/FLASH SWITCH COMMERCIAL
function changeCommercial(divId){
    var youtubeId = "";
    var mainID = document.getElementById('flashtv');
	var subDivs = mainID.getElementsByTagName('div');
	for (var i=0;i<subDivs.length;i++){
		subDivs[i].style.display = "none";
	}

	if (divId == "ad15") { youtubeId = "J8399YS36yQ"; }
	else if (divId == "ad16") { youtubeId = "9OIJBkhLMYg"; }
	else if (divId == "ad17") { youtubeId = "sU_mSVep62k"; }
	else if (divId == "ad18") { youtubeId = "En8s4nXM6Lk"; }
	youtubeId = youtubeId + "?enablejsapi=1&playerapiid=tvplayer&fs=0&rel=0";
	so = new SWFObject("http://www.youtube.com/v/" + youtubeId, "tv", "400", "326", "9.0.47.0");
	so.addParam('wmode', 'transparent');
	so.addParam('allowScriptAccess', 'always');
	so.addParam('allowFullScreen', 'true');
    so.write("ad");
    document.getElementById("ad").style.display = "block";
}

//function to set a cookie
function set_cookie(name, value, exp_y, exp_m, exp_d, path, domain, secure) {
    var cookie_string = name + "=" + escape(value);

    if (exp_y) {
        var expires = new Date(exp_y, exp_m, exp_d);
        cookie_string += "; expires=" + expires.toGMTString();
    }

    if (path)
        cookie_string += "; path=" + escape(path);

    if (domain)
        cookie_string += "; domain=" + escape(domain);

    if (secure)
        cookie_string += "; secure";

    document.cookie = cookie_string;
}

//function to delete a cookie by name
function delete_cookie(cookie_name) {
    var cookie_date = new Date();  // current date & time
    cookie_date.setTime(cookie_date.getTime() - 1);
    document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

//function to get a cookie by name
function get_cookie(cookie_name) {
    var results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');

    if (results)
        return (unescape(results[2]));
    else
        return null;
}

// TABS FOR "KNOW WHATS IN YOUR JUICE" PAGE

//Reset Tabs
function resetTabs() {
    $("img#tabOriginal").attr("src", "../App_Themes/Tools/images/kwiyj/original_tab_off.gif");
    //$("img#tabStages").attr("src", "../App_Themes/Tools/images/kwiyj/stages_tab_off.gif");
    $("img#tabSparkling").attr("src", "../App_Themes/Tools/images/kwiyj/sparkling_tab_off.gif");
}

//Set Current Tab
function setTab(tab) {
    if (tab == 0) { $("img#tabOriginal").attr("src", "../App_Themes/Tools/images/kwiyj/original_tab_on.gif"); }
    //else if (tab == 1) { $("img#tabStages").attr("src", "../App_Themes/Tools/images/kwiyj/stages_tab_on.gif"); }
    else { $("img#tabSparkling").attr("src", "../App_Themes/Tools/images/kwiyj/sparkling_tab_on.gif"); }
    $("#hfSelectedTab").val(tab);
}

//Finds the height of the viewable area of the browser
function getViewableAreaHeight() {
    var height;
    var clientBounds = $common.getClientBounds();
    var clientWidth = clientBounds.width;
    var clientHeight = clientBounds.height;
    if (Sys.Browser.agent == Sys.Browser.InternetExplorer && document.compatMode != "CSS1Compat") {
        height = document.body.scrollHeight;
    }
    else {
        height = Math.max(Math.max(document.documentElement.scrollHeight, document.body.scrollHeight), clientHeight);
    }
    return height;
}

//Finds the width of the viewable area of the browser
function getViewableAreaWidth() {
    var width;
    var clientBounds = $common.getClientBounds();
    var clientWidth = clientBounds.width;
    var clientHeight = clientBounds.height;
    if (Sys.Browser.agent == Sys.Browser.InternetExplorer && document.compatMode != "CSS1Compat") {
        width = document.body.scrollWidth;
    }
    else {
        width = Math.max(Math.max(document.documentElement.scrollWidth, document.body.scrollWidth), clientWidth);
    }
    return width;
}

//Centers a div within the viewable browser area
function centerPositionDiv(divId, iframeid) {
    var divElement = document.getElementById(divId);
    var divIFrame = document.getElementById(iframeid);
    if (divElement && divIFrame) {
        var divWidth = 620;
        var divHeight = 396;
        var divXOffset = divWidth / 2;
        var divYOffset = divHeight / 2;
        
        var iViewableWidth = getViewableAreaWidth();
        var iViewableHeight = getViewableAreaHeight();
        var iViewableX = iViewableWidth / 2;
        var iViewableY = iViewableHeight / 2;

        var divXPos = iViewableX - divXOffset;
        var divYPos = iViewableY - divYOffset;

        //now we have the coordinates for the top left position of the div
        divElement.style.top = "215px";
        divElement.style.left = divXPos + "px";
        showdiv(iframeid);
        divIFrame.style.top = "215px";
        divIFrame.style.left = divXPos + "px";

        showdiv(divId);
    }
}

