﻿DomLoaded.load(Archive);
function Archive(){
	SetArchiveDefault.call($("yearbox","YearSelect"));
	BatchDiffEvent.call($("YearSelect"),["onmouseover",OpenArchiveList],["onmouseout",ChooserLeaved]);
	document.onclick = function(e){
		if(!e)e = window.event;
		var EventObj = e.target?e.target:e.srcElement;
		if(!FindObj.call(EventObj)){
			HiddenArchiveList.call($("yearbox"));
		}
	}
}
function FindObj(){
    var oObj = this;
    try{
        do{
            if(oObj == $("yearbox")){
                return true;
                break;
            }
            oObj = oObj.parentNode;
        }while(oObj.tagName != "div" || oObj != $("yearbox"))
    }catch(e){}
}
function SetArchiveDefault(){
	this[0].status = "Hide";
    this[1].conntect = this[0];
    this[0].conntect = this[1];
    this[0].MaxHeight = this[0].getElementsByTagName("LI").length * 20 + 20;
    this[0].MaxWidth = 210;
    this[0].Speed = 0.2;
    this[0].Hide = SetYearListHidden;
    this[0].Open = SetYearListOpen;
	this[0].onmouseover = SetYearListMouseOver;
}
function SetYearListOpen(){
    ClearSetTime()
    var List = this;
	List.style.background = "none";
    List.style.display = "block";
    ListOpen = setInterval(function(){
        List.style.height = List.offsetHeight + (List.MaxHeight * List.Speed - 20) + "px";
		List.style.width = List.offsetWidth + (List.MaxWidth * List.Speed - 20) + "px";
        if(List.offsetWidth >= List.MaxWidth || List.offsetHeight >= List.MaxHeight){
            List.style.height = List.MaxHeight + "px";
			List.style.width = List.MaxWidth + "px";
			List.style.backgroundColor = "#F4FCFF";
			List.conntect.className = "highlight";
            List.status = "Open";
            clearInterval(ListOpen);
        }
    },10);
}
function SetYearListHidden(){
    ClearSetTime()
    var List = this;
	List.style.background = "none";
    ListClose = setInterval(function(){
        List.style.height = List.offsetHeight - (List.MaxHeight * List.Speed) + "px";
		List.style.width = List.offsetWidth - (List.MaxWidth * List.Speed) + "px";
        if(List.offsetWidth <= 42 || List.offsetHeight <= 24){
            List.style.height = "10px";
			List.style.width = "0px";
            List.style.display = "none";
            List.conntect.className = "";
            List.status = "Hide";
            clearInterval(ListClose);
        }
    },10);
}
function SetYearListMouseOver(e){
    var List = this;
    document.onmouseover = function(e){
	    if(!e)e = window.event;
	    var EventObj = e.target?e.target:e.srcElement;
	    if(GetParent.call(EventObj)){
	        if(window.HiddenArchive)clearTimeout(HiddenArchive);
	    }else{
	        DelayHidden.call(List);
	        document.onmouseover = null;
	    }
    }
}
function ClearSetTime(){
    if(window.ListOpen)clearInterval(ListOpen);
    if(window.ListClose)clearInterval(ListClose);
	if(window.HiddenArchive)clearTimeout(HiddenArchive);
}
function OpenArchiveList(){
	if(window.HiddenArchive)clearTimeout(HiddenArchive);
	if(this.conntect.status == "Hide"){
        var conntect = this.conntect;
	    OpenArchive = setTimeout(function(){
	        conntect.Open();
	    },200);
    }
}
function ChooserLeaved(){
	DelayHidden.call(this.conntect);
}
function DelayHidden(){
    if(window.OpenArchive)clearTimeout(OpenArchive);
	var conntect = this;
	HiddenArchive = setTimeout(function(){
	    HiddenArchiveList.call(conntect);
	},500);
}
function HiddenArchiveList(){
	if(this.status == "Open"){
		this.Hide();
	}
}
function GetParent(){
	var oParent = this;
	while(oParent.tagName != "HTML"){
		if(oParent.id == "yearbox"){
			return true;
		}
		oParent = oParent.parentNode;
	}
	return false;
}
