/*
 * 	Easy Slider - jQuery plugin
 *	written by Alen Grakalic	
 *	http://cssglobe.com/post/3783/jquery-plugin-easy-image-or-content-slider
 *
 *	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
 
/*
 *	markup example for $("#images").easySlider();
 *	
 * 	<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.easySlider2 = function(options){
	  
		// default configuration properties
		var defaults2 = {
			
			prevText: 		'testo',	
			nextText: 		'',
			orientation:	'', //  'vertical' is optional;
			speed: 			800		
		}; 
		
		var options = $.extend(defaults2, options);  
		
		return this.each(function() {  
			obj2 = $(this);
			var s2 = $("li", obj2).length;
			var w2 = $("li", obj2).width();
			var h2 = $("li", obj2).height();
			var ts2 = s2-1;
			var t2 = 0;
			var vertical2 = (options.orientation2 == 'vertical');
			$("ul", obj2).css('width',s2*w2);			
			if(!vertical2) $("li", obj2).css('float','left');
			//$(obj).after('<span id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span> <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>');		
			$("a","#"+options.prevId2).hide();
			$("a","#"+options.nextId2).hide();
			$("a","#"+options.nextId2).click(function(){		
				animate("next");
				if (t2>=ts2) $(this).fadeOut();
				$("a","#"+options.prevId2).fadeIn();
			});
			$("a","#"+options.prevId2).click(function(){		
				animate("prev");
				if (t2<=0) $(this).fadeOut();
				$("a","#"+options.nextId2).fadeIn();
			});	
			function animate(dir2){
				if(dir2 == "next"){
					t2 = (t2>=ts2) ? ts2 : t2+1;	
				} else {
					t2 = (t2<=0) ? 0 : t2-1;
				};								
				if(!vertical2) {
					p2 = (t2*w2*-1);
					$("ul",obj2).animate(
						{ marginLeft: p2 }, 
						options.speed
					);				
				} else {
					p2 = (t2*h2*-1);
					$("ul",obj2).animate(
						{ marginTop: p2 }, 
						options.speed
					);					
				}
			};
			if(s2>1) $("a","#"+options.nextId2).fadeIn();	
		});
	  
	};

})(jQuery);
