this.slideshow = function(obj) {
		var s = $("li", obj).length;
		var w = obj.width(); 		
		var ts = s-1;
		var intv = 0
		var t = 0;
		$("ul", obj).css("width",s*w);
		$(obj).parent().append("<span class=\"prev\"><a href=\"javascript:void(0);\"></a></span> <span class=\"next\"><a href=\"javascript:void(0);\"></a></span>");
		
		$(".prev a", obj.parent()).hide();
		$("#c1", obj.parent()).click(function(){	
			clearInterval(intv);
			t = 0;
			animate("go");
		});
		$("#c2", obj.parent()).click(function(){	
			clearInterval(intv);
			t = 1;
			animate("go");
		});
		$("#c3", obj.parent()).click(function(){
			clearInterval(intv);		
			t = 2;
			animate("go");
		});
		$("#c4", obj.parent()).click(function(){	
			clearInterval(intv);
			t = 3;
			animate("go");
		});
		$(".next a", obj.parent()).click(function(){	
			clearInterval(intv);
			animate("next");
			if (t>=ts) $(this).fadeOut('slow');
			$(".prev a", obj.parent()).fadeIn();
		});
		$(".prev a", obj.parent()).click(function(){		
			clearInterval(intv);
			animate("prev");
			if (t<=0) $(this).fadeOut('slow');
			$(".next a", obj.parent()).fadeIn();
		});	
		this.ss = function() {
			animate("next");	
		};
		this.animate = function(dir){
			if(dir == "go"){

			}else if(dir == "next"){
				t = (t>=ts) ? ts : t+1;	
			} else {
				t = (t<=0) ? 0 : t-1;
			};		
			p = (t*w*-1);		
			$("ul",obj).animate(
				{ marginLeft: p }, 
				800
			);	
		};
		$(".prev a", obj.parent()).fadeIn();
		intv = setInterval(ss, 10000);
};
this.init = function() {
	$("#templates").each(function(){	
		slideshow($(this));	
	});		
};


$(document).ready(function(){	
	init();
});
