/**
	Copyright © Red Orbit
	Author Jerry man 
**/

$(document).ready(function() {
			
	/**
		Slideshow prvi korak
	**/
	
	$("#paging a:first").addClass("active");
		
	var imageWidth = $("#index-banner").width();
	var imageSum = $("#img-big img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	$("#img-big").css({'width' : imageReelWidth});
	
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1; 
		var image_reelPosition = triggerID * imageWidth;

		$("#paging a").removeClass('active');
		$active.addClass('active'); 
		
		$("#img-big").animate({ 
			left: -image_reelPosition
		}, 500 );
		
	}; 
	
	rotateSwitch = function(){		
		play = setInterval(function(){ 
			$active = $('#paging a.active').next();
			if ( $active.length === 0) {
				$active = $('#paging a:first');
			}
			rotate();
		}, 5000);
	};
	
	rotateSwitch();
	
	$("#img-big a").hover(function() {
		clearInterval(play);
	}, function() {
		rotateSwitch();
	});	
	
	$("#paging a").click(function() {	
		$active = $(this);
		
		clearInterval(play);
		rotate();
		rotateSwitch();
		return false;
	});	
	
});
