$(document).ready(function(){
    var curr = 0;
    var next = 0;
    var timer_on = true;
    var timer_delay = 0;
    
    $.timer(10000, function (timer_inst) {        
        if(timer_on) {
            updateSplashImage(2000, 1000);
        }
        else {
            $.timer.stop();
        }
    });
    
    $("div.splash-num").click(function(){
        updateSplashImage(0,0, $(this).index());
    });

    $("div.splash-num").mouseover(function (){ timer_on = false;});
    $("div.splash-num").mouseout(function (){ timer_on = true;});

    function getNextSplashImageIndex(index) {
        return (index >= $("#splash-banner img").length - 1) ? 0 : index + 1;
    }
    
    function updateSplashImage(in_speed, out_speed, force_next){
        next = force_next == null ? getNextSplashImageIndex(curr) : force_next;
        $("#splash-banner img").eq(curr).fadeOut(in_speed, function(){});
        $("#splash-banner img").eq(next).fadeIn(out_speed, function(){});                 
        $("div#banner-title span").eq(curr).fadeOut(in_speed, function(){});
        $("div#banner-title span").eq(next).fadeIn(out_speed, function(){});
        $("div.splash-num").eq(curr).attr('class', 'splash-num blue');                  
        $("div.splash-num").eq(next).attr('class', 'splash-num orange');
        curr = next;
    }
    $("#search_bar input[type=text]").focus(function(){if($(this).val() == 'Search'){$(this).val('');}});
});

