﻿
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
	window.onload = func;
  } else {
	window.onload = function() {
	  oldonload();
	  func();
	}
  }
}

function autoResize(i){
	var iframeHeight=(i).contentWindow.document.body.scrollHeight;
	(i).height=iframeHeight+20;
}

function familySite02() {
	if(!document.getElementById || !document.getElementsByTagName) return false;
	if (!document.getElementById("footerSelect")) return false;
	var footerSelect = document.getElementById("footerSelect"); 
	var footerSelectUl = footerSelect.getElementsByTagName("ul");
	var footerSelectLi = footerSelectUl[0].getElementsByTagName("li");
	
	footerSelectUl[0].onclick = function(){
		if(footerSelectUl[1].style.display == "block") {
			footerSelectUl[1].style.display = "none"; 
		} else {
			footerSelectUl[1].style.display = "block";
			footerSelectUl[1].style.top = -110 + "px"

			var footerSelectLi02 = footerSelectUl[1].getElementsByTagName("li");
			var footerSelectLi02_count = footerSelectLi02.length;
			

			for(i = 0; i < footerSelectLi02_count; i++) {
				footerSelectLi02[i].onmouseover = function() {
					this.style.background = "#ebebeb";
				}

				footerSelectLi02[i].onmouseout = function() {
					this.style.background = "#fff";
				}

				footerSelectLi02[i].onclick = function() {
					for(j = 0; j < footerSelectLi02_count; j++) {
						footerSelectLi02[j].style.color = "#858585";
						footerSelectLi02[j].style.fontWeight = "normal";
					}
					this.style.color = "#585858";
					this.style.fontWeight = "bold";
					var titleNode = footerSelectLi[0].childNodes[0];
					titleNode.nodeValue = this.childNodes[0].firstChild.nodeValue;
					footerSelectUl[1].style.display = "none";
				}
			}
		}
	}
}


function topSearch() {
	if (!document.getElementById('searchSelect')) {
		return false;
	}

	var searchdl = document.getElementById("searchSelect");
	var searchli = searchdl.getElementsByTagName("li");

	searchli[0].onclick = function(){
		if(searchli[1].style.display == "block") {
			searchli[1].style.display = "none";
		} else {
			searchli[1].style.display = "block";

			var categoryul = searchli[1].getElementsByTagName("ul");
			var categoryli = categoryul[0].getElementsByTagName("li");
			var categoryli_count = categoryli.length;

			for(i = 0; i < categoryli_count; i++) {
				categoryli[i].onmouseover = function() {
					this.style.color = "#f48a02";
				}

				categoryli[i].onmouseout = function() {
					this.style.color = "#858585";
				}

				categoryli[i].onclick = function() {
					for(j = 0; j < categoryli_count; j++) {
						categoryli[j].style.color = "#858585";
						categoryli[j].style.fontWeight = "normal";						
					}
					this.style.color = "#585858";
					this.style.fontWeight = "bold";					
					var titleNode = searchli[0].childNodes[0];
					titleNode.nodeValue = this.childNodes[0].childNodes[0].nodeValue;

					searchli[1].style.display = "none";
				}
			}
		}
	}
}

function initMoving(target, position, topLimit, btmLimit) {
	if (!target)
		return false;

	var obj = target;
	obj.initTop = position;
	obj.topLimit = topLimit;
	obj.bottomLimit = document.documentElement.scrollHeight - btmLimit;

	obj.style.position = "absolute";
	obj.top = obj.initTop;
	obj.left = obj.initLeft;

	if (typeof(window.pageYOffset) == "number") {
		obj.getTop = function() {
			return window.pageYOffset;
		}
	} else if (typeof(document.documentElement.scrollTop) == "number") {
		obj.getTop = function() {
			return document.documentElement.scrollTop;
		}
	} else {
		obj.getTop = function() {
			return 0;
		}
	}


	if (self.innerHeight) {
		obj.getHeight = function() {
			return self.innerHeight;
		}
	} else if(document.documentElement.clientHeight) {
		obj.getHeight = function() {
			return document.documentElement.clientHeight;
		}
	} else {
		obj.getHeight = function() {
			return 500;
		}
	}

	obj.move = setInterval(function() {
		if (obj.initTop > 0) {
			pos = obj.getTop() + obj.initTop;
		} else {
			pos = obj.getTop() + obj.getHeight() + obj.initTop;
			//pos = obj.getTop() + obj.getHeight() / 2 - 15;
		}

		if (pos > obj.bottomLimit)
			pos = obj.bottomLimit;
		if (pos < obj.topLimit)
			pos = obj.topLimit;

		interval = obj.top - pos;
		obj.top = obj.top - interval / 3;
		obj.style.top = obj.top + "px";
	}, 30)
}


addLoadEvent(topSearch);



