// Generic RSS block
function WNGetRSS(blockTitle, ribbonText, numItems, rssURL, containerID, imgPath){
	function rssInitContent(){
		rssParseXML(this);
	}
		
	function rssErrorFunction(e){}
	
	function makeRSSRequest(){
			WNHttpRequestManager.makeRequest(rssURL, { onSuccess: rssInitContent, onError: rssErrorFunction});
	};
	
	makeRSSRequest();

	function rssParseXML(xml){
		var fullFeed = xml.response.responseXML;
		var totalItems = ($wn(fullFeed).find("item").length);
		if(totalItems){
			if(ribbonText == true){
				var buildCont = "<div id='rss" + containerID + "' class='wnBlock displaySize rss'><ul class='wnGroup' style='clear:both;'><li class='wnItem header'><h3><span class='text' style='display:inline;'>" + blockTitle + "</span></h3></li>";
			} else if(ribbonText == false && imgPath){
				var buildCont = "<div id='rss" + containerID + "' class='wnBlock displaySize rss'><ul class='wnGroup' style='clear:both;'><li class='wnItem header'><h3 style='width:100%;height:36px;background-image:url(http://KPHO.images.worldnow.com/images/606379_G.gif);background-repeat:no-repeat;background-position:left bottom;'><span class='text' style='display:inline;'>&nbsp;</span></h3></li>";
			} else if(ribbonText == false){
				var buildCont = "<div id='rss" + containerID + "' class='wnBlock displaySize rss'><ul class='wnGroup' style='clear:both;'>";
			}
			if(totalItems > numItems){
				totalItems = numItems;
			}
			var $items = $wn(fullFeed).find("item:lt(" + totalItems + ")");
			$items.each(function(xx){
				var headline = $wn(this).find("title").text();
				var pageURL = $wn(this).find("link").text();

				buildCont += "<li class='wnItem feature priority-" + (xx+1) + "'><h4 class='wnContent headline'><a href='" + pageURL + "' target='_blank'><span class='text'>" + headline + "</span></a></h4></li>";		
			});
			
			buildCont += "</ul></div>";
			
			$wn("#wn" + containerID).html(buildCont);
		}
	}
}

/* Site Configurations */
var branding = {
	alertsLink : "/category/208615/weather-alerts",
	closingsLink : "/category/210159/traffic",
	closingsText: "Traffic Alerts",
	logoLink : "/category/212414/cbs-5-action-button"
}

/* COMMON WEATHER */
var wxCache = {};
function fetchWxFeed(i, callback) {
  if (wxCache[i] !== undefined) {
    callback(wxCache[i], i);
    return;
  }

  var wxBase = 'http://data.wp.myweather.net/eWxII/?data=*{STATION}';
  var url = wxBase.replace('{STATION}', wxLocations[i].zipCode);
  WNHttpRequestManager.makeRequest(url, {
    onSuccess: function() {
      wxCache[i] = this.response.responseXML;
      callback(this.response.responseXML, i);
    },
    onError: function() {}
  });
}

var wxLocations = [
  {name: 'Phoenix',     zipCode: '85001'},
  {name: 'Scottsdale',  zipCode: '85250'},
  {name: 'Glendale',    zipCode: '85308'},
  {name: 'Deer Valley', zipCode: '85068'},
  {name: 'Goodyear',    zipCode: '85395'}
];

// Old station list, for backwards compatibility
var wxStations = new Array();
wxStations[0] = new Array("http://data.wp.myweather.net/eWxII/?data=*85001", "Phoenix");
wxStations[1] = new Array("http://data.wp.myweather.net/eWxII/?data=*85250", "Scottsdale");
wxStations[2] = new Array("http://data.wp.myweather.net/eWxII/?data=*85308", "Glendale");
wxStations[3] = new Array("http://data.wp.myweather.net/eWxII/?data=*85068", "Deer Valley");
wxStations[4] = new Array("http://data.wp.myweather.net/eWxII/?data=*85395", "Goodyear");

/* Vibrant Ad Tags */
if(wng_pageInfo.containerType === 'S'){
	var vibSrc = "";
	if(wng_pageInfo.contentClassification === 'Auto'){
		vibSrc = "http://meredithtv.us.intellitxt.com/intellitxt/front.asp?ipid=6977";
	}
	else if((wng_pageInfo.contentClassification === 'Community') || (wng_pageInfo.contentClassification === 'Community - Calendar') || (wng_pageInfo.contentClassification === 'Community - Events') || (wng_pageInfo.contentClassification === 'Education')){
		vibSrc = "http://meredithtv.us.intellitxt.com/intellitxt/front.asp?ipid=6988";
	}
	else if((wng_pageInfo.contentClassification === 'Entertainment') || (wng_pageInfo.contentClassification === 'Entertainment - Interview') || (wng_pageInfo.contentClassification === 'Entertainment - Music')){
		vibSrc = "http://meredithtv.us.intellitxt.com/intellitxt/front.asp?ipid=6978";
	}
	else if((wng_pageInfo.contentClassification === 'Food Recipe')){
		vibSrc = "http://meredithtv.us.intellitxt.com/intellitxt/front.asp?ipid=6979";
	}
	else if((wng_pageInfo.contentClassification === 'Health')){
		vibSrc = "http://meredithtv.us.intellitxt.com/intellitxt/front.asp?ipid=6981";
	}
	else if((wng_pageInfo.contentClassification === 'Sales - Home and Garden') || (wng_pageInfo.contentClassification === 'Sales - Home Garden-New Home') || (wng_pageInfo.contentClassification === 'Sales - Home Garden-Plumbing') || (wng_pageInfo.contentClassification === 'Sales - Home Garden-Real Estate') || (wng_pageInfo.contentClassification === 'Sales - Home Garden-Remodeling') || (wng_pageInfo.contentClassification === 'Sales - Home Garden-Roofing') || (wng_pageInfo.contentClassification === 'Sales - Home Garden-Security') || (wng_pageInfo.contentClassification === 'Sales - Home Garden-Windows')){
		vibSrc = "http://meredithtv.us.intellitxt.com/intellitxt/front.asp?ipid=6982";
	}
	else if((wng_pageInfo.contentClassification === 'Sales - Finance')){
		vibSrc = "http://meredithtv.us.intellitxt.com/intellitxt/front.asp?ipid=6980";
	}
	else if((wng_pageInfo.contentClassification.indexOf('News') != -1) || (wng_pageInfo.contentClassification.indexOf('Political') != -1) || (wng_pageInfo.contentClassification.indexOf('Station') != -1) || (wng_pageInfo.contentClassification.indexOf('Weather') != -1)){
		vibSrc = "http://meredithtv.us.intellitxt.com/intellitxt/front.asp?ipid=6976";
	}
	else if((wng_pageInfo.contentClassification.indexOf('Sport') != -1)){
		vibSrc = "http://meredithtv.us.intellitxt.com/intellitxt/front.asp?ipid=6983";
	}
	else if((wng_pageInfo.contentClassification === 'Technology')){
		vibSrc = "http://meredithtv.us.intellitxt.com/intellitxt/front.asp?ipid=6985";
	}
	else if((wng_pageInfo.contentClassification.indexOf('Traffic') != -1) || (wng_pageInfo.contentClassification.indexOf('Travel') != -1)){
		vibSrc = "http://meredithtv.us.intellitxt.com/intellitxt/front.asp?ipid=6987";
	}
}

/* Meredith Shared Code */
document.write('<scr' + 'ipt type="text/javascript" src="http://ftpcontent.worldnow.com/meredith/custom/custom-master.js"><\/scr' + 'ipt>');

