
var Layerbox = {

    /** Configuraciones **/
    time2hide: 5000,
    anchoLayer: 770,
    altoLayer: 370,
    opacityLayer: 0.70,
    cookieName: 'publicidadLayer',
    expiredays: 365,

    setAutohide: function(path) {
        var thecookie = Layerbox.readCookie();
        if(thecookie === '' || thecookie === null) {
            $().colorbox({
                href: path,
                width: Layerbox.anchoLayer,
                height: Layerbox.altoLayer,
                opacity: Layerbox.opacityLayer,
                transition: 'none',
                scrolling: false,
                open: true,
                overlayClose: false,
                onOpen: function() {
                    $('#cboxTitle').remove();
                    setTimeout(function() {
                        $(this).colorbox.close();
                    }, Layerbox.time2hide);
                    Layerbox.createCookie();
                }
            });
        }
    },

    createCookie: function() {
        var valor = 'true';
        var expires = '';
        if (Layerbox.expiredays) {
            var date = new Date();
            date.setDate(date.getDate()+(Layerbox.expiredays));
            expires = "; expires="+date.toGMTString();
        }
        document.cookie = Layerbox.cookieName+"="+valor+expires+"; path=/";
    },

    readCookie: function() {
        var nameEQ = Layerbox.cookieName + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            if (c.indexOf(nameEQ) !== -1) {
                return c.substring(nameEQ.length,c.length);
            }
        }

        return '';
    }
};
