(function ($) {
	// VERTICALLY ALIGN FUNCTION
	$.fn.vAlign = function () {
		return this.each(function (i) {
			var ah = $(this).height();
			var ph = $(this).parent().height();
			var mh = Math.ceil((ph - ah) / 2);
			$(this).css('margin-top', mh);
		});
	};
})(jQuery);

$(function () {
	$('a[rel*=lightbox]').lightBox();
});

$(document).ready(function () {

	
	$('.products li img').vAlign();
	
	// ROTATOR
	$('#rotator').each(function () {
		var $this = $(this),
			time = null,
			eq = 0,
			len = $('.item', $this).length - 1;
		$('.item', $this).hide().css('position', 'absolute');
		$('.item:eq(' + eq + ')', $this).show();
		$('.pager a:eq(' + eq + ')', $this).addClass('active');
		$('.rotator-wrap', $this).css('overflow', 'hidden');

		var rote = function (eq) {
			if (eq != $('div.active', $this).index()) {
				$('div.item:eq(' + eq + ')', $this).show().css({ 'z-index': '2', 'opacity': '1' });
				$('div.active', $this)
					.animate({
						'opacity': '0'
					}, 500, function () {
						$(this).hide().removeClass('active').css('z-index', '1');
						$('div.item:eq(' + eq + ')', $this).addClass('active');
					});
				$('.pager a', $this).removeClass('active');
				$('.pager a:eq(' + eq + ')', $this).addClass('active');
			}
		}
		var timex = function () {
			time = setInterval(function () {
				if (eq == len) {
					eq = 0;
				}
				else {
					eq = eq + 1;
				}
				rote(eq);
			}, 5000);
		}
		timex();

		$('.pager a', $this).click(function () {
			eq = $(this).index();
			rote(eq);
			time = clearInterval(time);
			timex();
			return false;
		});
	});

});
