/*
 * 	Easy Slider 1.5 - jQuery plugin
 *	written by Alen Grakalic	
 *	http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding
 *
 *	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
 *
 */

	

(function($) {
		
	$.fn.headerSlider = function(options){
	 

		// default configuration properties
		var defaults = {			
			controlsShow:	true,
			controlsBefore:	'',
			controlsAfter:	'',	
			controlsFade:	true,
			firstId: 		'firstBtn',
			secondId:       'secondBtn',
			thirdId: 		'thirdBtn',   				
			vertical:		false,
			speed: 			800,
			auto:			false,
			pause:			2000,
			continuous:		false
		}; 
		
		var options = $.extend(defaults, options);  
				
		this.each(function() {  
			
			var obj = $(this); 				
			var s = $("li", obj).length;
			var w = $("li", obj).width(); 
			var h = $("li", obj).height(); 
			obj.width(w); 
			obj.height(h); 
			obj.css("overflow","hidden");
			var t = 0;
			$("ul", obj).css('width',s*w);	
			$("li", obj).css('float','left');

			
			$("a","#"+options.firstId).click(function(){		
				animate("first",true);
			});
			$("a","#"+options.secondId).click(function(){		
				animate("second",true);				
			});	
			$("a","#"+options.thirdId).click(function(){		
				animate("third",true);
			});				
			
			$(window).load(function(){		
				animate("first",false);		
			});
			
			function animate(dir,clicked){
				document.getElementById("slider").style.visibility = "visible";
				
				var ot = t;				
				switch(dir){
					case "first":						
						t = 1;
						break; 
					case "second":
						t = 2;
						break; 
					case "third":
						t = 3;
						break; 
					default:
						break; 
				};	
				
			
				var diff = Math.abs(ot-t);
				var speed = diff*options.speed;						
				p = (t*w*-1);
				$("ul",obj).animate(
						{ marginLeft: p }, 
						speed
					);				
				
				if(clicked) clearTimeout(timeout);
				if(options.auto && dir=="next" && !clicked){;
						timeout = setTimeout(function(){
						animate("next",false);
					},diff*options.speed+options.pause);
				};
				
				
				
			};
		
		});
	  
	};

})(jQuery);



