var currentTab = 0;
var rotateSpeed = 3000;
var numTabs;
var autoRotate;
var toggleSpeed = 300;
var toggleType = "";

function openTab(clickedTab) {
    var thisTab = $("#home-main #menu li a").index(clickedTab);

    $("#home-main #menu li").removeClass("active");
    $("#home-main #menu li:eq("+thisTab+")").addClass("active");

    $("#home-main #picture img").hide(toggleType, {}, toggleSpeed);
    $("#home-main #picture img:eq("+thisTab+")").show(toggleType, {}, toggleSpeed);

    $("#home-main #description .item").hide(toggleType, {}, toggleSpeed);
    $("#home-main #description .item:eq("+thisTab+")").show(toggleType, {}, toggleSpeed);

    currentTab = thisTab;
}

function rotateTabs() {
    var nextTab = (currentTab == (numTabs - 1)) ? 0 : currentTab + 1;
    openTab($("#home-main #menu li a:eq("+nextTab+")"));
}

$(document).ready(function() {
    //$(".item", "#home-main #description").equalHeights();
    numTabs = $("li a", "#home-main #menu").length;

    $("#home-main #menu li a").click(function() {
        openTab($(this)); return false;
    });

    
    //autoRotate = setInterval("rotateTabs()", rotateSpeed);
    //$("#home-main #menu li a:eq("+currentTab+")").click()

    $("#home-main").mouseover(function() { clearInterval(autoRotate); /*openTab($("li a", this));*/ })
        .mouseout(function() { autoRotate = setInterval("rotateTabs()", rotateSpeed); });
    
    //$("#home-main #menu").mouseover(function() { clearInterval(autoRotate); /*openTab($("li a", this));*/ })
    //    .mouseout(function() { autoRotate = setInterval("rotateTabs()", rotateSpeed); });

    $("#home-main #menu li:eq("+currentTab+")").click();
    $("#home-main #menu").mouseout();

    // pretty Photo initialization
    $("a[rel^='prettyPhoto']").prettyPhoto({
        animationSpeed: 'normal', /* fast/slow/normal */
        padding: 40, /* padding for each side of the picture */
        opacity: 0.35, /* Value betwee 0 and 1 */
        showTitle: false, /* true/false */
        allowresize: true, /* true/false */
        counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
        theme: 'facebook', /* light_rounded / dark_rounded / light_square / dark_square */
        hideflash: true,
        wmode: 'opaque'
    });

    $("a.prettyPhoto").prettyPhoto({
        animationSpeed: 'normal', /* fast/slow/normal */
        padding: 40, /* padding for each side of the picture */
        opacity: 0.35, /* Value betwee 0 and 1 */
        showTitle: false, /* true/false */
        allowresize: true, /* true/false */
        counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
        theme: 'facebook', /* light_rounded / dark_rounded / light_square / dark_square */
        hideflash: true,
        wmode: 'opaque'
    });

});
