(function($) {
	$.fn.cycle_prod = function(options){
		var defaults = {
			elementContainer: '.scroll_holder',
			prevElement: '.scroll .scroller_left',
			nextElement: '.scroll .scroller_right',
			speed: 290,
			showCount: 5
		};
		
		var options = $.extend(defaults, options);  
				
		this.each(function() {

			var totalElements = $(this).find("li");
			var maxIndex = totalElements.length - 1;
			
			var startIndex = -1;
			var elementWidth = $(this).find("li").outerWidth(true);
			var margin = ((startIndex + 1) * elementWidth) * -1;
			var lowerIndex = startIndex + 1;
			var upperIndex = startIndex + options.showCount;
			var parent = $(this);
			
			$(this).find(options.elementContainer).css({
				'width': (options.containerWidth) ? options.containerWidth : elementWidth * options.showCount,
				'overflow': 'hidden'
			});
			$(this).find("ul").css({
				'width': (maxIndex + 1) * elementWidth,
				'padding': '0'
			});
			
			cycle("load");
			
			$(options.nextElement).click(function(){ cycle("next"); return false; });
			$(options.prevElement).click(function(){ cycle("prev"); return false; });	
			
			function cycle(dir){			
				switch(dir){
					case "next":
						if(upperIndex <= maxIndex) {
							$(options.prevElement).show();
							margin = margin - elementWidth;
							upperIndex = upperIndex + 1;
							lowerIndex = lowerIndex + 1;
							$("ul",parent).animate({
									marginLeft: margin
								},options.speed);
								
							if((upperIndex + 1) > maxIndex) {
								$(options.nextElement).hide();
							}
						}					
						break;	
					case "prev":
						if(lowerIndex >= 0) {
							$(options.nextElement).show();	
							upperIndex = upperIndex - 1;
							lowerIndex = lowerIndex - 1;
							margin = margin + elementWidth;
							$("ul",parent).animate({
								marginLeft: margin
							}, options.speed);
							if((lowerIndex-1) < 0) {
								$(options.prevElement).hide();
							}
						}
						break;
						
					case "load": {
						$("ul",parent).animate({
							marginLeft: margin
						}, options.speed);
						break;
					}
					default:
						break; 
				};													
			};
		}); 
	};
})(jQuery);

(function($) {
	$.fn.cycle_prod_big = function(options){
		var defaults = {
			elementContainer: '.products',
			prevElement: '.special .scroller_left',
			nextElement: '.special .scroller_right',
			speed: 290,
			showCount: 3
		};
		
		var options = $.extend(defaults, options);  
				
		this.each(function() {

			var totalElements = $(this).find("li");
			var maxIndex = totalElements.length - 1;
			
			var startIndex = -1;
			var elementWidth = $(this).find("li").outerWidth(true);
			var margin = ((startIndex + 1) * elementWidth) * -1;
			var lowerIndex = startIndex + 1;
			var upperIndex = startIndex + options.showCount;
			var parent = $(this);
			
			$(this).find(options.elementContainer).css({
				'width': (options.containerWidth) ? options.containerWidth : elementWidth * options.showCount,
				'overflow': 'hidden'
			});
			$(this).find("ul").css({
				'width': (maxIndex + 1) * elementWidth,
				'padding': '0'
			});
			
			cycle("load");
			
			$(options.nextElement).click(function(){ cycle("next"); return false; });
			$(options.prevElement).click(function(){ cycle("prev"); return false; });	
			
			function cycle(dir){			
				switch(dir){
					case "next":
						if(upperIndex <= maxIndex) {
							$(options.prevElement).show();
							margin = margin - elementWidth;
							upperIndex = upperIndex + 1;
							lowerIndex = lowerIndex + 1;
							$("ul",parent).animate({
									marginLeft: margin
								},options.speed);
								
							if((upperIndex + 1) > maxIndex) {
								$(options.nextElement).hide();
							}
						}					
						break;	
					case "prev":
						if(lowerIndex >= 0) {
							$(options.nextElement).show();	
							upperIndex = upperIndex - 1;
							lowerIndex = lowerIndex - 1;
							margin = margin + elementWidth;
							$("ul",parent).animate({
								marginLeft: margin
							}, options.speed);
							if((lowerIndex-1) < 0) {
								$(options.prevElement).hide();
							}
						}
						break;
						
					case "load": {
						$("ul",parent).animate({
							marginLeft: margin
						}, options.speed);
						break;
					}
					default:
						break; 
				};													
			};
		}); 
	};
})(jQuery);