/**
 * Baseado no slider
 * http://www.sohtanaka.com/web-design/automatic-image-slider-w-css-jquery/
 * Modificador e adaptado por: frederico.vieira@gmail.com
 * Data: 02/12/2010
 */

$(document).ready(function() {
      
	/*start = function() {*/
	$(".paging").show();
	$(".paging a:first").addClass("active");

	var imageHeight = $(".window img").height();
	var imageWidth = $(".image_reel img").width();
	var screenWidth = $("#principal").width()
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = screenWidth * imageSum;
      
	$(".image_reel").css({'width' : imageReelWidth});
	$(".image_reel").css({'height' : imageHeight});
	$(".window").css({'height' : imageHeight});
	$(".window").css({'width' : $(this).width()});
      
	$(".image_reel div").css({'width' : screenWidth});
	
	var lefPos = (screenWidth - imageWidth) / 2;
	$(".image_reel img").css({'margin-left' : (lefPos >= 0 ? lefPos : 0)});
      
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1;
		var image_reelPosition = triggerID * screenWidth;
		
		$(".paging a").removeClass('active');
		$active.addClass('active');
		
		$(".image_reel").animate({ 
			left: -image_reelPosition
		}, 500 );
	}; 
      
	rotateSwitch = function(){		
		play = setInterval(function() {
			$active = $('.paging a.active').next();
			if ($active.length === 0) {
				$active = $('.paging a:first');
			}
			rotate();
		}, 7000);
	};
      
	rotateSwitch();
      
	$(".image_reel a").hover(function() {
		clearInterval(play);
	}, function() {
		rotateSwitch();
	});	
      
	$(".paging a").click(function() {	
		$active = $(this);
		clearInterval(play);
		rotate();
		rotateSwitch();
		return false;
	});
	/*};
	
	start();
	
	$(window).resize(function() {
		clearInterval(play);
		start();
	});*/
});
