/* 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.containerId == "210522"){
	document.write('\x3Clink rel="stylesheet" href="http://ftpcontent.worldnow.com/wtvg/custom/homepage.css">');
	$wn(document).ready(function(){
		hbRestyle();
		bfChange();
	});
}

if(wng_pageInfo.containerType == "S"){
	document.write('\x3Clink rel="stylesheet" href="http://ftpcontent.worldnow.com/wtvg/custom/story.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[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(){
	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(this).text("More " + $wn(this).parents(".wnDSContainer-standard").find(".wnDSHeader h3 span").text() + "...");
		});
		$wn("#WNCol3 .wnMoreLink").each(function(){
			$wn(this).appendTo($wn(this).parents(".wnDSContainer-standard").find(".wnDSItems-standard"));
			$wn(this).text("More...");
		});
	}
	/* OPTIMUS 3B */
	if ($wn(".more.enabled").length) {
		$wn(".more.enabled").each(function () {
			$wn(this).addClass("moreBlue");
			$wn(this).text("");
			$wn(this).text("More " + $wn(this).parents("h3").find(".text").filter(":visible").text() + "...");
			$wn(this).appendTo($wn(this).parents(".wnGroup"));
		});

		$wn("#WNCol3").find(".more.enabled").each(function () {
			$wn(this).text("More...");
		});
	}
}

//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>");
	});
}

// Col. 4 Branding Feature Change
function bfChange(){
	if($wn("#WNCol4 .wnDVNestedCategory .wnDSHeader").length){
		$wn("#WNCol4 .wnDVNestedCategory .wnDSHeader h3 span:contains('Weekend')").parents(".wnDSContainer-standard").addClass("bf");
		var $fHeadline = $wn("#WNCol4 .wnDVNestedCategory.bf");
		if($fHeadline.find(".wnDVSummary:eq(0)").find(".wnDate").length){
			fixDate($fHeadline.find(".wnDVSummary:eq(0)").find(".wnDate"));
		}
		$fHeadline.find(".wnDVSummary:eq(0) .wnDate").prependTo($fHeadline.find(".wnDVSummary:eq(0)"));
		$fHeadline.find(".wnDVSummary:gt(0)").addClass("noDisplay");
	}
}

//Weather Branding Feature
function launchWx(){
	var wxbf = "<div id='wxBrand'><div id='liveCam'><span>Live </span><a href='http://www.13abc.com/story/15249065/live-action-cams'>Action Cams</a></div><div id='date'></div><div id='wxLocation'></div><div id='now'><div>Right Now:</div><div id='wxTemp'><span></span></div></div><div id='wxFeel'></div><div id='wxForecast'></div><div id='wxCondition'><div id='wxIcon'></div><div id='wxText'></div></div></div>";
	
	var wxint;
	var stationNum = 0;
	var wxStations = new Array();
	wxStations[0] = new Array("http://data.wp.myweather.net/eWxII/?data=*43601", "Toledo, OH");				
				
	var wxIconPath = "http://ftpcontent.worldnow.com/wtvg/custom/wx_icons/"
	
	var wxLength = wxStations.length;
	var br_url = wxStations[stationNum][0];
	
	function wxInit(){
		br_weatherFeed(this);
	}
	
	function todayDate(){
		// Array of month Names
		var monthNames = new Array(
		"January","February","March","April","May","June","July",
		"August","September","October","November","December");
		
		var now = new Date();
		var today = monthNames[now.getMonth()] + " " + now.getDate() + ", " + now.getFullYear();
		return today;
	}
	
	function br_weatherFeed(xml){
		$wn("#wxBrand").hide();
	
		var fullFeed = xml.response.responseXML;
		var currentLoc = wxStations[stationNum][1];
		var currentTemp = $wn(fullFeed).find("currents location temp").text();
		if (!currentTemp){
			stationChange();
		} else {
			$wn("#WNDS70").hide();
			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");
			var skyCondition = $wn(fullFeed).find("currents location sky").text();
			var skyConditionIcon = $wn(fullFeed).find("currents location icon").text();
			
			$wn("#wxBrand #date").html(todayDate);
			$wn("#wxBrand #wxLocation").html(currentLoc);
			$wn("#wxBrand #wxTemp span").html(currentTemp + "&deg;");
			$wn("#wxBrand #wxFeel").html("Feels like " + feelsLike + "&deg;");
			$wn("#wxBrand #wxForecast").html("Hi " + forecastHi + " / Lo " + forecastLow);
			$wn("#wxBrand #wxIcon").css("background-image", "url('" + wxIconPath + skyConditionIcon + ".png')");
			$wn("#wxBrand #wxText").html(skyCondition);
			$wn("#wxBrand").show();
		}
	}
 
	function stationChange(){
		clearTimeout(wxint);
		wxint = setTimeout(stationChange, 5000);
		stationNum++;
		if(stationNum >= wxLength){ stationNum = 0; }
		br_url = wxStations[stationNum][0];
		WNHttpRequestManager.makeRequest(br_url, { onSuccess: wxInit, onError: wxError});
	}
	
	function wxError(){}
 
	WNHttpRequestManager.makeRequest(br_url, { onSuccess: wxInit, onError: wxError});
	wxint = setTimeout(stationChange, 5000);	

			$wn("#WNBranding").append(wxbf);		
}

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


