/** 
 * -------------------------------------- 
 * KRIACAO
 * @file: GENERIC JS FUNCTIONS
 * @author: João
 * @date: 14-09-2011
 *
 * --------------------------------------
*/


jQuery(function () {

/*	function setupHorizontalScroll(amount, time) {
		jQuery('.promoItemScroller').css('left', 0);
		jQuery('.promoItemScroller').stop().animate({ left: -amount }, time, 'linear');
	}

	jQuery(function () {

		var duration = 50000;
		var scrollAmount = jQuery('.promoItemScroller').width();



		// iniciar logo a animação
		jQuery('.promoItemScroller').css('left', 0);
		jQuery('.promoItemScroller').stop().animate({ left: -scrollAmount }, duration, 'linear');
		jQuery(document).everyTime(duration, function () {
			setupHorizontalScroll(scrollAmount, duration);
		});

	});
*/



	var index = 0;
	
	var move_right = 1;
	
	var num = jQuery('.promocaoItem').size() - 1;
	
	jQuery('.promocaoBtnLeft').css('cursor', 'default');
	jQuery('.promocaoBtnLeft').css('background-image', 'none');
	
	jQuery('.logo').each(function () {
		if(num <= 0)
		{
			jQuery('.promocaoBtnRight').hide();
			jQuery('.promocaoBtnLeft').css('cursor', 'default');
			jQuery('.promocaoBtnLeft').css('background-image', 'none');
		}
	});
	
	jQuery('.promocaoBtnRight').click(function() {
		if(index != num)
		{
			index = index + 1;
		}
		if(index == num)
		{
			jQuery('.promocaoBtnRight').hide();
			move_right = 0;
		}
		if(index > 0)
		{
			jQuery('.promocaoBtnLeft').css('cursor', 'pointer');
			jQuery('.promocaoBtnLeft').css('background-image', 'url(/image/leftreserv.png)');
		}
		
		var value = index * (-377);
		jQuery('.promoItemScroller').stop().animate({
			left: value
		});
	}, 350, jQuery.easing.def);
		
	jQuery('.promocaoBtnLeft').click(function() {
		if(index != 0)
		{
			index = index - 1;
		}
		if(index == num-1)
		{
			jQuery('.promocaoBtnRight').show();
		}
		if(index == 0)
		{
			jQuery('.promocaoBtnLeft').css('cursor', 'default');
			jQuery('.promocaoBtnLeft').css('background-image', 'none');
			move_right = 1;
		}
		
		var value = index * (-377);
		jQuery('.promoItemScroller').stop().animate({
			left: value
		});
	}, 350, jQuery.easing.def);

	
	jQuery('.logo').everyTime('10s', function() {
		
		if(move_right == 1)
		{
			if(index != num)
			{
				index = index + 1;
			}
			if(index == num)
			{
				jQuery('.promocaoBtnRight').hide();
				move_right = 0;
			}
			if(index > 0)
			{
				jQuery('.promocaoBtnLeft').css('cursor', 'pointer');
				jQuery('.promocaoBtnLeft').css('background-image', 'url(/image/leftreserv.png)');
			}
		}
		else
		{
			if(index != 0)
			{
				index = index - 1;
			}
			if(index == num-1)
			{
				jQuery('.promocaoBtnRight').show();
			}
			if(index == 0)
			{
				jQuery('.promocaoBtnLeft').css('cursor', 'default');
				jQuery('.promocaoBtnLeft').css('background-image', 'none');
				move_right = 1;
			}
		}
	
		var value = index * (-377);
		jQuery('.promoItemScroller').stop().animate({
			left: value
		});
	}, 350, jQuery.easing.def);

});
