$(document).ready(function(){addEvents();});

function addEvents() 
{
    addTourEvents();
    
    startThemeViewer();
}

/******************************************************
* TOUR
******************************************************/

function addTourEvents()
{
    if (!$("#tour").length) return false;
    
    $("#itemImage").click(function(){closeAll();});
    
    $(".button").click(function(){toggleDescription($(this).attr("id")+"Desc");});
    $(".buttonDescription").click(function(){toggleDescription($(this).attr("id"));});
}

function toggleDescription(name)
{
    $("#"+name).slideToggle("slow");
}

function closeAll()
{
    $(".buttonDescription").slideUp("slow");
}

function startThemeViewer()
{
    if (!$("#themeViewer").length) return false;
    
    
    $(".theme").css("position", "absolute");
    $("#themeViewer").append("<input type='hidden' id='currentTheme' value='0' />");
   
    showNextTheme();
}

function hideTheme()
{
    var themeString = "#theme"+$("#currentTheme").val();
    $(themeString).fadeOut(1000);
    showNextTheme();
}

function showNextTheme()
{
    var nextIndex = 1*$("#currentTheme").val() + 1;

    // Check that next billboard exists else reset to 1
    //
    if(!$("#theme"+nextIndex).length)
    {
        nextIndex= 1;
    }

    $("#theme"+nextIndex).fadeIn(1000);
    $("#currentTheme").val(nextIndex);

    window.setTimeout(hideTheme, 3000);

}
