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

function builtWxBranding(){
	var wxbf = "<div id='wxBrand'><div id='icon'><img src='' /></div><div id='conditionText'></div><div id='tempText'></div><div id='hiText'></div><div id='loText'></div><div id='indexText'></div><a class='links' href='/category/174765/10-day-forecast '>10-Day Forecast</a></div>";
	
	$wn("#WNBranding").prepend(wxbf);
};

function builtBrandSocial(){
if (wng_pageInfo.contentClassification == "Station 50"){
	var socialTools = "<div id='brandSocial'><div class='row'><a class='icon' rel='fb' style='top:3px;left:105px;' href='http://www.facebook.com/KFRECW59/'><img src='http://ftpcontent.worldnow.com/kmph/custom/redesign11/social/fb.png' /></a><a class='icon' rel='mobile' style='top:3px;left:130px;' href='http://www.kmph.com/link/528629/kmphkfre-iphone-and-ipad-app'><img src='http://ftpcontent.worldnow.com/kmph/custom/redesign11/social/mobile.png' /></a></div></div>";
} else {
	var socialTools = "<div id='brandSocial'><div class='row'><a class='icon' rel='fb' style='top:3px;left:5px;' href='http://www.facebook.com/KMPHFOX26'><img src='http://ftpcontent.worldnow.com/kmph/custom/redesign11/social/fb.png' /></a><a class='icon' rel='twitter' style='top:3px;left:30px;' href='http://twitter.com/KMPHFOX26'><img src='http://ftpcontent.worldnow.com/kmph/custom/redesign11/social/twitter.png' /></a><a class='icon' rel='youtube' style='top:3px;left:55px;' href='http://www.youtube.com/kmphfox26'><img src='http://ftpcontent.worldnow.com/kmph/custom/redesign11/social/youtube.png' /></a><a class='icon' rel='rss' style='top:3px;left:80px;' href='/story/10740244/rss'><img src='http://ftpcontent.worldnow.com/kmph/custom/redesign11/social/rss.png' /></a><a class='icon' rel='mail' style='top:3px;left:105px;' href='http://www.kmph.com/global/link.asp?L=104054&function=manageprofile&mode=create&referrer=http%3A//www.kmph.com/'><img src='http://ftpcontent.worldnow.com/kmph/custom/redesign11/social/mail.png' /></a><a class='icon' rel='mobile' style='top:3px;left:130px;' href='http://www.kmph.com/link/528629/kmphkfre-iphone-and-ipad-app'><img src='http://ftpcontent.worldnow.com/kmph/custom/redesign11/social/mobile.png' /></a></div></div>";
}	
	
	$wn("#WNBranding").prepend(socialTools);
	$wn("#WNBranding #brandSocial").show();
};

function imgSwap(xx,url,type){
	var $tmp = $("#" + xx + " .row a");
	$tmp.each(function(){
		$(this).hover(function(){
			$(this).find("img").attr("src", url + $(this).attr("rel") + "_on." + type);
		},	function(){
			$(this).find("img").attr("src", url + $(this).attr("rel") + "." + type);
		})			
	});
}

$wn(document).ready(function(){
	builtWxBranding();
	builtBrandSocial();
	$wn("#WNCopyright img").attr("src","http://ftpcontent.worldnow.com/kmph/custom/redesign11/wn_powerby.png");
});

function wxBrandingSetup(){
	var wxint;
	var stationNum = 0;
	var wxStations = new Array();
	var wxStations = new Array();
	wxStations[0] = new Array("http://data.wp.myweather.net/eWxII/?data=*93727", "Fresno");									
				
	var wxIconPath = "http://ftpcontent.worldnow.com/kmph/custom/redesign11/wx_icons/"
	
	var wxLength = wxStations.length;
	var br_url = wxStations[stationNum][0];
	
	function wxInit(){
		br_weatherFeed(this);
	}
	
	function br_weatherFeed(xml){
		$wn("#wxBrandFeature .current, #wxBrandFeature .forecast").hide();
	
		var fullFeed = xml.response.responseXML;
		var currentLoc = wxStations[stationNum][1];
		var currentTemp = $wn(fullFeed).find("currents location temp").text();
		if (!currentTemp){
			stationChange();
		} else {
			//var currentHigh = $wn(fullFeed).find("currents location high").text();
			//var currentLow = $wn(fullFeed).find("currents location low").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");
			var currentIcon = $wn(fullFeed).find("currents location icon").text();
			var currentCondition = $wn(fullFeed).find("currents location sky").text();
			var currentFeel = $wn(fullFeed).find("currents location feelslike").text();
			
			$wn("#wxBrand #tempText").html(currentTemp + "&deg;");
			$wn("#wxBrand #conditionText").html(currentCondition);
			$wn("#wxBrand #icon").find("img").attr("src", wxIconPath + currentIcon + ".png").end().show();
			$wn("#wxBrand #hiText").html("High: <span>" + forecastHigh + "&deg;</span><div class='clear'></div>");
			$wn("#wxBrand #loText").html("Low: <span>" + forecastLow + "&deg;</span><div class='clear'></div>");
			$wn("#wxBrand #indexText").html("Index: <span>" + currentFeel + "&deg;</span><div class='clear'></div>");
			$wn("#wxBrand .links").show();
			$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(window).load(function(){
	wxBrandingSetup();
	imgSwap("brandSocial","http://ftpcontent.worldnow.com/kmph/custom/redesign11/social/","png");
});

if(wng_pageInfo.containerType === "S"){
	PLATFORM.EventMan.registerToEvent(function(){
		setTimeout(function(){var s="kmph",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>');
		
		try {
			   var tmp = __dsns_.GetCookie('dsnscomm'); 
			   if(tmp) {
					 GA_googleAddAttr("location", tmp);
					 GA_googleFillSlot("KMPH_Homepage_Hyperlocal_Ad_Slot_Cookie_300x250");
			   }
			   else {
					 GA_googleFillSlot("KMPH_Homepage_Hyperlocal_Ad_Slot_IP_300x250");
			   }
		} catch(e) {
			  GA_googleFillSlot("KMPH_Homepage_Hyperlocal_Ad_Slot_IP_300x250");
		}		
	},'WNCol4done');
}
	
