/*
 * 	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($j) {

	$.fn.easySlider = function(options){
	  
		// default configuration properties
		var defaults = {
			prevId: 		'prevBtn',
			prevText: 		'Previous',
			nextId: 		'nextBtn',	
			nextText: 		'Next',
			orientation:	'', //  'vertical' is optional;
			speed: 			800			
		}; 
		
		var options = $j.extend(defaults, options);  
		
		return this.each(function() {  
			obj = $j(this); 				
			var s = $j("li", obj).length;
			var w = obj.width();
			//alert(w); 
			var h = obj.height(); 
			var ts = s-5;
			var t = 0;
			var x = 0;
			var vertical = (options.orientation == 'vertical');
			if($j("ul", obj).css('width',s*131)<624)
			{
				$j("ul", obj).css('width',624);
			}
			else
			{
			$j("ul", obj).css('width',s*131);	
			}		
			if(!vertical) $j("li", obj).css('float','left');
			$j(obj).after('<div id="'+ options.prevId +'"><a href=\"javascript:void(0);\"></a></div> <div id="'+ options.nextId +'"><a href=\"javascript:void(0);\"></a></div>');		
			//$j("div","#"+options.prevId).hide();
			//$j("div","#"+options.nextId).hide();
			$j("#nextBtn>a").click(function(){
				//alert("hello");
				if(s>5)
				{		
				animate("next");
				}
				/*if (t>=ts) $(this).fadeOut();
				$j("a","#"+options.prevId).fadeIn();*/
			});
			$j("#prevBtn>a").click(function(){	
				//alert("hello");	
				animate("prev");
			/*	if (t<=0) $(this).fadeOut();
				$j("a","#"+options.nextId).fadeIn();*/
			});
			$j("ul.futo").hover(function(){
				var mar=$j(this).css('margin-left');
				var marstr="-"+ts*131+"px";
				//alert(marstr);
				if(s>5)
				{
					if($j(this).css('margin-left')==marstr)
					{
						animate("prev");
					}
					else{
						animate("next");
					}
				}
				});	
			function animate(dir){
				if(dir == "next"){
					t = (t>=ts) ? ts : t+1;
						
				} else {
					t = (t<=0) ? 0 : t-1;
					
				};								
				if(!vertical) {
					p = (t*131*-1);
					$j("ul",obj).animate(
						{ marginLeft: p }, 
						options.speed
					);				
				} else {
					p = (t*h*-1);
					$j("ul",obj).animate(
						{ marginTop: p }, 
						options.speed
					);					
				}
				
			};
			if(s>1) $j("a","#"+options.nextId).fadeIn();	
		});
	  
	};

})(jQuery);

