
window.onload = function() {
	initTab();
};
var getElementsByClassName = function(className, tag, elm){
	var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}
var initTab = function(){
	var togglers = getElementsByClassName("toggler");
	var tab_content = getElementsByClassName("tab_content");
	var length = tab_content.length;
	var togglersLen = togglers.length;
	var slectedNum = 0;
	var anc = location.hash;
	var anc2 = anc.slice(1);
	var anc_array = new Array();
	if(length>1&&togglersLen>1){
		for(var i = 0; i < length; i++){
			//togglers[i].firstChild.removeAttribute("href");
			togglers[i].no = i;
			togglers[i].onclick = function(){
				if(this.no != slectedNum){
					togglers[slectedNum].firstChild.style.backgroundPosition = "0 0";
					tab_content[slectedNum].style.display = "none";
					
					slectedNum = this.no;
					location.hash = "#"+anc_array[slectedNum];
					
					togglers[slectedNum].firstChild.style.backgroundPosition = "0 100px";
					tab_content[slectedNum].style.display = "block";
				}
				return false;
			}
			togglers[i].onmouseover = function(){
				if(this.no != slectedNum){
					this.firstChild.style.backgroundPosition = "0 100px";
				}
			}
			togglers[i].onmouseout = function(){
				if(this.no != slectedNum){
					this.firstChild.style.backgroundPosition = "0 0";
				}
			}
			tab_content[i].style.display = "none";
			anc_array.push(tab_content[i].id);
			
			
			
			if(tab_content[i].id == anc2){
				slectedNum = i;
			}
			tab_content[0].style.display = "block";
			togglers[0].firstChild.style.backgroundPosition = "0 100px";
			
			tab_content[i].id = null;
		}
		if(anc!=""){
			var obj = tab_content[slectedNum];
			obj.style.display = "block";
			togglers[slectedNum].firstChild.style.backgroundPosition = "0 100px";
			togglers[0].firstChild.style.backgroundPosition = "0 0"
			tab_content[0].style.display = "none";
			
			obj.style.display = "block";
			
			window.scrollBy(0, 0);
			return false;
			
		}else{
			var obj = tab_content[0];
			obj.style.display = "block";

			togglers[0].firstChild.style.backgroundPosition = "0 100px"
			slectedNum = 0;
			
		}
	}
}
