var current = 0;
var currentThumbs = 0;
var interval;

function movePanel(index)
{
	var margin = '-' + 475 * index + 'px';
	$('.promo-holder').animate({'marginLeft': margin}, "slow");

	current = index;
}

function moveThumbs(index)
{
	var margin = '-' + 95 * index + 'px';
	$('#thumbs_holder').animate({'marginTop': margin}, "slow");

//	current = index;
}

$(document).ready(function(){
	var elem = $('.promo');
	var len = $('.promo').length;
	var thumbsLen = Math.round($('#thumbs_holder a').length / 5);

	if(len > 1)
	{
		function periodic()
		{
			if(current < (len - 1))
			{
				current++;
			}
			else
			{
				current = 0;
			}

			movePanel(current);
		}


		function periodicThumbs()
		{
			if(currentThumbs < thumbsLen)
			{
				moveThumbs(currentThumbs);
				currentThumbs++;
			}
			else
			{
				currentThumbs = 0;
			}
		}

		interval = setInterval(periodic, 3000);
		setInterval(periodicThumbs, 5000);
	}

	$('#thumbs_holder a').mouseover(function(){
		current = $(this).attr('rel') - 1;
		clearInterval(interval);

		var margin = '-' + 475 * current + 'px';
		$('.promo-holder').css({'marginLeft': margin});

//		movePanel(current);
	});

	$('#thumbs_holder a').mouseout(function(){
		interval = setInterval(periodic, 3000);
	});

	if($("#sales").length) $("#sales").tablesorter();

	$('#search_form input').focus(function(){
		$('#bubble').fadeIn(500);
	});
	$('#search_form input').blur(function(){
		$('#bubble').fadeOut(600);
	});

	$('.fade').mouseover(function(){
		$(this).animate({'opacity': 1, '-moz-opacity': 1, '-khtml-opacity': 1, 'filter': 'alpha(opacity=100)'}, "fast");
	});

	$('.fade').mouseout(function(){
		$(this).animate({'opacity': 0.5, '-moz-opacity': 0.5, '-khtml-opacity': 0.5, 'filter': 'alpha(opacity=50)'}, "fast");
	});

//	$('#thumb_holder a').mouseOver
});