

/**
 * Ad layer namespace
 */
var AdLayer = {};

AdLayer.frequency  = 33;                     // chance the ad is shown, in percent
AdLayer.cookieName = 'itlAdLayer2WasClicked'; // nam the cookie taht will store visited state

/**
 * Check if the ad layer was clicked (if the cookie is set).
 */
AdLayer.wasClicked = function() {
    return Cookie.readCookie(AdLayer.cookieName) == 'true';
}

/**
 * Check if the layer was clicked. If not, show it with the chance defined in AdLayer.frequency
 */
AdLayer.willShow = function() {
    return !AdLayer.wasClicked() && Math.random() * 100 <= AdLayer.frequency;
}

/**
 * Close the layer
 */
AdLayer.close = function() {
    $j('#ad_layer_bg, #ad_layer').remove();
}

/**
 * Store visited state in cookie, then close the layer
 */
AdLayer.onClick = function() {
    Cookie.createCookie(AdLayer.cookieName, 'true', 999);
    AdLayer.close();
}



jQuery.noConflict();
$j = jQuery;

$j(document).ready(function() {
    if (AdLayer.willShow()) {
        $j('#ad_layer_bg, #ad_layer').show();
        $j('div#ad_layer div.button a').click(function(){
            AdLayer.close();
            return false;
        });
        $j('div#ad_layer div.content a').click(function(){
            AdLayer.onClick();
            return true;
        });
    }
});

