$(document).ready(function() {
    //setInterval("banner()", 7000);
    $("#banner").banner();

    if (window.location.pathname != "/")
        $('#galerija-dots').dots();
});

if (window.location.pathname == "/") {
    $(document).ready(function() { welcomeFooter(); });
    $(window).resize(function() { welcomeFooter(); });
}
    

/**
 * This is invoked repeatedly.
 * Replaces the three images in header using smooth transition.
 * */
function banner()
{
    // all three 'banners' (divs)
    var banners = Array("#banner0", "#banner1", "#banner2");
    
    // list of images
    var images = Array();
    var i = 0;
    for (; i < window.__banner; i++)
        images[i] = '/img/banner/' + i + '.jpg';
    
    // do nothing if list is empty
    if ( i == 0 )
        return;
    
    // shuffle that list
    while ( --i ) {
        var j = Math.floor( Math.random() * ( i + 1 ) );
        var tmp_i = images[i];
        var tmp_j = images[j];
        images[i] = tmp_j;
        images[j] = tmp_i;
    }
    
    // hide, switch and show :)
    $(banners).each(function(i, dom) {
    
        if ($(banners[i]).css('display') == 'block') {
            $(banners[i]).fadeOut('slow');
        } else {
            $(banners[i]).css('backgroundImage', 'url(' + images[i] + ')');
            $(banners[i]).fadeIn('slow');
        }
            
    });
}

/**
 * Move footer to the bottom of the site if this is welcome page and 
 * if browser height allows it.
 * */
function welcomeFooter()
{
    
    if ($(window).height() < 650) {
        $("#footer").css("position", "static");
    } else {   
        $("#footer").css("position", "absolute");
        $("#footer").css("bottom", "0");
    }
}

/**
 * Show login box
 */
function showLogin()
{
    $('#login').toggle('slow')
}

/**
 * Handle photogallery dots
 */
