var homepage = function ($) {

    var priv = {

        showcaseCurrentIndex: 1,
        showcaseInterval: null,
        showcaseTotal: 8,
        showcaseCurrentMousePos: 'out'

    };

    return {
        onTest: function () {
            alert(priv.showcaseCurrentIndex);
        },

        startShowcase: function () {
            if (priv.showcaseInterval != 'undefined') {
                priv.showcaseInterval = setInterval('homepage.showShowcaseTab()', 8000);
            }
        },

        clickShowcaseTab: function (tabId) {
            clearInterval(priv.showcaseInterval);

            if (tabId != -1) {
                priv.showcaseCurrentIndex = tabId;
                homepage.showShowcaseTab();
            }
        },

        showShowcaseTab: function () {
            var currentTab = $("#tab" + priv.showcaseCurrentIndex);
            var currentShowcase = $("#showcase" + priv.showcaseCurrentIndex);
            var top = $(window).scrollTop();
            $('div.showcase-container').each(function () {
                $(this).hide();
            });
            currentShowcase.show();

            //Fix for skipping back to top in Chrome
            $(window).scrollTop(top);
            
            $('.gallery-area ul li').each(function () {
                $(this).removeClass('active');
            });
            currentTab.addClass('active');

            if (priv.showcaseCurrentIndex == parseInt(priv.showcaseTotal) - 1) {
                priv.showcaseCurrentIndex = 0;
            }
            else {
                priv.showcaseCurrentIndex = priv.showcaseCurrentIndex + 1;
            }
        },

        updateCurrentMousePos: function (status) { priv.showcaseCurrentMousePos = status; },
        getCurrentMousePos: function () { return priv.showcaseCurrentMousePos; }
    }
} (jQuery);

//starts the automatic tab roulation on the homepage
jQuery(function ($) {
    //unbind the functions that keeps track of the mouseposition before the page is done loading (those are bound in default.aspx file)
    $('.carousel').unbind();

    //determine where the mouse is positioned when the pageload is finished
    if (homepage.getCurrentMousePos() == 'out') //'out' = not on the showcase tabs
    {
        //homepage.startShowcase();
    }
    else {
        homepage.clickShowcaseTab(-1);
    }
    //bind the new functions that will start and pause the showcase tabs
    $('.carousel').bind('mouseout', function () {
        homepage.startShowcase();
    });

    $('.carousel').bind('mouseover', function () {
        homepage.clickShowcaseTab(-1);
    });
}
);
	
