var inatervalID;
function theRotator() {
    // Устанавливаем прозрачность всех картинок в 0
    $('div#rotator ul li').css({opacity: 0.0});
 
    // Берем первую картинку и показываем ее (по пути включаем полную видимость)
    $('div#rotator ul li:first').css({opacity: 1.0});
 
    // Вызываем функцию rotate для запуска слайдшоу, 5000 = смена картинок происходит раз в 5 секунд
    inatervalID = setInterval('rotate()',5000);
}
 
function rotate() {  

    // Берем первую картинку
    var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));
 
    // Берем следующую картинку, когда дойдем до последней начинаем с начала
    var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));    
    
    // подсветка ссылок
    $('div#rotator a.sho').removeClass('sho');
    $('div# a#'+(next.attr('id')).substring(0,3)).addClass('sho');
 
    // Расскомментируйте, чтобы показвать картинки в случайном порядке
    // var sibs = current.siblings();
    // var rndNum = Math.floor(Math.random() * sibs.length );
    // var next = $( sibs[ rndNum ] );
 
    // Подключаем эффект растворения/затухания для показа картинок, css-класс show имеет больший z-index
    next.stop();
    current.stop();
    next.css({opacity: 0.0})
    .addClass('show')
    .animate({opacity: 1.0}, 1000);
 
    // Прячем текущую картинку
    current.animate({opacity: 0.0}, 1000)
    .removeClass('show');
    
    
};
function rotateto()
{
    clearInterval(inatervalID) ; 
    id = $(this).attr('id');
    var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));
 
    // Берем следующую картинку, когда дойдем до последней начинаем с начала
    var next = $('div#rotator ul li#'+id+'li');    
    
    // подсветка ссылок
    $('div#rotator a.sho').removeClass('sho');
    $('div# a#'+(next.attr('id')).substring(0,3)).addClass('sho');
 
    // Расскомментируйте, чтобы показвать картинки в случайном порядке
    // var sibs = current.siblings();
    // var rndNum = Math.floor(Math.random() * sibs.length );
    // var next = $( sibs[ rndNum ] );
 
    // Подключаем эффект растворения/затухания для показа картинок, css-класс show имеет больший z-index
    
 
    // Прячем текущую картинку
    if(next.attr('id') != current.attr('id'))
    {
        current.animate({opacity: 0.0}, 1000)
        .removeClass('show');
        
        next.css({opacity: 0.0})
        .addClass('show')
        .animate({opacity: 1.0}, 1000);
    }
        
    
    inatervalID = setInterval('rotate()',5000);
}
 
$(document).ready(function() {  
    $('div#rotator a#im1').live( 'click', rotateto );    
    $('div#rotator a#im2').live( 'click', rotateto );      
    $('div#rotator a#im3').live( 'click', rotateto );            
    $('div#rotator a#im4').live( 'click', rotateto ); 
    $('div#rotator a#im5').live( 'click', rotateto );           
    // Запускаем слайдшоу
    theRotator();
    $('div.descr-cont').mouseover(function(){
        $(this).addClass('descr-contv');
    }).mouseout(function(){
        $(this).removeClass('descr-contv');
    });
});
