﻿// JavaScript Document

function ListItem(){
	if(arguments[0]<1){
		alert("StyleControl Object needs one DOM object as argument.");
		return;
	}
	
	var object=arguments[0];
	var nodes=object.childNodes;
	for(var i in nodes){
		if(nodes[i].tagName && nodes[i].tagName.toLowerCase()=="a"){
			this.a=new StyleControl(nodes[i]);
		}else if(nodes[i].tagName && nodes[i].tagName.toLowerCase()=="span"){
			this.span=new StyleControl(nodes[i]);
			this.text=nodes[i].innerHTML;
		}
	}
}

ListItem.prototype={
	a:null,
	span:null,
	text:null,
	
	init:function(){
		this.a.setClassName("");
		this.a.object.onmouseover=function(){
			eval(ObjectRegister.objectGraduallyExpand+".halt()");
		}
		this.a.object.onmouseout=function(){
			eval(ObjectRegister.objectGraduallyExpand+".start()");
		}
		this.span.hide();
	},
	
	expand:function(){
		this.span.clearObject();
		
		var middle=document.createElement("span");
		middle.className="SmallWord Marked";
		middle.innerHTML=this.text;
		middle.style["height"]="0px";
		this.span.appendObject(middle);
		
		var top=document.createElement("span");
		top.className="LeftBoxTop";
		this.span.insertObject(top);
		
		var bottom=document.createElement("span");
		bottom.className="LeftBoxBottom";
		this.span.appendObject(bottom);
		
		this.a.setClassName("current");
		this.span.show();
		
		var browse=new Browse();
		if(browse.getVersion()=="Internet Explorer"){
			var timer=setInterval(function(){
							  	  var height=middle.style["height"];
								  var regExp=/(\d+)px/gi;
								  regExp.exec(height);
								  height=parseInt(RegExp.$1);
								  if(height>129){
									  clearInterval(timer);
								  }else{
								  	  middle.style["height"]=(height+(130-height)*0.2)+"px";
								  }
							  },90);
		}else{
			middle.style["height"]="130px";
		}
		
	},
	fold:function(){
		this.span.clearObject();
		this.span.hide();
		this.a.setClassName("");
		this.span.object.innerHTML=this.text;
		return true;
	}
}

function GraduallyExpand(){
	if(arguments.length<1){
		alert("GraduallyExpand Object needs one DOM object as argument.");
		return;
	}
	
	var object=null;
	if((typeof(arguments[0])=="string")&&arguments[0].constructor==String){
		object=document.getElementById(arguments[0]);
	}else{
		object=arguments[0];
	}
	
	if(object){
		this.list=new Array();
		var items=object.getElementsByTagName("li");
		for(var i in items){
			if(items[i].tagName && items[i].tagName.toLowerCase()=="li"){
				var temp=new ListItem(items[i]);
				this.list.push(temp);
			}
		}
		for(var i in this.list){
			this.list[i].init();
		}
		this.current=0;
		this.interval=5000;
		this.status=false;
	}else{
		return;
	}
}

GraduallyExpand.prototype={
	list:null,
	current:null,
	interval:null,
	status:null,
	timer:null,
	
	start:function(){
		this.status=true;
		this.timer=window.setInterval(this.change,this.interval);
	},
	
	change:function(){
		var currentIndex=eval(ObjectRegister.objectGraduallyExpand+".current");
		var previousIndex=eval(ObjectRegister.objectGraduallyExpand+".getPrevious()");
		eval(ObjectRegister.objectGraduallyExpand+".movenext()");
		if(eval(ObjectRegister.objectGraduallyExpand+".list["+previousIndex+"].fold()")){
			eval(ObjectRegister.objectGraduallyExpand+".list["+currentIndex+"].expand()");
		}
	},
	
	halt:function(){
		if(this.status){
			this.status=false;
			clearInterval(this.timer);
		}
	},
	
	movenext:function(){
		++this.current;
		if(this.current>=this.list.length){
			this.current=0;
		}
	},
	
	getPrevious:function(){
		var index=this.current;
		index--;
		if(index<0){
			index=this.list.length-1;
		}
		return index;
	}
}
