actual_main_pic = 0;
var pause_pic_change = 0;

function change_actual_pic(index) {
    if (actual_main_pic==index) return false;
    $target = $('.pic DIV').eq(index);
    $('.pic DIV.active').fadeOut('slow').removeClass('active');
    $("#main_pic .menu UL LI A").removeClass('active');
    $('a', $("#main_pic .menu UL LI")).eq(index).addClass('active');
    $target.fadeIn('slow').addClass('active');
    actual_main_pic = index;
}

function step_main_pic() {
    if (pause_pic_change==1) return;
    $('.pic DIV').stop(true, true);
    change_actual_pic( actual_main_pic < ($('.pic DIV').length-1) ? (actual_main_pic+1) : 0 );
}

function init_main_pic() {
    $("#main_pic .menu UL LI A").hoverIntent( 
        function() {
            var index = $(this).parents('li').prevAll().size();
            change_actual_pic(index);
        }, 
        function() {
            
        } 
    )
    $("#main_pic").hover(
        function() {
            pause_pic_change = 1;
        },
        function() {
            pause_pic_change = 0;
        }
    );
    $("#main_pic").bind('click', function() {
        var href = $('#main_pic .menu UL LI A.active').attr('href');
        window.location = href;
    })
}

function start_main_pic_interval()
{
    main_pic_interval = setInterval('step_main_pic()', 5000);
}



$(document).ready( function() {
    init_main_pic();
    start_main_pic_interval();

});


