/***********************
** PAGE SLIDER ON INDEX
***********************/
var sliderTimer; // setTimeout() container
var sliderTimed = false; // timer status

// Make page slide
function slideTab (to) {
    var from = parseInt($("#SLIDER div.item.active").attr("id").replace("ci",""));
    
    if (to == undefined || to <= 0 || to >= 4) { if (from == 3) { to = 1; } else { to = (from+1); }
    } else { to = to; }
    
    if (from != to) {
        $("#ci"+from).css({"opacity" : 1});
        $("#ci"+from).animate({"opacity" : 0}, 500, function() {
            $(this).css({"display" : "none"});
            $(this).removeClass("active");
            $("#SLIDER .nav .nitem").removeClass("active");
            $("#n-ci"+to).addClass("active");
    
            $("#ci"+to).css({"display" : "inherit", "opacity" : 0});
            $("#ci"+to).addClass("active");
            $("#ci"+to).animate({"opacity" : 1}, 500, function() {
                setSlideTimer(true);
            });
        });
    } else {
        setSlideTimer(true);
    }
}

/*******************
** The timer handler
*******************/
function setSlideTimer (gon) {
    if (gon == true) {
        clearTimeout(sliderTimer);
        sliderTimer = setTimeout(function(){slideTab();}, 10000);
    } else {
        clearTimeout(sliderTimer);
    }
}
/*
function debugME (string) {
    var d = new Date();
    $("#debug").html($("#debug").html() + "<br/>" + string + "-- " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds());
}
*/
$(document).ready(function(){  
    setSlideTimer(true);
    $("#SLIDER .nav .nitem").click(function() { slideTab(parseInt($(this).attr("id").replace("n-ci",""))); });
    $("#SLIDER .nav .nitem .title a").click(function() { slideTab(parseInt($(this).attr("id").replace("n-cia",""))); return false; });
    $("#SLIDER").hover(function(){ setSlideTimer(false); }, function(){ setSlideTimer(true); });
    
})
