/*
 * Functions to handle adSlider
 */
$(function () {
	$('ul.spy').simpleSpy();
});

(function (a) {
	a.fn.simpleSpy = function(b,c) {
		if( a(this).length === 0 ) {
			return;
		}
		b = b || 2;
		c = c || 9999;
		var d = 250;
		return this.each(function () {
			var g = a(this), h = [], k = 0, i = 0, l = false, e = g.find("> li:first").width(), m = g.find("> li:first").height();
			g.find("> li").each(function() {
				h.push("<li>"+a(this).html()+"</li>");
			});
			i = h.length;
			k = i-1;
			g.wrap('<div class="spyWrapper" />').parent().css({ width: (e*2+16) });
			var f = g.find("li").length;
			function j() {
				var n = a(h[k]).css({ width:0, opacity:0, display:"none" }).prependTo(g);
				g.find("> li:last").animate( { opacity:0 }, d/2, function() {
					n.animate({width:e}, d).animate({opacity:1}, d/2);
					a(this).remove();
				});
				k--;
				if( k < 0) {
					k=i-1;
				}
				if( l!==true ) {
					timer = setTimeout(j,c);
				}
			}
			j();
		});
	};
})(jQuery);
