/*
 * 	Easy Slider - jQuery plugin
 *
 *	Built for jQuery library
 *	http://jquery.com
 *  Further edited by wyemun.
 *  Notes: 	- i replaced "li" with ".sliderli" and "ul" with "#slideril"
 *  		to avoid conflicts for sub listings in "portfolio", take note that i also replace
 *			corresponding styles in css.
 *		   	- I also added more buttons and pages (5 in total)
 *			- easing available
 *	
 *	referred to Easy Slider - jQuery plugin written by Alen Grakalic	
 *	http://cssglobe.com/post/3783/jquery-plugin-easy-image-or-content-slider-
 */
 
/*
 *	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.easySlider = function(options){
	  
		// default configuration properties
		var defaults = {
			prevId: 		'prevBtn',
			prevText: 		'Previous',
			nextId: 		'nextBtn',	
			nextText: 		'Next',
			homeId:			'homeBtn',
			homeText:		'Home',
			page2Id:		'page2Btn',
			page2Text:		'Page2',
			page3Id:		'page3Btn',
			page3Text:		'Page3',
			orientation:	'', //  'vertical' is optional;
			speed: 			1200,
			easing:			'swing'
		}; 
		
		var options = $.extend(defaults, options);  
		
		return this.each(function() {  
			obj = $(this); 				
			var s = $(".sliderli", obj).length;
			var w = 800; 
			var h = obj.height(); 
			var ts = s-1;
			var t = 0;
			var vertical = (options.orientation == 'vertical');
			$("#sliderul", obj).css('width',s*w);			
			if(!vertical) $(".sliderli", obj).css('float','left');
			
	
			
			//Setting the buttons
				//Next Btn
			$("a","#"+options.nextId).click(function(){		
				animate("next");
			});
				// Prev Btn
			$("a","#"+options.prevId).click(function(){		
				animate("prev");
			});	
				// Home Btn
			$("a","#"+options.homeId).click(function(){		
				animate("home");
			});	
				// Page2 Btn
			$("a","#"+options.page2Id).click(function(){		
				animate("page2");
			});	
				// Page3 Btn
			$("a","#"+options.page3Id).click(function(){		
				animate("page3");
			});	
			// Animation function
			function animate(dir){
				if(dir == "next"){
					t = (t>=ts) ? ts : t+1;	
				} else if(dir== "prev"){
					t = (t<=0) ? 0 : t-1;
				} else if(dir== "home"){
					t = (t==0) ? 0 : 0; 
				} else if(dir== "page2"){
					t = (t==2) ? 2 : 2; 
				} else if(dir== "page3"){
					t = (t==4) ? 4 : 4;
				};								
				if(!vertical) {
					p = (t*w*-1);
					$("#sliderul",obj).stop().animate(
						{ marginLeft: p}, 
						options.speed,
						options.easing
					);				
				} else {
					p = (t*h*-1);
					$("#sliderul",obj).stop().animate(
						{ marginTop: p}, 
						options.speed,
						options.easing
					);					
				}
			};
		});
	  
	};

})(jQuery);