var animate = {

	num : -1,

	cur : 0,

	cr : [],

	al : null,

	at : 5 * 1000,

	ar : true,
	
	j_img_items : '',
	
	j_nav_items : '',
	
	current_class : '',

	init : function(options) {
		//图片和导航的包装集
		this.j_img_items = options.images ? $(options.images) : $('img.slider');
		this.j_nav_items = options.navs ? $(options.navs) : $('.slider_nav li');
		
		this.current_class = options.current_class;
		
		this.j_img_items.css({position:'absolute'});
		
		this.num = this.j_img_items.length;
		if (!this.num)
			return false;
		
		var pos = Math.floor(Math.random() * 1);
		
		$(this.j_img_items[0]).fadeIn(300);
		
		//绑定click
		this.j_nav_items.each(function(index){
			$(this).click(function(){
				animate.slide(index);
			});
		});
		
		this.on(pos);

		this.cur = pos;

		window.setTimeout('animate.auto();', this.at);

	},

	auto : function() {

		if (!this.ar)
			return false;

		var next = this.cur + 1;

		if (next >= this.num)
			next = 0;

		this.slide(next);

	},

	slide : function(pos) {

		if (pos < 0 || pos >= this.num || pos == this.cur)

			return;

		window.clearTimeout(this.al);

		this.al = window.setTimeout('animate.auto();', this.at);

		this.j_img_items.fadeOut(800);
		$(this.j_img_items[pos]).fadeIn(1000);
			
		this.on(pos);
		
		this.cur = pos;
	},

	on : function(pos) {
		//导航处于当前
		this.j_nav_items.removeClass(this.current_class);
		$(this.j_nav_items[pos]).addClass(this.current_class);

	}

};
