﻿var intval = ""
function start_Int() {
    if (intval == "") {
        intval = window.setInterval("cycleTabs()", 3000)
    } else {
        stop_Int()
    }
}

function stop_Int() {
    if (intval != "") {
        window.clearInterval(intval)
        intval = ""
    }
}

function cycleTabs() {
    var currentTab = j$('#carouselPosition').val();

    currentTab++

    var newTab = (currentTab % 4 + 1);

    j$.get('/site/pages/carouselContent.aspx', { panel: newTab }, function(data) {
        j$('.carouselBody').fadeOut(100, function() {
            j$(this).html(data).fadeIn(100);
        });
    });
    j$('.clickTab').removeClass('on');
    j$('#tab' + newTab).addClass('on');

    j$('#carouselPosition').val(currentTab);
}

function gallery(page, thisObject) {
    j$.get('/site/pages/carouselContent.aspx', { panel: page }, function(data) {
        j$('.carouselBody').fadeOut(100, function() {
            j$(this).html(data).fadeIn(100);
        });
    });
    j$('.clickTab').removeClass('on');
    j$(thisObject).addClass('on');

}

j$(document).ready(function() {
    j$('.clickTab').click(function() {
        var pageNum = j$(this).attr("href").match(/panel=([0-9]+)/)[1];
        //j$('.carouselBody').load('/site/pages/carouselContent.aspx', { panel: pageNum });
        j$('#carouselPosition').val(pageNum - 1);
        gallery(pageNum, this);
        return false;
    });
    j$('.clickTab').mouseenter(function() {
        stop_Int();
    });

    j$('.clickTab').mouseleave(function() {
        start_Int();
    });

    j$('.carouselBody').mouseenter(function() {
        stop_Int();
    });

    j$('.carouselBody').mouseleave(function() {
        //cycleTabs();
        start_Int();
    });
    start_Int();
});

startList = function() {
    if (document.all && document.getElementById) {
        navRoot = document.getElementById("nav");
        for (i = 0; i < navRoot.childNodes.length; i++) {
            node = navRoot.childNodes[i];
            if (node.nodeName == "LI") {
                node.onmouseover = function() {
                    this.className += " over";
                }
                node.onmouseout = function() {
                    this.className = this.className.replace
          (" over", "");
                }
            }
        }
    }
}
window.onload = startList;    