// Full Horizontals Gradient Activation
var nogradient = false;

// Rounded Box
function CSroundedBox(){
	if (window.PIE) {
		$wn(".wnBlock.displaySize .wnGroup, .wnBlock.displaySize .wnItem.header").each(function() {
			PIE.attach(this);
		});
		$wn(".wnDVHeadlineBox, .wnDVNestedCategory, .wnDVPromoBox, .wnDVQuickSignup, .wnDVQuickForm, .wnDVPoll, .wnDSHeader").each(function() {
			PIE.attach(this);
		});
		$wn("#WNTopStoryWrap, #WNCol2 .wnDS-20, .wnDS-10, #WNHorizontals, .wnDS-1, .wnDVWxFullForecast").each(function() {
			PIE.attach(this);
		});
		$wn(".wnDS28, #WNCol2 .wnDS22, .wnDS3, .wnDS14, .wnDS20, #WNStoryAssociatedLinks").each(function() {
			PIE.attach(this);
		});
	}
}

if($wn.browser.msie && parseInt($wn.browser.version) < 9){
	document.write('\x3Cscript type="text/javascript" src="http://ftpcontent.worldnow.com/revenue/js/PIE.js">\x3C/script>');
	$wn(document).ready(function(){
		CSroundedBox();
	});
}

//CUSTOM MEMBER CENTER
function CSnewMemberCenter(){
	var memberSectionTitle = "Subscription Center:";
	var memberLink = [];
	memberLink[0] = ["http://www.kait8.com/category/217781/the-loop-email-and-text-alerts-control-center?id=change","Manage Account"];
    memberLink[1] = ["http://www.kait8.com/category/217781/the-loop-email-and-text-alerts-control-center","Sign Up"];
	var memberDiv = "<ul id='newMemberCenter'><li>" + memberSectionTitle + "</li>";
	for (var aa=0;aa<memberLink.length;aa++){
		memberDiv += "<li class='item'><a href='" + memberLink[aa][0] + "'>" + memberLink[aa][1] + "</a></li>";
	}
	memberDiv += "</ul>";
	$wn("#WNContainerMemberSearch-headertop").append(memberDiv);
	$wn("#newMemberCenter li.item:last").addClass("last");
}

PLATFORM.EventMan.registerToEvent(function(){
	CSnewMemberCenter();
},'WNMenuCol1done');

// First Full Horizontal Gradient
function CSaddFHGradient(){
	if (nogradient == false){
		// OPTIMUS
		$wn("#DisplaySizeId-7 .wnItem.feature:first").addClass("gradient");
		if($wn("#DisplaySizeId-7 .wnItem.feature").length == 1){
			$wn("#DisplaySizeId-7 .wnItem.feature:last").addClass("solo");
			if (window.PIE) {
				$wn(".solo").each(function() {
					PIE.attach(this);
				});
			}
		} else {
			if (window.PIE) {
				$wn(".gradient").each(function() {
					PIE.attach(this);
				});
			}
		}
		$wn("#WNHorizontals #WNDS-7 .wnDVSummary:first").addClass("gradient");
		if($wn("#WNHorizontals #WNDS-7 .wnDVSummary").length == 1){
			$wn("#WNHorizontals #WNDS-7 .wnDVSummary:last").addClass("solo");
			if (window.PIE) {
				$wn(".solo").each(function() {
					PIE.attach(this);
				});
			}
		} else {
			if (window.PIE) {
				$wn(".gradient").each(function() {
					PIE.attach(this);
				});
			}
		}
	}
}

// Half Horizontals Force No Border OPTIMUS
function CSforceNoBorder(){
	$wn("#DisplaySizeId-4 .wnItem.feature.odd:first, #DisplaySizeId-4 .wnItem.feature.even:first").addClass("noBorder");
}

// Lifestyle
function CSlifestyle(){
	$wn("#WNAd44 table tr:first td:first").wrapInner("<div class='ribbon'><div class='ribbonText'></div></div>");
	$wn("#WNAd44 table tr:last").addClass("bg");
}

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

function CSlaunchDynamicNav(){
	var h = 26;
	var t = 34;
	$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);
	});	
}

$wn(document).ready(function(){
	CSaddFHGradient();
	CSforceNoBorder();
	CSlifestyle();
	CSlaunchDynamicNav();
});

//BREAKING NEWS BANNER SITEWIDE INCLUSION
document.write('\x3Cscript type="text/javascript" src="http://ftpcontent.worldnow.com/kait/html/RaycomBreakingNewsHeader.js">\x3C/script>');

//DATASPHERE LOADER CODE
setTimeout(function() { var s = "kait", a = document.getElementsByTagName("head")[0] || document.documentElement, c = document.createElement("script"), b = document.createElement("link"); c.type = "text/javascript"; c.async = true; c.src = "http://content.secondspace.com/" + s + "/widgets" + (window.__dsns_.GetCookie('dsnswidgetversion') || '') + ".js"; b.rel = "stylesheet"; b.type = "text/css"; b.href = "http://content.secondspace.com/" + s + "/widgets" + (window.__dsns_.GetCookie('dsnswidgetversion') || '') + ".css"; a.insertBefore(b, a.firstChild); a.insertBefore(c, a.firstChild); }, 200); if (typeof window.__dsns_ == "undefined") window.__dsns_ = {}; window.__dsns_.GetCookie = function(a) { a += "="; for (var c = document.cookie.split(";"), b = 0; b < c.length; b++) { for (var d = c[b]; d.charAt(0) == " "; ) d = d.substring(1, d.length); if (d.indexOf(a) == 0) return d.substring(a.length, d.length) } return null }; document.write('<style type="text/css">#dsnslocal {display:none}</style>');


// WEATHER BRANDING //
if((wng_pageInfo.containerId != "3491") && (wng_pageInfo.containerId != "209468")){
	document.write('\x3Cscript type="text/javascript" src="http://ftpcontent.worldnow.com/kait/custom/2011/icastlib1_kait.js">\x3C/script>');
	document.write('\x3Clink rel="stylesheet" href="http://www.intellicast.com/Styles/Widgets/Stylesheet_20100615.css">');
	document.write('\x3Cscript type="text/javascript" src="http://content.worldnow.com/global/interface/httprequest/httprequest.js">\x3C/script>');
	
	$wn(document).ready(function(){
		CSlaunchWx();
	});
}

var mainTimer;
function CSlaunchWx(){
	if($wn("#wxBrandFeatureOuter").length){
		$wn("#wxBrandFeatureOuter").remove();
	}	
	var wxbf = "<div id='wxBrandFeatureOuter' style='z-index: 10'><div id='wxBrandFeature'><div class='current'><div id='loc' class='text'></div><div id='temp' class='text'></div><div id='feel' class='text'>Feels Like: <span></span></div></div><a href='/category/201158/todays-region-8-stormteam-forecast'><div id='firstTime' class='forecast'><div id='time' class='text'></div><div id='image' class='text'><img src='' /></div><div id='temp' class='text'></div></div></a><a href='/category/201158/todays-region-8-stormteam-forecast'><div id='secondTime' class='forecast'><div id='time' class='text'></div><div id='image' class='text'><img src='' /></div><div id='temp' class='text'></div></div></a><div class='radar'><a href='/category/5795/wood-ford-storm-tracker'><img src='http://kait.images.worldnow.com/images/incoming/weather/_radar133radar.jpg' /><div>Radar</div></a></div><div class='buttons'><a class='button' href='/weather'><div class='text'>7-Day Forecast</div></a><a class='button' href='/category/90388/region-8-stormteam-interactive-radar'><div class='text'>Interactive Radar</div></a><div class='zipcode'><div class='text'><input type='text' autocomplete='off' value='Zip code' name='query' id='BFicast_searchBox' class='ac_input'><input type='button' id='BFicast_searchButton' value='Lookup' width='20' height='12' style='cursor: pointer;' onClick='javascript:icast_Search();'></div></div></div></div></div>";
	
	function addTime(t){
		var d = new Date();
		var curr_hour = d.getHours();
		var new_hour = "";
		var a_p = "";	
		curr_hour = curr_hour + t;
		
		if (curr_hour >= 24) {
			curr_hour = curr_hour - 24;
			if (curr_hour == 0) {
				curr_hour = 12;
			}
			a_p = "a";	   
		} else if ((curr_hour > 12) && (curr_hour < 24)) {
			curr_hour = curr_hour - 12;	
			a_p = "p";
		} else if (curr_hour == 12) {	
			a_p = "p";	   			   
		} else if (curr_hour < 12) {
			a_p = "a";
		} else if (curr_hour == 0) {
			curr_hour = 12;
			a_p = "a";
		}
						
		new_hour = curr_hour + a_p;
		return new_hour;		
	}
		
	var wxint;
	var stationNum = 0;
	var wxStations = [];
	wxStations[0] = new Array("http://services.intellicast.com/200904-01/175606286/Weather/Report/USAR0304", "Jonesboro");
	wxStations[1] = new Array("http://services.intellicast.com/200904-01/175606286/Weather/Report/USTN0325", "Memphis");
	wxStations[2] = new Array("http://services.intellicast.com/200904-01/175606286/Weather/Report/USAR0533", "Stuttgart");
	wxStations[3] = new Array("http://services.intellicast.com/200904-01/175606286/Weather/Report/USAR0336", "Little Rock");		
	wxStations[4] = new Array("http://services.intellicast.com/200904-01/175606286/Weather/Report/USAR0197", "Fort Smith");	
	wxStations[5] = new Array("http://services.intellicast.com/200904-01/175606286/Weather/Report/USMO0099", "Branson");
	wxStations[6] = new Array("http://services.intellicast.com/200904-01/175606286/Weather/Report/USAR0033", "Batesville");
	wxStations[7] = new Array("http://services.intellicast.com/200904-01/175606286/Weather/Report/USMO0932", "West Plains");
	wxStations[8] = new Array("http://services.intellicast.com/200904-01/175606286/Weather/Report/USMO0316", "Fort Leonard Wood");		
	wxStations[9] = new Array("http://services.intellicast.com/200904-01/175606286/Weather/Report/USMO0787", "St. Louis");	
	wxStations[10] = new Array("http://services.intellicast.com/200904-01/175606286/Weather/Report/USKY1215", "Paducah");
	wxStations[11] = new Array("http://services.intellicast.com/200904-01/175606286/Weather/Report/USTN0154", "Dyersburg");						
	var wxLength = wxStations.length;			
	var wxIconPath = "http://ftpcontent.worldnow.com/raycom/wsi_icons/wx_"
	var br_url = wxStations[stationNum][0];
	var wxSavedData = [];	
	
	for(dd=0;dd<wxLength;dd++){
		wxSavedData[dd] = [];
	}
	
	function wxInit(){
		br_weatherFeed(this);
	}
		
	function br_weatherFeed(xml){
		$wn("#wxBrandFeature .current, #wxBrandFeature .forecast").hide();
		var fullFeed = xml.response.responseXML;
		var testFeed = $wn(fullFeed).find("Cities City CurrentObservation").attr("TempF");
		if (isNaN(parseInt(testFeed))){
			stationChange();
		} else {
			wxSavedData[stationNum][0] = $wn(fullFeed).find("Cities City CurrentObservation").attr("TempF");
			wxSavedData[stationNum][1] = wxStations[stationNum][1];
			wxSavedData[stationNum][2] = $wn(fullFeed).find("Cities City CurrentObservation").attr("FeelsLikeF");
			wxSavedData[stationNum][3] = addTime(3);
			wxSavedData[stationNum][4] = addTime(6);
			wxSavedData[stationNum][5] = $wn(fullFeed).find("Cities City HourlyForecast Hour:eq(2)").attr("TempF");
			wxSavedData[stationNum][6] = $wn(fullFeed).find("Cities City HourlyForecast Hour:eq(2)").attr("IconCode");
			wxSavedData[stationNum][7] = $wn(fullFeed).find("Cities City HourlyForecast Hour:eq(5)").attr("TempF");
			wxSavedData[stationNum][8] = $wn(fullFeed).find("Cities City HourlyForecast Hour:eq(5)").attr("IconCode");
			
			$wn("#wxBrandFeature .current #loc").html(wxSavedData[stationNum][1]);
			$wn("#wxBrandFeature .current #temp").html(wxSavedData[stationNum][0] + "&deg;");
			$wn("#wxBrandFeature .current #feel span").html(wxSavedData[stationNum][2] + "&deg;");
			$wn("#wxBrandFeature #firstTime div[id='time']").html(parseInt(wxSavedData[stationNum][3]) + ":00 " + wxSavedData[stationNum][3].substr(wxSavedData[stationNum][3].length-1,1) + "m");
			$wn("#wxBrandFeature #firstTime div[id='temp']").html(parseInt(wxSavedData[stationNum][5]) + "&deg;");
			$wn("#wxBrandFeature #firstTime div[id='image'] img").attr("src", wxIconPath + wxSavedData[stationNum][6] + ".png");
			$wn("#wxBrandFeature #secondTime div[id='time']").html(parseInt(wxSavedData[stationNum][4]) + ":00 " + wxSavedData[stationNum][4].substr(wxSavedData[stationNum][4].length-1,1) + "m");
			$wn("#wxBrandFeature #secondTime div[id='temp']").html(parseInt(wxSavedData[stationNum][7]) + "&deg;");
			$wn("#wxBrandFeature #secondTime div[id='image'] img").attr("src", wxIconPath + wxSavedData[stationNum][8] + ".png");
			$wn("#wxBrandFeature .current, #wxBrandFeature .forecast").show();
		}
	}

	function inputSavedData(num){
		$wn("#wxBrandFeature .current, #wxBrandFeature .forecast").hide();
		$wn("#wxBrandFeature .current #loc").html(wxSavedData[num][1]);
		$wn("#wxBrandFeature .current #temp").html(wxSavedData[num][0] + "&deg;");
		$wn("#wxBrandFeature .current #feel span").html(wxSavedData[num][2] + "&deg;");
		$wn("#wxBrandFeature #firstTime div[id='time']").html(parseInt(wxSavedData[num][3]) + ":00 " + wxSavedData[num][3].substr(wxSavedData[num][3].length-1,1) + "m");
		$wn("#wxBrandFeature #firstTime div[id='temp']").html(parseInt(wxSavedData[num][5]) + "&deg;");
		$wn("#wxBrandFeature #firstTime div[id='image'] img").attr("src", wxIconPath + wxSavedData[num][6] + ".png");
		$wn("#wxBrandFeature #secondTime div[id='time']").html(parseInt(wxSavedData[num][4]) + ":00 " + wxSavedData[num][4].substr(wxSavedData[num][4].length-1,1) + "m");
		$wn("#wxBrandFeature #secondTime div[id='temp']").html(parseInt(wxSavedData[num][7]) + "&deg;");
		$wn("#wxBrandFeature #secondTime div[id='image'] img").attr("src", wxIconPath + wxSavedData[num][8] + ".png");
		$wn("#wxBrandFeature .current, #wxBrandFeature .forecast").show();
	}
	 
	function stationChange(){
		clearTimeout(wxint);
		wxint = setTimeout(stationChange, 5000);
		stationNum++;
		if(stationNum >= wxLength){ stationNum = 0; }
		br_url = wxStations[stationNum][0];
		if(!wxSavedData[stationNum].length){
			WNHttpRequestManager.makeRequest(br_url, { onSuccess: wxInit, onError: wxError});
		} else {
			inputSavedData(stationNum);
		}
	}
		
	function wxError(){}
	 
	WNHttpRequestManager.makeRequest(br_url, { onSuccess: wxInit, onError: wxError});
	if(wxLength>1){
		wxint = setTimeout(stationChange, 5000);
	}	

	$wn("#WNBranding").prepend(wxbf);
	
	$("#BFicast_searchBox").bind("blur", function(){
		BFicast_Swipe('off');
	});
	$("#BFicast_searchBox").bind("focus", function(){
		BFicast_Swipe('on');
	});
}
