$(document).ready(function() {
    // initialize overlay trigger
    $("a[rel]").overlay({
        // start exposing when overlay starts to load
        onBeforeLoad: function() {
            // this line does the magic. it makes the background image sit on top of the mask
            this.getBackgroundImage().expose({color: '#ddd'});
            // grab wrapper element inside content
            var wrap = this.getContent().find("div.wrap");
            wrap.load(this.getTrigger().attr("href"));
        },
        // when overlay is closed take the expose instance and close it as well
        onClose: function() {
            $.expose.close();
        }
    });
    $("input[rel]").overlay({
        // start exposing when overlay starts to load
        onBeforeLoad: function() {
            // this line does the magic. it makes the background image sit on top of the mask
            this.getBackgroundImage().expose({color: '#ddd'});
            // grab wrapper element inside content
            var wrap = this.getContent().find("div.wrap");
            wrap.load(this.getTrigger().attr("href"));
        },
        // when overlay is closed take the expose instance and close it as well
        onClose: function() {
            $.expose.close();
            if ($("#agreement").is(':checked') ) {
                $("#agreement").attr('checked', false);
            } else {
                $("#agreement").attr('checked', true);
            }
        }
    });
});
function loadLogin (url) {
    $('#lost-password').fadeOut(800);
    $.get(url, '', function (html) {
                    $('#lost-password').replaceWith(html);
                    $('#login').hide();
                    $('#login').fadeIn(1800);
                    });
    return false;
}
function loadLostpass (url) {
    $('#login').fadeOut(800);
    $.get(url, '', function (html) {
                        $('#login').replaceWith(html);
                        $('#lost-password').hide();
                        $('#lost-password').fadeIn(1800);
                    });
    return false;
}
function caudicazione(url) {
    window.open(url,'caud','width=295,height=335,directories=0,location=0,menubar=0,status=0,toolbar=0');
}
function toggleCoreg() {
    if ($('#agreement').attr("checked")) {
        $('input[id^=creg-]').attr("checked", true);
        $('input[id^=coreg]').attr("value", 1);
    } else {
        $('input[id^=creg-]').attr("checked", false);
        $('input[id^=coreg]').attr("value", 0);
    }
}
