/* GLOBAL SCRIPT FILE INCLUDES */
document.write('\x3Cscript type="text/javascript" src="http://content.worldnow.com/global/interface/httprequest/httprequest.js">\x3C/script>');
/* END GLOBAL SCRIPT FILE INCLUDES */

/* BEGIN DYNAMIC STATIC NAV */

var navTx;
function wnNavReset(){
	clearTimeout(navTx);
	$wn(".wnLevel2:visible").hide();
	$wn(".cur").show();
}

function launchDynamicNav(){
	var h = 26;
	var t = 37;
	$wn(".wnMainMenu .wnHorizontal .wnStatic .wnSublevel").css({"z-index": "1000"});
	$wn(".wnMainMenu .wnHorizontal .wnStatic .wnSublevel li").css({ "background-position" : "left 8px" });

	$wn(".wnStatic .wnLevel1 li:first").attr("rel", "1");
	$wn(".wnStatic .wnLevel1 li:first").siblings("li").each(function(){
		$wn(this).attr("rel", "1");
		if(!$wn(this).find("ul").length){
			$wn(this).append("<ul class='wnLevel2 wnSublevel' style='height: "+ h +"px; top: "+ t +"px; display: none;'><li class='wnFirstNode wnOn'><span><a href=''>&nbsp;</a></span></li></ul>");
		}
	});
	$wn(".wnStatic .wnLevel2 li:first").attr("rel", "2");
	$wn(".wnStatic .wnLevel2 li:first").siblings("li").each(function(){
		$wn(this).attr("rel", "2");
	});
	
	var subnavPos = $(".wnMenuSpacer").offset();
	if($wn(".wnLevel2:visible").attr("class") != null){
		//IF A SUB NAV IS PRESENT FOR THE CURRENT CATEGORY
		$wn(".wnLevel2:visible").addClass("cur");
		$wn(".wnLevel2").css({"height": h + "px", "top": t+"px"});
	}else{
		//IF A SUB NAV IS NOT PRESENT FOR THE CURRENT CATEGORY
		$wn("#WNMenuCol1 .wnMenuSpacer").height(h);
		//$wn(".wnLevel1 li").height($(".wnLevel1 li").height() + h);
		//$wn(".wnLevel1 li ul li").height(h);
		//$wn(".wnLevel1 .wnFirstNode").append("<ul class='wnLevel2 wnSublevel' rel='cur'><li class='wnFirstNode'><span><a href=''>&nbsp;</a></span></li></ul>");
		$wn(".wnLevel2").css({"height": h+"px", "top": (subnavPos.top+2) +"px", "left": (subnavPos.left) +"px", "width": ($wn(".wnMenuSpacer").width()-2) +"px", "overflow": "hidden"});
	}
	$wn("ul.wnLevel1 li[rel='1']").bind("mouseenter", function(){
		clearTimeout(navTx);
		$wn(".wnLevel2:visible").hide();
		$wn(this).find(".wnLevel2").addClass("wnOn").css({"display": "block"});
	});
/*
	if (($wn.browser.msie) && ($wn.browser.version == "7.0")){
		$wn("#WNMenuCol1 .wnMenuSpacer").height(t);
	}
*/	
	$wn("ul.wnLevel1 li[rel='2']").bind("mouseenter", function(){
		clearTimeout(navTx);
	});
	
	$wn("#WNMenuCol1").bind("mouseleave", function(){
		clearTimeout(navTx);
		navTx = setTimeout(function(){
			wnNavReset();
		}, 500);
	});	
}

$wn(document).ready(function(){
	launchDynamicNav();
});

/* END DYNAMIC STATIC NAV */

/* BEGIN SET PAGE STYLE */
if (wng_pageInfo.contentClassification == "General020"){
	document.write('\x3Clink rel="stylesheet" href="http://ftpcontent.worldnow.com/kljb/custom/kgcw.css">');
	$wn(document).ready(function(){
		$wn("#WNBranding area").attr("href", "http://kgcwtv.com/");
		$wn("#WNBrandingImage").attr("src","http://kljb.images.worldnow.com/images/520057_G.jpg");
	});
} else {
	document.write('\x3Clink rel="stylesheet" href="http://ftpcontent.worldnow.com/kljb/custom/default.css">');
}

/* END SET PAGE STYLE */

/* WEATHER BRANDING FEATURE */
var wxbf = "<div id='wxBrandFeature'><div class='current'><div id='temp' class='text'></div><div id='feel' class='text'>Feels like <span></span>F</div><div id='image' class='text'></div><div id='condition' class='text'></div></div><div class='forecast'><div id='temperature' class='text'>Hi <span id='hi'></span> / Lo <span id='low'></span></div><div id='link' class='text'><a href='/weather'>7 Day Forecast ></a></div></div><div class='location'><select id='wxLocation'><option value='0' selected='selected'>Davenport, IA</option><option value='1'>Moline, IL</option><option value='2'>Galesburg, IL</option><option value='3'>Muscatine, IA</option><option value='5'>Burlington, IA</option><option value='6'>Sterling/Rock Falls, IL</option></select></div><div class='default'><input type='checkbox' id='wxCity' name='wxCity' /><label id='wxCityLabel' for='wxCity'></label></div><div id='sponsoredAd'><span class='text'>Sponsored by:</span><span id='adCall'></span></div></div>";

function wxBrandingSetup(){
	$wn("#WNBranding").append(wxbf);
	var stationNum = 0;
	var wxStations = new Array();
	wxStations[0] = new Array("http://data.wp.myweather.net/eWxII/?data=*52801", "Davenport, IA");
	wxStations[1] = new Array("http://data.wp.myweather.net/eWxII/?data=*61265", "Moline, IL");
	wxStations[2] = new Array("http://data.wp.myweather.net/eWxII/?data=*61401", "Galesburg, IL");
	wxStations[3] = new Array("http://data.wp.myweather.net/eWxII/?data=*52761", "Muscatine, IA");
	wxStations[4] = new Array("http://data.wp.myweather.net/eWxII/?data=*52601", "Burlington, IA");
	wxStations[5] = new Array("http://data.wp.myweather.net/eWxII/?data=*61081", "Sterling/Rock Falls, IL");
	var wxIconPath = "http://ftpcontent.worldnow.com/kljb/custom/wx_icons/"
	
	var wxLength = wxStations.length;
	var br_url = wxStations[stationNum][0];
	var selNum = $wn("#wxBranding #wxLocation").find("option:selected").val();
	
	function wxInit(){
		br_weatherFeed(this);
	}
	
	function br_weatherFeed(xml){
		var fullFeed = xml.response.responseXML;
 		var currentTemp = $wn(fullFeed).find("currents location temp").text();
		if (!currentTemp){
			$wn("#wxBrandFeature").hide();
		} else {
			var currentFeel = $wn(fullFeed).find("currents location feelslike").text();
			var currentIcon = $wn(fullFeed).find("currents location icon").text();
			var currentCondition = $wn(fullFeed).find("currents location sky").text();
			var forecastHigh = $wn(fullFeed).find("forecasts location day[index='0'] forecast:first").attr("high");
			var forecastLow = $wn(fullFeed).find("forecasts location day[index='0'] forecast:first").attr("low");
			$wn("#wxBrandFeature .current #temp").html(currentTemp + "&deg;");
			$wn("#wxBrandFeature .current #feel span").html(currentFeel);
			$wn("#wxBrandFeature .current #image").css("background", "url('"+ wxIconPath + currentIcon + ".png') top center no-repeat");
			$wn("#wxBrandFeature .current #condition").html(currentCondition);
			$wn("#wxBrandFeature .forecast #temperature #hi").html(forecastHigh);
			$wn("#wxBrandFeature .forecast #temperature #low").html(forecastLow);
			$wn("#wxBrandFeature").show();
		}
	}
 
	function stationChange(num){
		br_url = wxStations[num][0];
		WNHttpRequestManager.makeRequest(br_url, { onSuccess: wxInit, onError: wxError});
	}
	
	function wxError(){}
	
	$wn("#wxBrandFeature #wxLocation").change(function(){
		stationChange($wn(this).val());
	});

	$wn("#wxBrandFeature #wxCity").click(function(){
		if($wn("#wxBrandFeature #wxCity:checked").length){
			wxValue = $wn("#wxBrandFeature #wxLocation").find("option:selected").val();
			setCookie("wxLoc", wxValue, 365);
			$wn("#wxBrandFeature #wxCityLabel").text(wxStations[wxValue][1]);
		}
		else {
			setCookie("wxLoc", wxValue, 0);
			$wn("#wxBrandFeature #wxCityLabel").text("Make Default City");
		}
	});	
	
	function setCookie(c_name,value,expiredays) {
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +escape(value)+
		((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
	}
	
	function getCookie(c_name)	{
		if (document.cookie.length>0) {
			c_start=document.cookie.indexOf(c_name + "=");
			if (c_start!=-1) {
				c_start=c_start + c_name.length+1;
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
			}
		}
		return "";
	}		
	
	function checkCookie(){
		wxValue = getCookie("wxLoc");
		if (wxValue!=null && wxValue!=""){
			document.getElementById("wxCity").checked = true;
			$wn("#wxBrandFeature #wxCityLabel").text(wxStations[wxValue][1]);
			$wn("#wxLocation option").removeAttr("selected");
			$wn("#wxLocation option:eq(" + wxValue + ")").attr("selected", "selected");
			WNHttpRequestManager.makeRequest(wxStations[wxValue][0], { onSuccess: wxInit, onError: wxError});	
		} else {
			$wn("#wxBrandFeature #wxCityLabel").text("Make Default City");
			WNHttpRequestManager.makeRequest(br_url, { onSuccess: wxInit, onError: wxError});	
		}
	}
	checkCookie();			
}

/* Weather Branding Sponsored Ad */
function addSponsoredAd(){
	var ord = Math.random()*10000000000000000;
	var wncc = '';
	var ad_wncc = '';
	try {
		wncc = wng_pageInfo.contentClassification;
		ad_wncc = wncc.toLowerCase();
		while (ad_wncc.indexOf(" ") != -1){
			ad_wncc = ad_wncc.replace(" ", "");
		}
	} catch(e) {}
	
	var affNameCaps = '';
	var affName = ''
	try {
		affNameCaps = wng_pageInfo.affiliateName;
		affName = affNameCaps.toLowerCase();
	} catch(e) {}	
	
	$wn("#sponsoredAd #adCall").append("<iframe id='headerAd' width='118' height='19' marginwidth='0' marginheight='0' frameborder='0' scrolling='no'></iframe>");
	var adcall = "http://ad.doubleclick.net/adi/wn.loc."+affName+"/"+ ad_wncc +";sz=120x60;ord=" + ord + "?";
	$wn("#sponsoredAd #adCall #headerAd").attr("src", adcall);
}
$wn(window).load(function(){
	wxBrandingSetup();
	addSponsoredAd();
});
/* END WEATHER BRANDING FEATURE */

$wn(document).ready(function(){
	$wn("a.wnMoreLink").text("More");
});
