$(function(){
	//jMyCarousel
	$('.jMyCarousel').jMyCarousel({visible: '100%', eltByElt: true, evtStart: 'mousedown', evtStop: 'mouseup', speed: 250, circular: false, btnPrev: $('#prev'), btnNext: $('#next')});

	//fancybox
	$('#catalog a[rel="group"], .old_gallery a[rel="group"]').fancybox({'titlePosition':'inside', 'titleShow': 'false', 'transitionIn': 'fade',	'transitionOut': 'fade','overlayColor': '#000'});

	if ($('body').hasClass('black')) {
		c = $('.top li a').css('color');
		$('.top li').hover(
			function(){
				$('.top li a').css({color: '#7C7C7C'});
				$(this).find('a').css({color: '#fff'});
			},
			function(){
				$('.top li a').css({color: c});
			}
		);
	};	
	
	//ресайз
	$(window).resize(function(){
		catalog();
		columns();
	});
	
	//вертикальное выравнивание моделей и стрелок в каталоге
	catalog();
	
 	function catalog() {		
		if ($('.basket img').length) {			
			$('#footer').css({margin: '-133px auto 0'});
			$('#catalog').css({top: ($(document).height()-187-153-$('#catalog').height())/2 + 'px'});
			$('#next, #prev').css({top: $(document).height()/2 + 'px'});
		} else {
			$('#footer').css({margin: '-40px auto 0'});		
			$('#catalog').css({top: ($(document).height()-187-61-$('#catalog').height())/2 + 'px'});
			$('#next, #prev').css({top: ($(document).height()+(187/2))/2 + 'px'});
		};
	};	
	
	//выбор цвета в каталоге
	$('#color span').each(function(){
		$(this).click(function(){
			var
				src = $(this).parent().parent().parent().prev('.info-image').attr('src').match('[0-9]+'),
				color = $(this).attr('value');
            adr = this;
			$('#color p').text('Цвет: ' + $(this).text());
            $.post('/ajax.php', {
                'color':color,'recolor':'recolor'
            },
            function(data){
                data_img = data;
                $(adr).parent().parent().parent().prev('.info-image').attr('src', data);
            });
		});
	});
	
	//вытягиваем таблицу на главной странице во всю высоту экрана	
	columns();
		
	function columns() {
		$('.columns').css({height: ($(window).height() - ($('#header').height()+$('#footer').height()))-41 + 'px'});
	};
	
	//регистрация (в зависимости от урл показываем нужную часть регистрации)
	registration();
	
	function registration(){
		$('#l, #r').hide();
		
		var 
			r = window.location.href.match('#r'),
			l = window.location.href.match('#l');
			
		if (r) {$('#r').show();};
		if (l) {$('#l').show();};
		
		$('a.register, a[href="/register#r"]').click(function(){
			$('#r').css({position: 'absolute'}).fadeIn('fast');
			$('#l').css({position: 'absolute'}).fadeOut('fast');
		});
		
		$('a.loggin').click(function(){
			$('#r').css({position: 'absolute'}).fadeOut('fast');
			$('#l').css({position: 'absolute'}).fadeIn('fast');
		});		
	};
	
	//заказать прайс-лист
	$('#openit').toggle(
		function(){$('.request-price').fadeIn('fast');},
		function(){$('.request-price').fadeOut('fast');}
	);	
	
});
