$(document).ready( function() {
setTimeout('theRotator()',2500);


        setTimeout(function()
        {
            $('#menu_sel').slideDown('slow');
        },'300');
        $('a[rel=lightbox]').lightBox();
     if($(".popup_body").length)
  {
        centerPopup();
        loadPopup();
  }
    //Click out event!
    $(".white_background").click(function()
    {
        disablePopup();
    });

    //Press Escape event!

    $(document).keypress(function(e)
    {
        if(e.keyCode==27 && popupStatus==1)
        {
            disablePopup();
        }
    });


//скрипты
});

function theRotator() {
	// Устанавливаем прозрачность всех картинок в 0
	$('div#rotator li').hide();
	rotate();

 
	// Вызываем функцию rotate для запуска слайдшоу, 5000 = смена картинок происходит раз в 5 секунд
	setInterval('rotate()',5000);
	
}

function rotate() {	
	// Берем первую картинку
	var current = ($('#rotator li.show')?  $('#rotator li.show') : $('#rotator li:first'));
 
	// Берем следующую картинку, когда дойдем до последней начинаем с начала
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('#rotator li:first') :current.next()) : $('#rotator li:first'));	
 
	// Расскомментируйте, чтобы показвать картинки в случайном порядке
	// var sibs = current.siblings();
	// var rndNum = Math.floor(Math.random() * sibs.length );
	// var next = $( sibs[ rndNum ] );
 
	// Подключаем эффект растворения/затухания для показа картинок, css-класс show имеет больший z-index
	
 
	// Прячем текущую картинку
	current.hide()
	.removeClass('show');
	
	next.hide()
	.addClass('show')
	.show();
	
	
};

$(window).load( function() {
 
});

$(function() {
	$("#mainSlideShow .title-box").html('<a href="#" title="">'+$('#mainSlideShow .item:not(.cloned):first a').attr('title')+'</a>');
	$("#mainSlideShow .slideshow-wrap").scrollable({
		circular: true,
		onSeek: function(event) {
			$("#mainSlideShow .title-box").html('<a href="#" title="">'+$('#mainSlideShow .item:eq('+(this.getIndex()+1)+') a').attr('title')+'</a>');
		}
	}).navigator().autoscroll({interval: 3000});
	
	
	$('#brandsTabs').tabs();
	
	$('table').each( function() {
		var trc = 0;
		$(this).find('tr').each( function() {
			if( $(this).hasClass('caption') ){
				trc = -1;
			}		
			if( trc > 0 ) {
				$(this).addClass('odd');
				trc = 0;
			} else {
				trc++;
			}
		});
	});
	
	$('#rotator a img').each(function(index, element) {
        var img_o = $(this).attr('src');
		var tmp = img_o.split('.');
		tmp = tmp[0]+'_hover.'+tmp[1];
		$('<img/>').attr('src',tmp);
    });
	
	var img_original;
	var img_hover;
	$('#rotator a').hover(
	function(){
		img_original = $(this).children('img').attr('src');
		img_hover = img_original.split('.');
		img_hover = img_hover[0] + '_hover.'+img_hover[1];
		$(this).children('img').attr('src',img_hover);
		},
	function(){
		$(this).children('img').attr('src',img_original);
		}
	);
});

//cufon
Cufon.replace('.top .header .phone .inner');
Cufon.replace('.top .header .auth-link .inner a', { hover: true });
Cufon.replace('.side h3');
Cufon.replace('.header h3');
Cufon.replace('.page-header h3');
Cufon.replace('.product .price');
Cufon.replace('.catalog .price');


        function showImg(src,elem,link)
            {
                $(elem).fadeOut('slow', function(){
                    $(elem).attr("src",src);
                });
                $(elem).fadeIn('slow');
                $('.img_big_link').attr("href",link);
            }
