﻿var curRotatorImgIndex = 0;


$(document).ready(
    function() {
        var intervalIndex = setInterval('rotateImg()', 5000);
        
        $('.rotator_floating_left_button').bind('mouseenter', function()
            { 
                clearInterval(intervalIndex);
                
                $('.rotator_floating_left_button').removeClass('currentSelectedRotatorButton');
                
                $(this).addClass('currentSelectedRotatorButton');
                
                $('#rotator_main_image_fore').attr('src', $(this).attr('pic'));
                $('#rotator_bottom_caption_div').html($(this).attr('cpt'));
                
                $('#rotator_main_image_link').attr('href', $(this).attr('dst'))
                $('#rotator_main_image_link_bottom').attr('href', $(this).attr('dst'))
            });
    }
);

function rotateImg()
{
    $('#rotator_left_button_' + curRotatorImgIndex).toggleClass('currentSelectedRotatorButton');
    
    curRotatorImgIndex = (curRotatorImgIndex + 1) % 6;
    
    $('#rotator_left_button_' + curRotatorImgIndex).toggleClass('currentSelectedRotatorButton');
        
    $('#rotator_main_image_fore').fadeOut('slow', function() 
        { $('#rotator_main_image_fore').attr('src', $('#rotator_left_button_' + curRotatorImgIndex).attr('pic')); }  );
        
    var nextRotatorImgIndex = (curRotatorImgIndex + 1) % 6;
    
    $('#rotator_main_image_fore').fadeIn('fast', function()
        { $('#rotator_main_image_div').css('background-image', "url('" + $('#rotator_left_button_' + nextRotatorImgIndex).attr('pic') 
            + "')"); }  );
            
    $('#rotator_main_image_link').attr('href', $('#rotator_left_button_' + curRotatorImgIndex).attr('dst'));
    $('#rotator_main_image_link_bottom').attr('href', $('#rotator_left_button_' + curRotatorImgIndex).attr('dst'));
    
    $('#rotator_bottom_caption_div').html($('#rotator_left_button_' + curRotatorImgIndex).attr('cpt'));
}

