AdvertLayer = function() {
    this.xboxaktuellAdvertLayerConfiguration = {
        cookieLifeTime: 1,       // nach X Tagen beginnt die Zählung erneut
        cookieName: 'xboxaktuellAdvertLayerCounter',
        clicksBefore: 2,
        clicksBetween: 10,
        
        layerOpacity: 0.7,
        layerText: '<a href="http://forum.xboxaktuell.de/member.php?action=login">Anmelden</a> bzw. <a href="http://forum.xboxaktuell.de/member.php?action=register">registrieren</a>, um diese Werbung zu deaktivieren!',
        pathJavascriptCookie: '/advert_layer/jquery.cookie.js',
        pathJavascriptColorbox: '/advert_layer/jquery.colorbox.js'
    }   

    this.updateCookieCounter = function() {
        pageViews = this.getCookieCounter();        
        jQuery.cookie(this.xboxaktuellAdvertLayerConfiguration.cookieName, (pageViews + 1), {
            expires: this.xboxaktuellAdvertLayerConfiguration.cookieLifeTime
        });
    }    
    this.resetCookieCounter = function() {
        jQuery.cookie(this.xboxaktuellAdvertLayerConfiguration.cookieName, 0)
    }    
    this.getCookieCounter = function() {
        var pageViews = jQuery.cookie(this.xboxaktuellAdvertLayerConfiguration.cookieName);
        if(pageViews == null) {
            pageViews = 1;
        }        
        return parseInt(pageViews);
    }    
    this.hideFlashObjects = function() {
    	jQuery("select, object, embed").css("visibility", "hidden");
    	jQuery("#xboxaktuellAdvertLayer select, #xboxaktuellAdvertLayer object, #xboxaktuellAdvertLayer embed").css("visibility", "visible");
    }
    this.showFlashObjects = function() {
    	jQuery("select, object, embed").css("visibility", "visible");
    }
    
    this.showAdvert = function() {
        cBefore = this.xboxaktuellAdvertLayerConfiguration.clicksBefore;
        cBetween = this.xboxaktuellAdvertLayerConfiguration.clicksBetween;
        
        if(((this.getCookieCounter() - cBefore) % cBetween) == 0) {
            jQuery.colorbox({
                inline:true, 
                href: "#xboxaktuellAdvertLayerContent",
                title: this.xboxaktuellAdvertLayerConfiguration.layerText,
                opacity: this.xboxaktuellAdvertLayerConfiguration.layerOpacity,
                onOpen: this.hideFlashObjects,
                onClosed: this.showFlashObjects
            });    
        }        
        this.updateCookieCounter();
    }       
    // construct
    this.init = function() {
    	var scriptCookie = jQuery('<script src="'+ this.xboxaktuellAdvertLayerConfiguration.pathJavascriptCookie +'"></script>');
    	var scriptBox = jQuery('<script src="'+ this.xboxaktuellAdvertLayerConfiguration.pathJavascriptColorbox +'"></script>');
    	
    	jQuery("head").append(scriptCookie);
    	jQuery("head").append(scriptBox);
    	
        if(jQuery("#xboxaktuellAdvertLayer").length > 0) {                 
            this.showAdvert();
        }
    }
}

//$.noConflict();
jQuery(function() {
    adLayer = new AdvertLayer();
    adLayer.init();
});
