﻿function Num$(id) { return document.getElementById(id); } 


/* slide show */ 
function addBtn() {
	if(!Num$('focus')||!Num$('focus_pic')) return;
	var picList = Num$('focus_pic').getElementsByTagName('a');
	if(picList.length==0) return;
	var btnBox = document.createElement('div');
	btnBox.setAttribute('id','focus_btn');
	var SpanBox ='';
	for(var i=1; i<=picList.length; i++ ) {
		var spanList = '<span class="normal">'+i+'</span>';
		SpanBox += spanList;
	}
	btnBox.innerHTML = SpanBox;
	Num$('focus').appendChild(btnBox);
	Num$('focus_btn').getElementsByTagName('span')[0].className = 'current';
	for (var m=0; m<picList.length; m++){
		var attributeValue = 'picLi_'+m
		picList[m].setAttribute('id',attributeValue);
	}
}
function classNormal() {
	var btnList = Num$('focus_btn').getElementsByTagName('span');
	for (var i=0; i<btnList.length; i++){
		btnList[i].className='normal';
	}
}
function picZ() {
	var picList = Num$('focus_pic').getElementsByTagName('a');
	for (var i=0; i<picList.length; i++){
		picList[i].style.zIndex='1';
	}
}
var autoKey = false;
function focus() {
	if(!Num$('focus')||!Num$('focus_pic')||!Num$('focus_btn')) return;
	Num$('focus').onclick = function(){autoKey = true};
	Num$('focus').onclick = function(){autoKey = false};
	var btnList = Num$('focus_btn').getElementsByTagName('span');
	var picList = Num$('focus_pic').getElementsByTagName('a');
	if (picList.length==1) return;
	picList[0].style.zIndex='2';
	for (var m=0; m<btnList.length; m++){
		btnList[m].onclick = function() {
			for(var n=0; n<btnList.length; n++) {
				if (btnList[n].className == 'current') {
					var currentNum = n;
				}
			}
			classNormal();
			picZ();
			this.className='current';
			picList[currentNum].style.zIndex='2';
			var z = this.childNodes[0].nodeValue-1;
			picList[z].style.zIndex='3';
			if (currentNum!=z){
				picList[z].style.top='0';
			}
		}
	}
}
setInterval('autoBanner()', 9000);
function autoBanner() {
	if(!Num$('focus')||!Num$('focus_pic')||!Num$('focus_btn')||autoKey) return;
	var btnList = Num$('focus_btn').getElementsByTagName('span');
	var picList = Num$('focus_pic').getElementsByTagName('a');
	if (picList.length==1) return;
	for(var i=0; i<btnList.length; i++) {
		if (btnList[i].className == 'current') {
			var currentNum = i;
		}
	}
	if (currentNum==(picList.length-1) ){
		classNormal();
		picZ();
		btnList[0].className='current';
		picList[currentNum].style.zIndex='2';
		picList[0].style.zIndex='3';
		picList[0].style.top='0';
	} else {
		classNormal();
		picZ();
		var nextNum = currentNum+1;
		btnList[nextNum].className='current';
		picList[currentNum].style.zIndex='2';
		picList[nextNum].style.zIndex='3';
		picList[nextNum].style.top='0';
	}
}




