
// Firebug fix. TEMPORARY.
try {
    console.assert(1);
} catch(e) {
    if (typeof loadFirebugConsole == 'function') {
         loadFirebugConsole();
    }  else {
        console = {
            log: function() {},
            debug: function() {},
            info: function() {},
            warn: function() {},
            assert: function() {}
        }
    }
}


var feedPID         = "PSlvHKIjOdolYsUhSjbpf7ROOkJP5EYR"; // Prod
var tickerFeedPID   = "VX36Dt2kyMm4oh2JDAZKacgMHCgS3CRP"; // Prod
var pidEntities     = "oUFmCcyEZuCA7UqChCElKJFTJxFcgO9G"; // Prod
var feedsServiceURL = "http://ap.feeds.theplatform.com/ps/JSON/PortalService/2.2";
var urlTPFeedBase   = "http://ap.feeds.theplatform.com/ps/JSON/PortalService/2.2/getReleaseList";
var releaseFields   = "title,description,thumbnailURL,URL,contentID,PID,ID,contentOwner";

var solrServiceURL = "http://ap.search.theplatform.com"; //Prod
var solrFields = "rid";
var solrItems = 60;

var qFeedLocal    = "&query=CustomBoolean|isNational|false";
var qFeedNational = "&query=CustomBoolean|isNational|true";
var qFeedExclude  = "&query=ContentCustomText|ExcludeDMAs|,&query=ContentCustomText|ExcludeStationGroups|,&query=ContentCustomText|ExcludeTypes|,&query=ContentCustomText|ExcludeCityStates|,";
var trackingParam = "&param=MBR|true&param=Tracking|True&param=Player|MainPlayer&param=Affiliate|";
var trackingParamR = "&MBR=true&Tracking=True&Player=MainPlayer&Affiliate=";

var affiliateJInfo = {"CMAccountName":"None", "DMA":"None", "StationGroup":"None", "Premium":"None", "Type":"None", "City":"None", "State":"None", "thumbnailURL":"None", "HomepageURL":"#", "FullLocalNavigation":"false"};

var APLogoURL = "http://localimg.video.ap.org/ap_olvnetwork.jpg";
var APLogoURLHref = "http://www.ap.org";
var defaultLogoURL = "images/APLogo_950x50.jpg";
var defaultLogoHref = "http://www.ap.org";

var GAID = "UA-6058144-1";
var thumbnailEncodingProfileParam = "&thumbnailEncodingProfile=Thumb 92 x 69"
var showcaseThumbnailEncodingProfileParam = "&thumbnailEncodingProfile=Thumb 180 x 135";
var mostWatchedDateRange = 2;
var relatedDateRange = 5;

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	METHODS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	/**
	 * JSONP is a technique to work around cross-domain permissions in JavaScript.
	 * See http://www.west-wind.com/Weblog/posts/107136.aspx
	 */
	function jsonp ( pURL , pCallback , pName , pQuery )
	{
		if ( pURL.indexOf( "?" ) > -1 )
			pURL += "&json.wrf=" + pName + "&"
		else
			pURL += "?json.wrf=" + pName + "&"
			
		if (pQuery)
			pURL += encodeURIComponent( pQuery ) + "&";   
		
		// Prevent Caching
		pURL += new Date().getTime().toString();
		
		console.warn( "[ap.js] jsonp() >> pURL: " + pURL + " // pName: " + pName + " // pQuery: " + pQuery );
		
		// Write dynamic script tag
		var script = document.createElement( "script" );		
		script.setAttribute( "src" , pURL );
		script.setAttribute( "type" , "text/javascript" );				
		document.body.appendChild( script );
	}
		
	function jsonpFeeds ( pURL , pName , pQuery )
	{
			
        var req = new JSONRequest (pURL, pName);
        req.send();
	}

	/*
	** return a string of today's date with the offset (format yyyy-mm-ddT00:00:00Z).
	**
	*/
	function getOffsetDate(offset) 
	{
		var today = new Date();
		var day2 = new Date(today.getFullYear(), today.getMonth(), today.getDate() - offset);
		var offsetDateString = formatDateString(day2);			
		offsetDateString += "T00:00:00Z";
		
		return offsetDateString;
	}
		
	function formatDateString(d) 
	{
		var ret = "";
		if (d != undefined && d != "" && typeof d == 'object') {
			ret = d.getFullYear() + "-";
			var m = d.getMonth() + 1;
			if (m < 10)
				ret += "0";
				
			ret += m + "-";
			
			if (d.getDate() < 10) {
				ret += "0";
			}
			
			ret += d.getDate();
		}
		
		return ret;
	}