//Slider
(function($) {//Start closure //
	$.fn.slider = function(params) {
		//Set defaul params------------------------//
		var defaults = {
			interval:1000,
			animationspeed:500,
			move:100,
		}
		opts = $.extend(defaults, params);
		//-----------------------------------------//
		var div = $(this)
		i=1;
		total_img = $(this).find('img').length;
		if(total_img > 1)
		{
			$(this).html(create_html(div));
			var slide_timer = setInterval(loop, opts.interval, div);
		}
		return false;
	};
	
	function loop(div)
	{
		if(i < total_img)
		{
			div.find('.slider').stop().animate({'margin-left':'-='+opts.move+'px'},opts.animationspeed)
//			div.find('.slider').stop().animate({'margin-left':'-100px'},opts.animationspeed)
		}
		if(i == total_img)
		{
			div.find('.slider').stop().animate({'margin-left':'0px'},opts.animationspeed)
			i=0;
		}
		i++;
	}
	
	function create_html(div)
	{
		var html = '<div class="slider" style="width:9999999px; height:auto; float:left;">'
		div.find('img').each(function(){
			var src = $(this).attr('src');	
			html+= '<img src="'+src+'" />'
		})
		html+= '</div>'
		return html;
	}
		
})(jQuery);//End closure

