/*
 * 	Simple Slider 0.1 - jQuery plugin
 *	written by Chellen Wong
 *	http://xx
 *
 *	Copyright (c) 2009 Chellen Wong
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *  and use easing - jQuery plugin
 */
 
/*  script:
 *	$("#slider").simpleSlider();
 *  $("#photo-news").sampleSlider({
 *      auto: true,
 *      continuous: true,
 *      numeric: true,
 *      vertical: true,
 *      pause:3000,
 *      easing: "easeInOutBack"
 *  });
 *	
 *  html
 * 	<div id="slider">
 *		<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.sampleSlider = function(options){
	  
		// default configuration properties
		var defaults = {
			numeric: 		false,
			numericId: 		'controls',
			firstId: 		'firstBtn',		
			vertical:		false,
			speed: 			400,
			auto:			true,
			pause:			3000
			//easing:			'easeOutQuad'
		}; 
		
		var options = $.extend(defaults, options);  
				
		this.each(function() {  
			var obj = $(this); 				
			var length = $('li', obj).length;
			var width = obj.find('img:first').width(); 
			var height = obj.find('img:first').height();
			var d;
			var v;
			obj.css({'position':'relative','overflow':'hidden'});
			obj.children('ul').css('position','absolute');
			if (options.vertical){
				obj.find('li').css({'display':'block','width':width,"height":height,'overflow':'hidden'});
			} else {				
				$("ul", obj).css('width',width*length);
				obj.find('li').css({'float':'left','width':width,'height':height});
			}
			if(options.numeric){
				var html = '<ol id="'+ options.numericId +'"></ol>';					
				$(obj).append(html);
				for(var i=0;i<length;i++){						
					$('<li></li>')
						.attr('id',options.numericId + (i+1))
						.html('<a rel='+ i +' href=\"javascript:void(0);\">'+ (i+1) +'</a>')
						.appendTo($("#"+ options.numericId))
						.mouseover(function(){
							index  = $('#'+options.numericId +' li').index(this);
							next(index);
						});	
				};
			}

			$('li', obj).hover(function(){
				  if(timeout){
					 clearInterval(timeout);
				  }
			 },function(){
				  timeout = setInterval(function(){
					next(index)
					index++;
					if(index==length){index=0;}
				  } , options.pause);
			 });
			
			function next(i){
				if (options.vertical){
					obj.children('ul').stop(true,false).animate({'top': -height*i+'px'},{duration: options.speed//,easing: options.easing
					});					
				} else {
					obj.children('ul').stop(true,false).animate({'left': -width*i+'px'},{duration: options.speed//,easing: options.easing
					});
				}
				$('#'+options.numericId +' li')
					.eq(i).addClass('current')
					.siblings().removeClass('current');
			}
			// init
			var index = 1;
			$('#'+options.numericId +' li:first').addClass('current')
			var timeout = setInterval(function(){
				next(index)
				index++;
				if(index==length){index=0;}
			 } , options.pause);			
					
			
		});
	  
	};

})(jQuery);



