
(function(){
    if ( typeof GEL == 'undefined') {
	setTimeout(arguments.callee, 100); /* Will call back into this function every 100 ms until GEL is available */
	return false; 
    }
   var 
	   _G= GEL,  
	   _C= _G.config, 
	   _I= _G.thepage.initializer,
	   _W= window, 
	   _U= _W.location.host,
	   _C= _G.config,
	   _LURL= '',
           _SD= '',
	   _P= _G.namespace("config.bus.providers"),
           _QSP = GEL.env.url.qsv
   ;
   // Test to see if _W['gci-cobrand'] is defined...if so, we can get the co-brand id from there...
   
   if(typeof _W['gci-cobrand'] != 'undefined') {
     _SD = _W['gci-cobrand']
   } else {
     _SD = (function() {
          if(_QSP.template)
               return _QSP.template;
          else
               //lets look at the subdomain for topics
               _D = _G.env.url.hostname.split('.')
               if(_D[0] == 'topics') {
                    return _D[1]
               } else {
                    return 'global'
               }
          })();
   }
       
   if(_SD == 'cobrand_test') {
     _SD = 'indystar'
   } else if (_SD == 'news10.net') {
     _SD = 'news10';
    } else if (_SD == 'chron' || _SD == 'mysanantonio' || _SD == 'sfgate' || _SD == 'timesunion') {
        _SD = 'global';
    }
    
     if(_SD == 'global') {
          _LURL= 'http://www.gannettonline.com/scripts/gel/global/localvars.js';
     } else {
          if (_SD == 'wusa9') {
               _SD = 'wusatv9';
          }
          _LURL= ['http://', _SD , ".gannettdigital.com/localvars.js"].join("");
     }
    
    GEL.log("co-brand id: " +  _LURL);
    
   _C.KeyWords=_W.location.toString().split('/')[3].toLowerCase().split('+').join('_');
   GEL.log("keyword: " + _C.KeyWords);
   
   var _Se = null,
       _Ss = null,
       _To = null,
       _St = null,
       _Ap = null,
       _H = _W['OAS_sitepage'].split('/');
   
   for(var _kv=0; _kv < _H.length; _kv++) {
	       //_H[_kv] = _H[_kv].toString();
	       // if the first value has a .com or .net it's not the SSTS portion so ignore
	       if(_H[_kv].indexOf('.com') == -1 && _H[_kv].indexOf('.net') == -1) {
			   GEL.log("part: " + _H[_kv]);
			   if(_H[_kv].indexOf('.htm') != -1) {
				       _Ap = _H[_kv];
			   } else {
				       if(_Se == null) {
						   _Se = _H[_kv];
				       } else if (_Ss == null) {
						   _Ss = _H[_kv];
				       } else if (_To == null) {
						   _To = _H[_kv];
				       } else {
						   _St = _H[_kv];
				       }
			   }
	       }
   }
   
   _G.thepage.pageinfo={ 
	   title: document.title, 
	   ssts: { 
		   section: _Se,
		   subsection: _Ss,
		   topic: _To,
		   subtopic: _St
	   }
   };
   
   _G.thepage.pageinfo.adpagetype= "topics.htm";
   _P.sitecat= 100; _P.bt= 100; _P.comscore= 100;
   if(_G.thepage.pageinfo.type == 'frontpage') 
	   _P.checkm8= 200; 
   
   (function(){ 
	   var _CFG= GEL.namespace("config.comscore"); 
	   _CFG.comscoreenable= "on";
	   _CFG.c1= 2;
	   _CFG.c4= GEL.namespace("thepage.pageinfo").articleinturl || '';
	   _P.comscore= 100;
   })();
   
   /*_G.register("localconfig", {path: _LURL, base: "relative"}); */
   _G.register("localconfig", {path: _LURL});
   _G.register("com.Omniture", {path: "vendor/omniture/sitecatalyst.js"}); 
   _G.util.importer.require("localconfig").write(); 
   _G.util.importer.require("com.Omniture").write(); 
   _I.add({ 
	   name: "banner", 
	   namespace: ["widget.AdBanner"], 
	   priority: 25, 
	   callback: loadBanners	
   });
   
   _I.add({ 
	   name: "analytics", 
	   namespace: ["analytics"], 
	   priority: 100, 
	   callback: loadAnalytics 
   });   
/*
 We only want to call in contentone's report suite if we're not on a local topic site.
 If we're on a local.com's topic page the url will be topic(s).localdomain.com
 the below if will split the hostname and look at the localdomain and
 see if it matches the value from template=
 
 if they DO match, then we're not on a content one hosted topic...
 if they don't match then we need to include content one's analytics.
*/

if(window.location.hostname.toString().split('.')[1] != _SD) {
   _I.add({ 
	   name: "analytics2", 
	   namespace: ["analytics"], 
	   priority: 120, 
	   callback: loadContentOneAnalytics 
   });
}
   _I.add({ 
	   name: "ur", 
	   namespace: ["legacy.GDN"],
	   priority: 150, 
	   callback: function(){ GDN.UR.Page.Intercept= new Function(); GDN.UR.Page.Load(); }
   }); 
   _G.thepage.on("ready", function(){ _I.init(); }); 
   
   function loadContentOneAnalytics() {
          var _c1_s = new _G.bus.PageTrack(),
              _acc  = "gpapercontentone"
          ;
          
          _G.namespace("config.omniture").s_code= new s_gi(_acc);
          _G.config.omniture.account=_G.env.user.site=_acc;
          
          _c1_s.init('sitecat');
          
          var _pn = (function () {
                              if( typeof(_W['gci_content_one_pn']) != 'undefined') {
                                   return _W['gci_content_one_pn'];
                              } else {
                                   var _t = _W.location.pathname.toString().split('/');
                                   
                                   if(_t.length > 2) {
                                        _t = _t[1];
                                   } else {
                                        _t = '';
                                   }
                                   if(_t == '') {
                                        _t = _W.location.hostname.toString();
                                   }
                                   return _t;
                              }
                   })();
          
          _c1_s.setAttribute('pageName', _pn);
          _c1_s.setAttribute('marketname', _acc);
          
          _c1_s.trackView();
     }
   
   function loadAnalytics(){
	   GEL.log("loadAnalytics");
           setBusConfig(); 
	   var 
	   _V= _G.thepage.viewTracker || (function(){ 
		   _G.thepage.viewTracker= new GEL.bus.PageTrack(); 
		   return _G.thepage.viewTracker; 
	   })();
   
	   for(var _p in _P)
		   _V.init(_p) ;
	   _V.trackView(); 
   }
   
   
   function loadBanners(){ 
	   setAdConfig(); 
	   var 
		   _t= new _G.util.benchmark.Timer("Banners").start(), 
		   _bl= _G.thepage.bannerLoader= 
			   new _G.widget.AdBanner.Locator(), 
		   _bm= null 
	   ; 	
	   _bl.findBanners(); 
	   _bm= _bl.loadBanners(
		   function(){ 
			   if(this.marker.getAttribute("url")){ 
				   this.config.url= this.marker.getAttribute("url"); 
				   GEL.log("set url to " + this.config.url ); 
			   }
			   return this.config.loadOnInit;
		   }, 
		   null, 
		   false
	   );
	   _bm.on("ready", _t.getStop()); 
	   this.addElement(_bm); 
   
   }
   
   function setAdConfig(){ 
	   var 
		   _C= _G.namespace("config"),
		   _T= _G.namespace("thepage.pageinfo"),
		   _S= _T.ssts
	   ;
	   _C.AdPage= _C.adDomain;
	   
	   if(_S.section)
		   _C.AdPage+="/" + _S.section;
	   
	   if(_S.subsection)
		   _C.AdPage+="/" + _S.subsection;
	   
	   if(_S.topic)
		   _C.AdPage+="/" + _S.topic;
	   
	   
	   _C.AdPage+= "/" + _T.adpagetype;
	   
	   _C.AdNetworkId= 5111.1; 
	   _C.AdServer= "gannett.gcion.com";
   }
   function setBusConfig(){ 
   var 
	   _W=window,
	   _obj= { 
		   channel: '',
		   currencyCode: "USD",
		   trackDownloadLinks: true,
		   trackExternalLinks: false,
		   trackInlineStats: true,
		   linkDownloadFileTypes: "exe,zip,wav,mp3,mp4,m4v,mov,mpg,avi,wmv,doc,pdf,xls",
		   linkInternalFilters: "javascript:apartments,careerbuilder,cars,customcoupon,customwire.ap.org,eharmony,gannett,gbahn,highschoolsports,homefinder,homescape,infi,job,legacy,network,newsbank,newslibrary,pictopia,salary,topix,ur.gcion.com,usatoday,traffic,planetdiscover,metromix,mom",
		   linkLeaveQueryString: false,
		   linkTrackVars: "None",
		   usePlugins: true, 
		   linkTrackEvents: "None"
	   },
	   _C= _G.namespace("config"), 
	   _A= _G.namespace("config.bus.properties"),
	   _O= _G.namespace("config.omniture")
	   ;
	   for(var p in _obj){ 
		   if(!(p in _O)) 
			   _O[p]= _obj[p]; 
	   }
	   _G.config.bus.properties= { 
		   
                   channel: "contentone",
		   server: "contentone",
		   custom6: "news",
		   custom8: "lingospot.com",
		   pageName: (function () {
                              if( typeof(_W['gci_content_one_pn']) != 'undefined') {
                                   return "content One:" + _W['gci_content_one_pn'];
                              } else {
                                   var _t = _W.location.pathname.toString().split('/');
                                   
                                   if(_t.length > 2) {
                                        _t = "content one:" + _t[1];
                                   } else {
                                        _t = '';
                                   }
                                   if(_t == '') {
                                        _t = "content one:" + _W.location.hostname.toString();
                                   }
                                   return _t;
                              }
                   })(),
		   contenttype: "section",
		   location: _W.location.href.split("?")[0],
		   syndication: _W.location.href.split("?")[1],
		   marketname: _W['g_affilSstatId'],
                   useraction: (function() {
                         var _p = GEL.env.url.qsv;
                         if(_p.odyssey)
                              return _p.odyssey;
                   })()
	   };
   
   }
})(); 
