/* 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 */

var wncc = "";
var wnaffName = "";

try {
	wncc = wng_pageInfo.contentClassification;
} catch(e) {
}

try {
	wnaffName = wng_pageInfo.affiliateName;
} catch(e) {
}

if(wng_pageInfo.containerType == "C"){
	if(wng_pageInfo.containerId == "102573"){
		document.write('\x3Clink rel="stylesheet" href="http://ftpcontent.worldnow.com/ntv/custom/homepage.css">');
	} else {
		document.write('\x3Clink rel="stylesheet" href="http://ftpcontent.worldnow.com/ntv/custom/override.css">');
	}
}

/* FIX WNDATE */
function fixDate($el){
	var tDate = $el;
	$wn(tDate).find("script").remove();
	$wn(tDate).find("noscript").remove();
	$wn(tDate).html($wn(tDate).text());
}

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

function launchDynamicNav(){
	var h = 26;
	var t = 41;
	$wn(".wnMainMenu .wnHorizontal .wnStatic .wnSublevel").css({"z-index": "1000"});

	$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(".wnLevel2").css({"height": h +"px", "top": subnavPos.top +"px", "left": subnavPos.left +"px", "width": ($wn(".wnMenuSpacer").width()-2) +"px", "overflow": "hidden"});
	}
	//$wn("ul.wnLevel1 li.wnFirstNode .wnLeft").css("padding-left","3px");
	$wn("ul.wnLevel1 li[rel='1']").bind("mouseenter", function(){
		clearTimeout(navTx);
		$wn(".wnLevel2:visible").hide();
		$wn(this).find(".wnLevel2").addClass("wnOn").css({"display": "block"});
	});
	$wn("ul.wnLevel1 li[rel='2']").bind("mouseenter", function(){
		clearTimeout(navTx);
	});
	
	$wn("#WNMenuCol1").bind("mouseleave", function(){
		clearTimeout(navTx);
		navTx = setTimeout(function(){
			wnNavReset();
		}, 500);
	});	
}

/* MORE LINK REPOSITION */
function moreLinkReposition(){
	$wn(".wnSummaryLink").text("More");
	if($wn(".wnMoreLink").length){
		$wn("#WNCol23 .wnMoreLink, #WNCol2 .wnMoreLink, , #WNCol4 .wnMoreLink").each(function(){
			$wn(this).appendTo($wn(this).parents(".wnDSContainer-standard").find(".wnDSItems-standard"));
		});
		$wn("#WNCol3 .wnMoreLink").each(function(){
			$wn(this).appendTo($wn(this).parents(".wnDSContainer-standard").find(".wnDSItems-standard"));
		});
	}
	/* OPTIMUS UPDATE */
		/* SHOULD BE CONTROLLED BY WORLDNOW WEB-PROD
	if($wn(".feature .more").length){
		$wn(".feature .more").each(function () {
			$wn(this).find(".text").text("More");
		});
	}
		*/
	if($wn(".header .more").length){
		$wn(".header .more.enabled").each(function () {
			$wn(this).addClass("wnMoreLink").appendTo($wn(this).parents(".contentGroup"));
		});
	}
}

//Col. 2 Headline Boxes for Homepage
function hbRestyle(){
	var backupImg = "http://wtvg.images.worldnow.com/images/535206_G.jpg";
	if($wn("#WNCol2 .wnDVHeadlineBox").length){
		$wn("#WNCol2 .wnDVHeadlineBox").each(function(){
			$wn(this).addClass("modded").find(".wnDVSummary:gt(0)").addClass("noDisplay");
			$wn(this).find(".wnDVSummary:last").addClass("last");
		});
	}
};

// Forms
function formRestyle(){
	$wn(".wnDVQuickForm, .wnDVQuickSignup").each(function(){
		$wn(this).find("h4:first").addClass("wnDSHeader").wrapInner("<h3><span style='display:inline;'></span></h3>");
	});
}

//Weather Branding Feature
function wxBrandingSetup(){
	if(!$wn("#severeWx").length){
		var wxBrandContent = "<div id='wxBrand'><a class='radar' href='http://www.nebraska.tv/category/222065/interactive-radar'><img src='http://ntv.images.worldnow.com/images/incoming/weather/Radar.gif' /></a><div class='wxSponsor'><div class='adTag'></div></div><div class='info'><div id='temp'></div><div id='feel'></div><div id='hilo'></div></div><div class='icon'></div><div class='selection'><a href='#'>7-Day Forecast ></a><div class='location'><select id='wxLocation'><option value='0' selected='selected'>Kearney</option><option value='1'>Grand Island</option><option value='2'>Hastings</option><option value='3'>Lexington</option><option value='4'>McCook</option><option value='5'>Broken Bow</option></select></div><div class='default'><input type='checkbox' id='wxCity' name='wxCity' /><label id='wxCityLabel' for='wxCity'></label></div></div></div>";
		
		//$wn("#WNBrandingImage").attr("src", "http://ftpcontent.worldnow.com/ntv/custom/hdr_branding.jpg");
		$wn("#WNBranding").prepend(wxBrandContent);
		var cc = wncc.toLowerCase();
	var callLetter = wnaffName.toLowerCase();
		var ord = Math.random()*10000000000000000;
		$wn("#wxBrand .adTag").html("<iframe width='114' height='37' scrolling='no' frameborder='0' marginheight='0' marginwidth='0' src='http://ad.doubleclick.net/adi/wn.loc." + callLetter + "/"+ cc +";sz=234x60;ord=" + ord + "?'></iframe>");
		
		var stationNum = 0;
		var wxStations = new Array();
		wxStations[0] = new Array("http://data.wp.myweather.net/eWxII/?data=*68847", "Kearney");
		wxStations[1] = new Array("http://data.wp.myweather.net/eWxII/?data=*68803", "Grand Island");
		wxStations[2] = new Array("http://data.wp.myweather.net/eWxII/?data=*68902", "Hastings");
		wxStations[3] = new Array("http://data.wp.myweather.net/eWxII/?data=*68850", "Lexington");
		wxStations[4] = new Array("http://data.wp.myweather.net/eWxII/?data=*69001", "McCook");
		wxStations[5] = new Array("http://data.wp.myweather.net/eWxII/?data=*68822", "Broken Bow");
		var wxIconPath = "http://ftpcontent.worldnow.com/ntv/custom/wx_icons/"
		
		var wxLength = wxStations.length;
		var br_url = wxStations[stationNum][0];
		var selNum = $wn("#wxBrand #wxLocation").find("option:selected").val();
		
		$wn("#WNDS70").hide();
		
		function wxInit(){
			br_weatherFeed(this);
		}
		
		function br_weatherFeed(xml){
			var fullFeed = xml.response.responseXML;
			var currentTemp = $wn(fullFeed).find("currents location temp").text();
			var currentIcon = $wn(fullFeed).find("currents location icon").text();
			var feelsLike = $wn(fullFeed).find("currents location feelslike").text();
			var forecastHi = $wn(fullFeed).find("forecasts location days:first day:first forecast:first").attr("high");
			var forecastLow = $wn(fullFeed).find("forecasts location days:first day:first forecast:first").attr("low");
			
			$wn("#wxBrand .info #temp").html(currentTemp + "&deg;");
			$wn("#wxBrand .icon").css("background-image", "url('"+ wxIconPath + currentIcon + ".png')");
			$wn("#wxBrand .info #feel").html("Feels like " + feelsLike + "&deg;");
			$wn("#wxBrand .info #hilo").html("Hi " + forecastHi + " / Lo " + forecastLow);
		}
	 
		function stationChange(num){
			br_url = wxStations[num][0];
			WNHttpRequestManager.makeRequest(br_url, { onSuccess: wxInit, onError: wxError});
		}
		
		function wxError(){}
		
		$wn("#wxBrand #wxLocation").change(function(){
			stationChange($wn(this).val());
		});
	
		$wn("#wxBrand #wxCity").click(function(){
			if($wn("#wxBrand #wxCity:checked").length){
				wxValue = $wn("#wxBrand #wxLocation").find("option:selected").val();
				setCookie("wxLoc", wxValue, 365);
				$wn("#wxBrand #wxCityLabel").text(wxStations[wxValue][1]);
			}
			else {
				setCookie("wxLoc", wxValue, 0);
				$wn("#wxBrand #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("#wxBrand #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("#wxBrand #wxCityLabel").text("Make Default City");
				WNHttpRequestManager.makeRequest(br_url, { onSuccess: wxInit, onError: wxError});	
			}
		}
		checkCookie();
	}
}

function swxLoad(){
	if($wn("#severeWx").length){
		$wn("#WNBrandingImage").attr("src", "http://ntv.images.worldnow.com/images/554994_G.jpg");
		$wn("#wxBrand").hide();
	}
}

function storyPage(){
	if (wng_pageInfo.containerType == "S"){
		//$wn("#WNStoryHeader h3:first").addClass("moved").insertBefore($("#WNContainerStory"));
		$("#WNContainerStory").before("<div class='wnDSHeader'><h3><span>Story</span></h3><div style='clear:both;'></div></div>");
		//$wn(".wnDSHeader").append("<div style='clear:both;'></div>");
	}
}

function breakingNews(){
	if($wn("#DisplaySizeId-30").length){
		$wn("#DisplaySizeId-30 .header").height($wn("#DisplaySizeId-30 .priority-1").height());
		$wn("#DisplaySizeId-30 .priority-1").height($wn("#DisplaySizeId-30 .header").height());
		if (($wn.browser.msie) && ($wn.browser.version == "7.0")){
			$wn("#DisplaySizeId-30 ul").append("<div class='wnClear'></div>");
		}
	}
}

function col4social(){
	var socialElement = "<div id='WNDS99' class='wnDS76 wnDSContainer-feature wnDS' style='margin-bottom:0;'><div id='socialTools'><div class='inner'><a class='icon' href='/story/6892134/contact-ntv' style='background-image:url(http://ftpcontent.worldnow.com/ntv/custom/social/mail.png)'></a><a class='icon' href='/link/261817/first-alert-text-messages-sign-up-here' style='background-image:url(http://ftpcontent.worldnow.com/ntv/custom/social/mobile.png)'></a><a class='icon' href='http://communitycorrespondent.com/ntv' style='background-image:url(http://ftpcontent.worldnow.com/ntv/custom/social/cc.png)'></a><a class='icon' href='/category/102576/news?clienttype=rss' style='background-image:url(http://ftpcontent.worldnow.com/ntv/custom/social/rss.png)'></a><a class='icon' href='http://www.facebook.com/ntvnews' style='background-image:url(http://ftpcontent.worldnow.com/ntv/custom/social/fb.png)'></a><a class='icon last' href='http://twitter.com/ntvnews' style='background-image:url(http://ftpcontent.worldnow.com/ntv/custom/social/twitter.png)'></a><div class='clear'></div></div></div></div>";
	$wn("#WNCol4").prepend(socialElement);
}

$wn(document).ready(function(){
	launchDynamicNav();
	wxBrandingSetup();
	col4social();
	swxLoad();
	breakingNews();
	storyPage();
	moreLinkReposition();
	formRestyle();
	hbRestyle();
});


