var fadeIndex = 0;
var fadeTimer = null;

$(document).ready(function(){
    //Shadowbox.init();

    $('#navigation > li:last').addClass('last');
    $("#navigation li").hover(
        function() { 
            if($(this).find('ul:first').css('display')=='none') { 
                $(this).find('ul:first').show(); 
                if(!$(this).find('a:first').hasClass("selected"))
                    $(this).find('a:first').addClass("selected hoverselected");
            }
        },
        function() { 
            $(this).find('ul:first').hide(); 
            if($(this).find('a:first').hasClass("hoverselected"))
                $(this).find('a:first').removeClass("selected hoverselected");
        }
    );  
    
    $("#banner").load(function(){
        var img = $('<img class="banner-img" id="second" src="" alt="" />');
        $(img).attr("src",fadeImgs.images[0].src);
        $("#banner p").after(img);
        $("#banner p").html(fadeImgs.images[0].desc);
        fadeTimer = setInterval("slideshow()",6000);
    }).trigger("load");

});

function slideshow() {
    fadeIndex += 1;
    if(fadeIndex>=$(fadeImgs.images).length)
        fadeIndex = 0;        
    $("#banner img:first").attr("src",fadeImgs.images[fadeIndex].src);
    $("#banner img#second").fadeOut(2000,function(){
        $("#banner img#second").attr("src",fadeImgs.images[fadeIndex].src);
        $("#banner img#second").show();
    });
    $("#banner p").html(fadeImgs.images[fadeIndex].desc);
}