/**
 * 
 */
(function($) {                                          
$.fn.carousel_const = function(all_width) {
    var wrapper = $('> div', this);
    //wrapper.after('<a href="#" class="arrow back">&lt;</a><a href="#" class="arrow forward">&gt;</a>');
    slider = wrapper.find('> div');
	carousel = slider.children();
	count_img = carousel.size();
	width_img = carousel.width();
	//slider.width(all_width);//count_img*width_img);
	var shift = 0;
	max_left = all_width - width_img;
	//max_left = width_img*count_img - width_img;
	//$('.back', this).bind('click', stop_right);
	//$('.forward', this).bind('click', stop_left);
	
	var interval = setInterval(go_left, 20);
	
	wrapper.hover(
		function(){
			clearInterval(interval);
		}
		, 
		function(){
			interval = setInterval(go_left, 20);
		}
	);
	return carousel.each(function(){
		$(this).css({'left':shift});
		shift += $(this).width();
		//shift += width_img;
	});
	/*function stop_left() {
		clearInterval(interval);
		interval = setInterval(go_right, 100);	
	}
	function stop_right() {
		clearInterval(interval);
		interval = setInterval(go_left, 100);	
	}*/
	function go_left() {
		carousel.each(function(){
			left = $(this).css('left');
			left = left.slice(0, left.length-2)-1;
			if(left < -width_img)
				//left=count_img*width_img +left;
				left=all_width +left;
			$(this).css({'left': left+'px'});
		});
		
	}
	
	function go_right() {
		carousel.each(function(){
			left = $(this).css('left');
			left = left.slice(0, left.length-2);
			left++;
			if(left > max_left)
				left= -width_img;
			$(this).css({'left': left+'px'});
		});
	}
};
})(jQuery);
