/* CO BRANDED [ header ] - [ pre ] */

/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : function
- write out iframe
*/
function writeIFrameHeader (iFrameID, baseURL, iFramePageSRC, iFrameHeight) {
	document.write("<iframe id=\"" + iFrameID + "\" name=\"" + iFrameID + "\" src=\"" + baseURL + iFramePageSRC + "\" width=\"810\" height=\"" + iFrameHeight + "\" style=\"margin: 0px; border: 0px;\" frameborder=\"0\" scrolling=\"no\"></iframe>");
}


/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : set global variables
- get param from query string
	msn = [ ?source=msn_channel_uniqueIdentifier ]
	comcast = [ ?source=__UNKNOWN__ ]
*/
var theSourceValue = getParam("source");

var iFramePageSRC = "";
var iFrameHeight = "";

// cookie expiration [ 1000(milliseconds) * 60(seconds) * 60(minutes) * 24(hours) * 1(days) ]
var thisDay = new Date();

/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : set MSN variables
- set vars for MSN
*/
if (theSourceValue) {
	var theSourceValueSplit = theSourceValue.split("_");
	var msnChannels = new Array(["kids","kidz.html",35],["cml","default.html",65],
		["encarta","default.html",65],["women","default.html",65],["family","default.html",65],
		["househome","default.html",65],["entertainment","default.html",65],
		["homepage","default.html",65],["outsmart","default.html",65]);
	for (msnsvs = 0; msnsvs < msnChannels.length; msnsvs++) {
		if (theSourceValueSplit[1] == msnChannels[msnsvs][0]) {
			iFramePageSRC = msnChannels[msnsvs][1];
			iFrameHeight = msnChannels[msnsvs][2];
			break;
		}
	}
	var baseMSNURL = "http://msn.discovery.com/includes/v9/";
	var msnIFrameId = "msntophat";
	
	// get the cookie + set msn cookie vars
	var theSourceCookie = getCookie("MSNHeader");
	if (theSourceCookie) { var theSourceCookieSplit = theSourceCookie.split("|"); }
	
	var msnCookieDie = new Date();
	msnCookieDie.setTime(thisDay.getTime() + 1000*60*60*24*0.25);
	
	var msnCookieValue = theSourceValueSplit[1] + "|" + theSourceValueSplit[2];
}


/* duplicate + tweak lines 24 - 51 w/ any additional 3rdp arty headers HERE */


/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : call function
- if ( cookie exists : test for header type and then dir. str. )
- else if ( look for referal flag : set cookie )
*/
if (theSourceCookie) {
	if (theSourceCookieSplit[0] == "msn") {
		writeIFrameHeader(msnIFrameId, baseMSNURL, iFramePageSRC, iFrameHeight);
	}
}
if (!theSourceCookie && theSourceValue) {
	if (theSourceValueSplit[0] == "msn") { 
		setCookie("MSNHeader", msnCookieValue, msnCookieDie, "/", ".discovery.com");
		writeIFrameHeader(msnIFrameId, baseMSNURL, iFramePageSRC, iFrameHeight);
	}
}

/* END CO BRANDED */
