//Designed by DivCsser---Öí¶ù³æµÜµÜ
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function insertAfter(newElement,targetElement) {
  var parent = targetElement.parentNode;
  if (parent.lastChild == targetElement) {
    parent.appendChild(newElement);
  } else {
    parent.insertBefore(newElement,targetElement.nextSibling);
  }
}

function addClass(element,value) {
  if (!element.className) {
    element.className = value;
  } else {
    newClassName = element.className;
    newClassName+= " ";
    newClassName+= value;
    element.className = newClassName;
  }
}



function showSection(id) {
  var divs = document.getElementsByTagName("div");
  for (var i=0; i<divs.length; i++ ) {
    if (divs[i].className.indexOf("section") == -1) continue;
    if (divs[i].getAttribute("id") != id) {
      divs[i].style.display = "none";
    } else {
      divs[i].style.display = "block";
    }
  }
}

function preparetopNav() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("topNav")) return false;
  var nav = document.getElementById("topNav");
  var links = nav.getElementsByTagName("a");
  for (var i=0; i<links.length; i++ ) {
    var sectionId = links[i].getAttribute("href").split("#")[1];
    if (!document.getElementById(sectionId)) continue;
    if(i == 0){
		document.getElementById(sectionId).style.display = "block";
	}
	else{
		document.getElementById(sectionId).style.display = "none";
	}
	links[i].destination = sectionId;
    links[i].onclick = function() {
      showSection(this.destination);
	  fixGototop();
      return false;
    }
  }
}

addLoadEvent(preparetopNav);

function fixGototop(){
	var divs = document.getElementsByTagName("div");
	var width=0.5*(screen.width-720-30);
	//720=Maincontet.width+0.5*banner.width
	//720=636+85
	//30=gototop.a.marginRight
	//var height=screen.height; 	
	//alert(height); 
	//alert(document.body.scrollHeight);
	//alert(document.body.clientHeight);
	//alert(document.body.offsetHeight);
	
  	for (var i=0; i<divs.length; i++ ) {
    
	if (divs[i].className.indexOf("gototop") != -1){
		
		divs[i].style.position="fixed";
		
		divs[i].style.left="auto";
		
		divs[i].style.right= width+"px";
		
		divs[i].style.top= "auto";
		
		divs[i].style.bottom="0px"
		
		//divs[i].style.top= "600px";
		
		//divs[i].style.bottom="auto";
		
		//divs[i].style.border="1px solid #000";
	}
  }
}













