/*
 * @package Mooncake CSS Framework
 * @subpackage common.js
 *
 * @author: P1RATE
 * @link: p1rate@inbox.ru
 *
 * @date 03/07/2011
 * @lastmodified 20/07/2011
 */

$(function(){

/*
 * @section enable JS
 */

	$('body').attr('id', 'js');

	if ($('#js').length) {

/*
 * @section catalog scroller
 */

		p = 0;
		h = $('.catalogItemsWrap').height();
		s = $('.catalogItemsScroller').height();
		i = $('.catalogItem').outerHeight(true);
		t = $('.catalogItem').length;
		speed = 200;
		method = 'easeInOutCubic';
		
		if (t <= 5) {
			$('.catalogItemsWrap').css({height: 'auto'});
			$('.catalogArrowTop, .catalogArrowBottom').hide();
		};
		
		$('.catalogArrowTop').click(function(){
			if (s < h) {
				return false;
			} else {		
				if (-p <= 0) {p = 0;} else {p += i;};
				$('.catalogItemsScroller').animate({marginTop: p +'px'}, {duration: speed, easing: method});
			};
		});

		$('.catalogArrowBottom').click(function(){
			if (s < h) {
				return false;
			} else {		
				if (-p >= s-i*2) {p = -(s-i*2);} else {p -= i;};
				$('.catalogItemsScroller').animate({marginTop: p +'px'}, {duration: speed, easing: method});
			};
		});

/*
 * @section catalogImage switcher
 */

		$('.catalogItemInfoMiniImages img:first').addClass('activeMiniImg');

		$('.catalogItemInfoMiniImages img').click(function(){
			$('.catalogItemInfoMiniImages img').removeClass('activeMiniImg');
			$(this).addClass('activeMiniImg');
			$('#img_viewer').attr('src', $(this).attr('data-img'));
		});

		$('.catalogItemInfoMiniImages img').hover(
			function(){$(this).animate({opacity: '1'}, 250);},
			function(){$(this).animate({opacity: '0.5'}, 250);}
		);

	};
});
