/**
 * author:	Cecil Heng
 * date:	2009-7-13
 * info:	广告切换
 *
 */

var Switch = {
	time : 3000,
	max_num : 0,
	cur_num : 1,
	refreshTimer : null,
	pause:function(){
		clearTimeout(this.refreshTimer);
	},
	start:function(){
		this.refreshTimer = setTimeout('Switch.selected();', this.time);
	},
	init:function(num){
		if(num == null || num <= 0)	return false;
		this.max_num = num;
		Switch.draw();
		Switch.start();
	},
	selected:function(id){
		Switch.pause();
		this.cur_num = id || this.cur_num;
		Switch.draw();
		this.refreshTimer = setTimeout('Switch.selected();', this.time);
	},
	draw:function(){
		var objs = document.getElementById('menus');
		var dom = objs.getElementsByTagName('li');
		var cur_id = this.cur_num;
		for(var i=0;i<dom.length;i++){
			if( i + 1 <= dom.length - this.max_num ){
				continue;
			}else if( ( (cur_id - 1) + (dom.length - this.max_num) ) == i ){
				dom[i].className = "menu_bj";
				document.getElementById('int_img_id').innerHTML = '';
				var a = document.createElement("a");
				a.target = "_blank";
				a.href = Switcher[cur_id]['link'];
				var img = document.createElement("img");
				img.src = Switcher[cur_id]['img'];
				img.border = 0;
				img.width = 470;
				img.height = 200;
				a.appendChild(img);
				document.getElementById('int_img_id').appendChild(a);
			}else{
				dom[i].className = "";
			}
		}
		if( this.cur_num >= this.max_num ){
			this.cur_num = 1;
		}else{
			this.cur_num += 1;
		}
	}
}