AdController = function (config)
{ 
    this.serveAds = config.serveAds;
    this.firstrun = true;
    this.coad = "";
   
    this.lastAdTag = "lastAdTag";  //in case of noord
    this.adCountTimer = null;
    this.adEvalMark = 10000;
    this.container = {id:0,adsPlayed:0}; 
    this.maxEls = config.adInsertion.maxEls;  
    this.maxElsOnReset = config.adInsertion.maxElsonReset;  
    this.resetSwitch = config.adInsertion.resetSwitch; 
    this.raiseFranchiseIntro = config.adInsertion.raiseFranchiseIntro;
    this.killTrailingAds = (typeof config.adInsertion.killTrailingAds=="undefined") ? 0 : config.adInsertion.killTrailingAds; 
    this.dartCommand = (typeof config.adCall.dartCommand=="undefined") ? "adx" : config.adCall.dartCommand; 
    this.maxTime = (typeof config.adInsertion.maxTime=="undefined") ? 0 : config.adInsertion.maxTime;
    if (typeof config.adExclusion=="undefined")
    {
	    this.adExclusion = new Array();
    } else
        this.adExclusion = config.adExclusion;
} 

//Ads functions
dojo.lang.extend(AdController,
                    {
                        //***************ifForceCoAd********************
	                    ifForceCoAd: function (cid)
	                    { 
	                        for (var i=0;i<this.adExclusion.length;i++)
	                        {  
		                        if (cid == this.adExclusion[i].id) return this.adExclusion[i].coAdUrl; 
	                        }
	                        return false;
                        },
                        //***************ifTakesAds********************
                        ifTakesAds: function (cid)
                        {  
	                        if (!this.serveAds) return false;
	                        for (var i=0;i<this.adExclusion.length;i++)
	                        {  
		                        if (cid == this.adExclusion[i].id) return false; 
	                        }
	                        return true;
                        },
                        //***************ifTakesLeadingAd********************
                        ifTakesLeadingAd: function (takesAds, type)
                        { 
	                        try
	                        {  
		                        if (!takesAds) return false; 
		                        if (this.ifRaiseFranchiseIntro(type)) return false;
		                        return true;
	                        }
	                        catch(e)
	                        {
		                        dojo.debug("EXCEPTION: ifTakesLeadingAd() " + e.description);
	                        }
                        },
                        //***************ifForceLeadingAd********************
                        ifForceLeadingAd: function (newContainer, takesLeadingAd)
                        { 
	                        try
	                        {  
	 	                        return (newContainer && this.maxElsOnReset==0 && takesLeadingAd);  
	                        } catch(e)
	                        {
		                        dojo.debug("EXCEPTION: ifForceLeadingAd() " + e.description);
	                        }
                        }, 
                        //***************ifTakesTrailingAd********************
                        ifTakesTrailingAd: function (takesAds, type)
                        { 
	                        try
	                        {
		                        if (!takesAds) return false; 
		                        return true;
	                        } catch(e) {
		                        dojo.debug("EXCEPTION: ifTakesTrailingAd() " + e.description);
	                        } 
                        },
                        //***************ifForceTrailingAd********************
                        ifForceTrailingAd: function (takesAds, type)
                        { 
	                        try
	                        {
		                        if (!takesAds) return false;
	 	                        if (this.ifRaiseFranchiseIntro(type)) return true;
		                        return false;
	                        } catch(e)
	                        {
		                        dojo.debug("EXCEPTION: ifForceTrailingAd() " + e.description);
	                        } 
                        }, 
                        //***************ifRaiseFranchiseIntro********************
                        ifRaiseFranchiseIntro: function (type)
                        { 
	                        try {
		                        if (this.raiseFranchiseIntro && type==15) return true;
		                        return false;
	                        } catch(e)
	                        {
		                        dojo.debug("EXCEPTION: ifRaiseFranchiseIntro() " + e.description);
	                        } 
                        }
	                 }
	              );



