//______________________  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 googleID = "";
    var mainID = document.getElementById('flashtv');
	var subDivs = mainID.getElementsByTagName('div');
	for (var i=0;i<subDivs.length;i++){
		subDivs[i].style.display = "none";
	}
    
    //PLAY
    if (divId == "ad1") { googleID = "-1533885933844934320";    }
    //DRINK STAND
    if (divId == "ad2") { googleID = "3992203074202821303";     }
    //THE INTERVIEW
    if (divId == "ad3") { googleID = "180787573118659041";      }
    //FITTING IN 
    if (divId == "ad4") { googleID = "-4950340628382194642";    }
    //SCREAM
    if (divId == "ad5") { googleID = "-7568969704099046145";    }
    //MARKETING
    if (divId == "ad6") { googleID = "2740052306837048665";     }
    //NEW EMPLOYEE
    if (divId == "ad7") { googleID = "-6046942337653953099";    }
    //MODEL
    if (divId == "ad8") { googleID = "-720223518154906150";     }
    //FISH OUT OF WATER
    if (divId == "ad9") { googleID = "9120050501022513460";     }
    //MOTHERS DAY
    if (divId == "ad10") { googleID = "-7400836421860090477";   }
    //FATHER'S DAY
    if (divId == "ad11") { googleID = "-4909540279336093212";   }
    //HARVEST SURPRISE
    if (divId == "ad12") { googleID = "-5984944809611183577"; }
    //IMMUNITY
    if (divId == "ad13") { googleID = "3687676706988052353"; }
    //BRAIN DEVELOPMENT
    if (divId == "ad14") { googleID = "-8377394562962238685"; }
    
 
    so = new SWFObject("http://video.google.com/googleplayer.swf?docId="+googleID+"&hl=en", "tv", "400", "326", "6", ""); 
	so.addVariable("autoPlay", "true");  
	so.addParam('wmode', 'transparent'); 
    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#tabHarvest").attr("src", "../App_Themes/Tools/images/kwiyj/harvest_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#tabHarvest").attr("src", "../App_Themes/Tools/images/kwiyj/harvest_tab_on.gif"); }
    $("#hfSelectedTab").val(tab);
}
