newsi.bbccom.AdLoaderStub = function(){
this._loadComplete = false;
this._objZoneFile = new Object();
this._isAdCall = false;
this._objZoneData = new Object();
this._adConfigurator = new newsi.bbccom.AdConfigurator();
this._listeners = new Array();
this._intTimer;
this._timerActive = false;
}
newsi.bbccom.AdLoaderStub.prototype = new Object;
newsi.bbccom.AdLoaderStub.prototype.addListener = function( objListen ){
this._listeners[0] =  objListen;
}
newsi.bbccom.AdLoaderStub.prototype.removeListener = function(){
this._listeners.splice(0);
}
newsi.bbccom.AdLoaderStub.prototype.init = function(){
var parent = this;
this._timerActive = true
if(document.getElementById( this._adConfigurator.getPropPath("_adBugElement") ) ){
document.getElementById(this._adConfigurator.getPropPath("_adBugElement") ).disabled = true;
}
if(window.attachEvent){
window.attachEvent("onload",function(e) { parent._onLoad(); });
}
else if(window.addEventListener){
window.addEventListener("load", function(e) { parent._onLoad(); },false);
}
}
newsi.bbccom.AdLoaderStub.prototype._broadcastMessage = function (){
if( this._timerActive && this._objZoneData.ads ){
this._listeners[0]["adloadTimeElapsed"]();
}
else{
window.clearTimeout(this._intTimer);
}
}
newsi.bbccom.AdLoaderStub.prototype._writeScriptElement = function(objElement){
var dE = document.createElement("script");
dE.setAttribute( "type" , "text/javascript" ) ;
dE.setAttribute( "id" , objElement.tagId ) ;
dE.setAttribute( "src" , objElement.tagSrc) ;
document.body.appendChild(dE);
}
newsi.bbccom.AdLoaderStub.prototype._onLoad = function(){
var parent = this;
this._writeScriptElement( new Object({	tagId:"script_zonefile",
tagSrc:this._adConfigurator.getPropPath("_zoneFile") } ) );
this._intTimer = window.setTimeout(function(e) { parent._broadcastMessage(); },AdLoaderStub.getInstance().getAdConfigurator().getPropPath("_timerInterval") )
}
newsi.bbccom.AdLoaderStub.prototype._clearUp = function(){
if(window.removeEventListener){
window.removeEventListener("load",this._onLoad,false);
}
else if(window.detachEvent){
window.detachEvent("onload",this._onLoad);
}
delete this._onLoad;
delete this._adSlots;
}
newsi.bbccom.AdLoaderStub.prototype.onZoneFileLoad = function(obj){
var objZoneParser = new newsi.bbccom.AdZoneParser(obj);
this._objZoneData = objZoneParser.getZoneData();
if( newsi.getIsGB() == false ){
this._isAdCall = true;
this._writeScriptElement( new Object({	tagId:"script_analytics",
tagSrc:this._adConfigurator.getPropPath("_analyticsFile") } ) );
}
if(newsi.getIsIpAdvertiseCombined() && this._objZoneData.ads){
this._writeScriptElement( new Object({	tagId:"script_application",
tagSrc:this._adConfigurator.getPropPath("_appFile") } ) );
}
else{
var adSlots = this._adConfigurator.getPropPath("_adSlots");
for(var ad in adSlots){
var objElement = new newsi.HTML.DOM( {divId:adSlots[ad].name} );
var closedClass = adSlots[ad].name + "closed";
var oCl = {el:objElement.divId,className:closedClass};
if(newsi.gebid( adSlots[ad].name ) ) objElement.setClass(oCl);
}
this._timerActive = false;
}
this._objZoneFile = obj;
this._clearUp();
}
newsi.bbccom.AdLoaderStub.prototype.getZoneFile = function(){
return this._objZoneFile;
}
newsi.bbccom.AdLoaderStub.prototype.getIsAdCall = function(){
return this._isAdCall;
}
newsi.bbccom.AdLoaderStub.prototype.getZoneFileData = function(){
return this._objZoneData;
}
newsi.bbccom.AdLoaderStub.prototype.getAdConfigurator = function(){
return this._adConfigurator;
}
newsi.bbccom.AdLoaderStub.prototype.getTimer = function(){
return this._intTimer ;
}
newsi.bbccom.AdLoaderStub.prototype.setActiveTimer = function(isActive){
this._timerActive = isActive;
}
newsi.bbccom.AdZoneParser = function(objZoneFile){
this._zoneFile = objZoneFile;
this._zoneDataVals = new Object( {keywords:{} } );
}
newsi.bbccom.AdZoneParser.prototype = new Object;
newsi.bbccom.AdZoneParser.prototype._parseZoneListElement = function(element , url, searchPos){
for(var dataProp in element.data){
if( dataProp == "keyValues" ){
for(kw in element.data.keyValues){
this._zoneDataVals.keywords[kw] = element.data.keyValues[kw];
}
}
else{
this._zoneDataVals[dataProp] = element.data[dataProp]
}
}
if(element.zoneList){
for(var i = 0; i < element.zoneList.length; i++ ){
var zne = element.zoneList[i];
var matchPos = url.indexOf(zne.uri , searchPos);
if(matchPos != -1 ){
return this._parseZoneListElement(zne,url,matchPos);
}
}
}
return this._zoneDataVals;
}
newsi.bbccom.AdZoneParser.prototype.getZoneData = function(){
var objUrl = new String( AdLoaderStub.getInstance().getAdConfigurator().getPropPath("_url") );
var lstMatches = new Array();
var oZoneData = new Object();
if(!this._zoneFile.zones){
oZoneData = {data:{ads:false, site:"bbccom.live.site.news", zone:"default",keywords:{sectn:"news",news:"news"} } };
}
if( this._zoneFile.zones.zoneList.length > 0 ) {
oZoneData = AdLoaderStub.getInstance()._zoneOverRide( this._parseZoneListElement(this._zoneFile.zones, objUrl ) );
}
delete this._zoneFile;
return oZoneData;
}
function Singleton ( oSuper ) {
var _private  = {_instance: null };
return {getInstance: function () {
if ( _private._instance == null ){
_private._instance = new oSuper ();
}
return _private._instance;
}
}
};
var AdLoaderStub = Singleton ( newsi.bbccom.AdLoaderStub );
AdLoaderStub.getInstance().init();
