/**
 * 页面初始化时，显示图片
 */
XN.dom.ready(function(){
	var list, list_a, list_img;
	var pic;
	pic = $("current_a");
	list = $("img_list");
	list_a = list.getElementsByTagName("a");
	list_img = list.getElementsByTagName("img");
	//获取图片列表 img_list
	//生成按钮 img_button
	var bar = $("bar");
	for(var i = 0 ; i<list_a.length; i++)
	{
		n_li = document.createElement("li");
		n_li.innerHTML = "<a class=\"wait\" onmouseover=\"select("+i+")\" onmouseout=\"goon()\">"+(i+1)+"</a>";
		bar.appendChild(n_li);
	}
	
	list_button = bar.getElementsByTagName("a");
	theInt = null;	//设为全局
	current = 0;	//设为全局
	
	/**
	 * 设置当前的图片为第n张，原有的图片设为wait
	 */
	set_current = function(n)
	{
		pic.setAttribute("href", list_a[n].href);						
		pic.innerHTML = "<img src=\""+ list_img[n].src +"\" width=\"735\" height=\"320\" />" ;
		list_button[current].setAttribute("class", "wait");
		list_button[n].setAttribute("class", "current");
		list_button[current].setAttribute("className", "wait");
		list_button[n].setAttribute("className", "current");
		current = n;
	}
	
	/**
	 * 选择图片，并显示已选图片
	 */
	select = function(n)
	{
		clearInterval(theInt);
		set_current(n);
	}
	
	/**
	 * 切换到下一张图片
	 * */
	next = function()
	{
		n = (current+1) % list_a.length;
		set_current(n);
	}
	
	/**
	 * 鼠标移出，自动切换图片
	 */
	goon = function()
	{
		theInt = setInterval(next, 4500);
	}
	
	set_current(0);
	goon();
});

