var pause = false;
var slide = 0;
$(document).ready(function(){
 // Default text on inputs  - in order for this to work, make the alt tag the same as the value
    $("input[type=text]").focus(function() {
        if( $(this).attr('alt') == $(this).val() ) $(this).val('');
    }).focusout(function(){
        if( $(this).val() == '' ) $(this).val( $(this).attr('alt') );
    });
});


$(window).ready(function() {
   $(".rotator img").each(function(){
       if ( $(this).hasClass("active") )
           $(this).css({"opacity": "100"});
       else
           $(this).css({"opacity": "0"});
   });
});


$(window).load(function() {

    $(".promo li").hover(
        function(){
            slide = $(this).index();
            rotator( $(this).index() );
            pause = true;
        }, function(){ pause = false; }
    );

    setInterval( 'rotator(null);' , 5000);

});

function rotator(index){

    var index_start = index;

    if( pause ) return false;

    var prev = $(".rotator img.active");

    if( index == null) {
        if( ( $(".rotator img").length - 1 ) == prev.index() ) index = 0;
        else index = prev.index() + 1;
    }

    if( index == prev.index() ) return false;

    // Navigation
    $( ".promo li.active" ).removeClass();
    $( ".promo li" ).eq( index ).addClass( "active" );

    setTimeout(function() {
       if( index != slide && index_start != null ) {
           return false;
       } else {

            // Not black effect 
            $(".rotator").css({background: 'url(' + prev.attr('src') + ') no-repeat'});

            prev.stop(false).css({"opacity": "0"}).removeClass('active');
            $(".rotator img:eq(" + index + ")")
                .stop()
                .animate({"opacity": "1"}, 1500)
                .addClass( "active" );
            return false;
       }
    }, 400);
}



