$(document).ready(function() {
    // tlo w menu
    if ($("#left-nav")[0]) {
        var leftNav = $("#left-nav");
        
        if ($("#salon-atrium-plaza").hasClass('active')) {
            $(leftNav).css("background-position", "0 0");
        }
        
        if ($("#salon-and-spa").hasClass('active')) {
            //console.log('test');
            $(leftNav).css("background-position", "-46px 0");
            //console.log("test: " + $(leftNav).css("background-position"));
        }
        
        if ($("#salon-saska-kepa").hasClass('active')) {
            $(leftNav).css("background-position", "-92px 0");
        }
    }
    
    // galerie w postach
    if ($("#post-gallery")[0]) {
        $("<div>", {
            'class': "simple_overlay",
            id: "photo",
            html: '<div class="contentWrap"></div>'
        }).appendTo('body');
        
        $("#post-gallery ul li a[rel]").overlay({
            onBeforeLoad: function() {
                
                // grab wrapper element inside content
                var wrap = this.getOverlay().find(".contentWrap");
                wrap.empty();
                // load the page specified in the trigger
                wrap.append("<img src='" + this.getTrigger().attr("href") + "' />");
            }
            
        });
    }
    
    // dodawanie zdjęć
    if ($("#add-photo")[0]) {
        $("<div>", {
            'class': "modal",
            id: "add-photo-modal"
        }).appendTo('body');
        
        $("#add-photo").attr('rel', "#add-photo-modal");
        
        $("a#add-photo[rel]").overlay({
            expose: { 
                color: '#fff', 
                loadSpeed: 200, 
                opacity: 0.9 
            },
            onBeforeLoad: function() {
                var wrap = this.getOverlay();
                wrap.load(this.getTrigger().attr("href"));
            }
        });
    }
    
    if ($(".scroll-pane")[0]) {
        $(".scroll-pane").jScrollPane({
            scrollbarWidth: 2
        });
    }
    
    // potwierdzenie usunięcia elementu
    if ($("a.confirm-delete")[0]) {
        $("<div>", {
            'class': "modal",
            id: "yesno",
            html: "<h2>Usunięcie elementu</h2><p>Czy jesteś pewien, że chcesz usunąć ten element?</p><p><button class='close button'>Tak</button> <button class='close button'>Nie</button></p>"
        }).appendTo('body');
        
        $("a.confirm-delete").attr('rel', '#yesno');
        
        var trigger;
        var triggers = $("a.confirm-delete").overlay({ 
            expose: { 
                color: '#fff', 
                loadSpeed: 200, 
                opacity: 0.9 
            }, 
            onLoad: function(){
                trigger = this.getTrigger();
            },
            closeOnClick: false 
        });
        
        var buttons = $("#yesno button").click(function(e) { 
            var yes = buttons.index(this) === 0; 
            if (yes) {
                window.location = trigger.attr("href"); 
            }
        });
    }
    
    // górne menu
    $("#cat-nav li a").each(function(){
        if (window.location.toString().search($(this).attr('href')) > -1) {
            $(this).addClass('current');
        }
    });
    
    // komunikaty
    if ($(".info, .success, .warning, .error, .validation, .notice")[0]) {
        $("<span>", {
            'class' : 'close',
            text: "x",
            click: function(){
                $(this).parent().slideUp('slow', function(){
                    $(this).remove();
                });
            }
        }).appendTo(".info, .success, .warning, .error, .validation, .notice");
        
        setTimeout(function() {
            $('.info, .success, .warning, .error, .validation, .notice').slideUp('slow', function(){
                $(this).remove();
            });
        }, 10000); 
    }
    
    // spis treści biuletynu
    $("#sidebar_bulletin ol li a").each(function(){
        var href = $(this).attr('href');
        if (window.location.toString().search(href) > 0) {
            $(this).parent().addClass('current');
        }
    });
});

