/*
 *	markup example for $("#images").smslider();
 *	
 * 	<div id="images">
 *		<ul>
 *			<li><img src="images/01.jpg" alt="" /></li>
 *			<li><img src="images/02.jpg" alt="" /></li>
 *			<li><img src="images/03.jpg" alt="" /></li>
 *			<li><img src="images/04.jpg" alt="" /></li>
 *			<li><img src="images/05.jpg" alt="" /></li>
 *		</ul>
 *	</div>
 *
 */

(function($) {

	$.fn.smslider = function(options){
	  
		// default configuration properties
		var defaults = {
			prevId: 		'prevBtn',
			nextId: 		'nextBtn',	
			speed: 			800,
			width:		100			
		}; 
		
		var options = $.extend(defaults, options);  
		
		return this.each(function() {  
			obj = $(this); 
			var s = $("li", obj).length;
			var id = obj.attr("id");			
			var w = obj.width();
			var h = obj.height(); 
			var ts = (Math.ceil(s/Math.ceil(w/options.width)));
			var t = 0;
			
			function rebuild(){
				s=$("#"+id+" li").length;
				ts = (Math.ceil(s/Math.ceil(w/options.width)));
				$("#"+id+" ul").css('width',ts*w);
			}
			
			
			$("#"+options.nextId+" a").hide();
			$("#"+options.prevId+" a").hide();
			
			if(ts>1) $("#"+options.nextId+" a").show();
			
			$("#"+options.nextId+" a").live('click', function(event) {
				rebuild();
				animate("next");
			});
			$("#"+options.prevId+" a").live('click', function(event) {
				rebuild();
				animate("prev");
			});			
			
			function animate(dir){				
				if(dir == "next"){
					t = (t>=(ts-1)) ? (ts-1) : t+1;	
				} else {
					t = (t<=0) ? 0 : t-1;
				}
				p = (t*w*-1);
				$("#"+id+" ul").animate(
					{ marginLeft: p }, 
					options.speed
				);

				if(t>0){
					$("#"+options.prevId+" a").fadeIn();
				}else{
					$("#"+options.prevId+" a").fadeOut();
				}
				
				if((t+1)<ts){
					$("#"+options.nextId+" a").fadeIn();
				}else{
					$("#"+options.nextId+" a").fadeOut();
				}

			}
		});
	  
	};

})(jQuery);

(function($) {

	$.fn.smproductslider = function(options){
	  
		// default configuration properties
		var defaults = {
			prevId: 		'previous',
			nextId: 		'next',	
			speed: 			800,
			increment:		680,
			maxscreens:		1			
		}; 
		
		var options = $.extend(defaults, options);  
		
		return this.each(function() {  
			obj = $(this); 
			// obj #slideproductlist
			
			var screen = 0;
			
			$("a#"+options.nextId).hide();
			$("a#"+options.prevId).hide();
			
			if(options.maxscreens>1) $("a#"+options.nextId).show();
			
			$("#"+options.nextId).live('click', function(event) {
				animate("next");
			});
			$("#"+options.prevId).live('click', function(event) {
				animate("prev");
			});			
			
			function animate(dir){				
				if(dir == "next"){
					if(screen<(options.maxscreens-1)){
						// go next
						
						screen++;
					}	
				} else {
					if(screen>0){
						// go prev
						
						screen--;
					}
				}
				p = (screen*options.increment*-1);
				obj.animate(
					{ marginLeft: p }, 
					options.speed
				);

				if(screen>0){
					$("a#"+options.prevId).fadeIn();
				}else{
					$("a#"+options.prevId).fadeOut();
				}
				
				if(screen<(options.maxscreens-1)){
					$("a#"+options.nextId).fadeIn();
				}else{
					$("a#"+options.nextId).fadeOut();
				}
			}			
		});
	  
	};

})(jQuery);
