if(!document.getElementById && document.all) { 
	document.getElementById = function(id) {
		return document.all[id]; 
	}
}
else if(!document.getElementById && !document.all) { 
	document.getElementById = function(id) {    
  		return { style: {} };
	}
}

function getAbsoluteLeft(o) { 
	oLeft = o.offsetLeft;
	while(o.offsetParent) {
		oParent = o.offsetParent;
		oLeft += oParent.offsetLeft;
		o = oParent;
	}
	return oLeft;
}

function getAbsoluteTop(o) { 
	oTop = o.offsetTop;
	while(o.offsetParent) {
		oParent = o.offsetParent;
		oTop += oParent.offsetTop;
		o = oParent;
	} 
	return oTop;
}

var GLOBAL_JS_OBJECT_REF = Array();
function addJsObject(jsObj) {
	var len = GLOBAL_JS_OBJECT_REF.length;
	GLOBAL_JS_OBJECT_REF[len] = jsObj;
}
function getJsObject(id) {
	var jsObj = null;
	
	len = GLOBAL_JS_OBJECT_REF.length;
	for(var i=0;i<len;i++) {
		jsObj = GLOBAL_JS_OBJECT_REF[i];
		if(jsObj.id==id) {
			break;
		}
		else {
			jsObj = null;
		}
	}
	return jsObj;
}

function getEvent(evt) {
	if(!evt) {
		return window.event;
	}
	else {
		return evt;
	}	
}

function getTarget(evt) {
	evt = getEvent();
	if(window.event) {
		return evt.srcElement;
	}
	else {
		return evt.target;
	}
}

function getRelatedTarget(evt) {
	evt = getEvent();
	if (window.event) {
		if(evt.type=="mouseover") {
			return evt.fromElement;
		}
		else  {
			return evt.toElement;
		}
	}
	else {
		return evt.relatedTarget;
	}	
}
	
function onMouseOver(evt) {
	var jsObj = getJsObject(this.id);	
	jsObj.isActive = true;
	jsObj.onMouseOverImpl(evt);
}

function onMouseOut(evt) {
	var jsObj = getJsObject(this.id);
	jsObj.isActive = false;
	jsObj.onMouseOutImpl(evt);
}

function onClick(evt) {
	var jsObj = getJsObject(this.id);
	jsObj.onClickImpl(evt);
}

function getHtmlObject(id) {
	return document.getElementById(id);
}


function changeStyle(id,property,value) {
	var htmlObj = getHtmlObject(id);
	htmlObj.style[property] = value;
}

function move(id,position) {
	var htmlObj = getHtmlObject(id);
	if(position.isPosition) {		
		changeStyle(id,'left',position.left+"px");
		changeStyle(id,'top',position.top+"px");
	}
}

function passivate(id1,id2) {
	var jsObj1 = getJsObject(id1);
	var jsObj2 = getJsObject(id2);	
	jsObj1.passivate();		
	jsObj2.passivate();			
}

function getSWPosition(id) {
	var htmlObj = getHtmlObject(id);
	return new Position(getAbsoluteLeft(htmlObj),getAbsoluteTop(htmlObj)+htmlObj.offsetHeight);
}

function initAllAction() {
	var len = GLOBAL_JS_OBJECT_REF.length;
	for(var i=0;i<len;i++) {
		var jsObj = GLOBAL_JS_OBJECT_REF[i];
		initAction(jsObj.id);
	}
}

function initAction(id) {
	var jsObj = getJsObject(id);
	var htmlObj = getHtmlObject(id); 

	if(jsObj && htmlObj) {
		if(jsObj.onMouseOverImpl) htmlObj.onmouseover = onMouseOver;
		if(jsObj.onMouseOutImpl) htmlObj.onmouseout = onMouseOut;
		if(jsObj.onClickImpl) htmlObj.onclick = onClick;
	}
}

var Position = function(left,top) {
	this.isPosition = true;
	
	this.left = left;
	this.top = top;
}

var HtmlItem = function(htmlTag,id,innerHtml,passiveClass,activeClass) {
	addJsObject(this);
	
	this.isHtmlItem = true;
	
	this.isActive = false;
			
	this.htmlTag = htmlTag;
	this.id = id;
	this.innerHtml = innerHtml;	
	this.passiveClass = passiveClass;
	this.activeClass = activeClass;
	
	this.controler = null;
	
	this.activate = function() {
		if(this.activeClass && this.isActive) {
			var htmlObj = getHtmlObject(this.id);
			htmlObj.className = this.activeClass;			
		}
	}
	
	this.passivate = function() {
		if(this.passiveClass && !this.isActive) {
			var htmlObj = getHtmlObject(this.id);
			htmlObj.className = this.passiveClass;			
		}
	}
	
	
		
	this.writeHtml = function() {
		var strBuffer = "<" + this.htmlTag;
		if(this.id) strBuffer += " id=\"" + this.id + "\"";
		if(this.passiveClass) strBuffer += " class=\"" + this.passiveClass + "\"";
		strBuffer += ">";
		if(this.innerHtml) strBuffer += this.innerHtml;
		strBuffer += "</" + this.htmlTag + ">";
		return strBuffer;
	}	
}

var LiItem = function(id,innerHtml,passiveClass,activeClass) {
	this.parent = HtmlItem;
	this.parent("li",id,innerHtml,passiveClass,activeClass);
	
	this.isLiItem = true;
}

var UlItem = function(id,passiveClass,activeClass) {
	this.parent = HtmlItem;
   	this.parent("ul",id,null,passiveClass,activeClass);

	this.isUlItem = true;

    this.liItemArray = new Array();
    
	this.addLiITem = function(liItem) {
		if(liItem.isLiItem) {
			var len = this.liItemArray.length;			
			if(!liItem.id) liItem.id = this.id + "#li" + len;
			this.liItemArray[len] = liItem;
		}
    }
	
	this.writeHtml = function() {
		var strBuffer = "<" + this.htmlTag;
		if(this.id) strBuffer += " id=\"" + this.id + "\"";
		if(this.passiveClass) strBuffer += " class=\"" + this.passiveClass + "\"";
		strBuffer += ">\n";
		var len = this.liItemArray.length;
		for(var i=0;i<len;i++) {
			strBuffer += this.liItemArray[i].writeHtml() + "\n";
		}
		strBuffer += "</" + this.htmlTag + ">\n";
		return strBuffer;		
	}		
	
	this.writeHtmlRef = function() {		
		var strBuffer = "";
		var len = this.liItemArray.length;
		for(var i=0;i<len;i++) {
			var currentLiItem = this.liItemArray[i];
			if(currentLiItem.isUlRefLiItem) strBuffer += currentLiItem.writeHtmlRef() + "\n";
		}
		return strBuffer;		
	}	
}

var UlRefLiItem = function(id,innerHtml,passiveClass,activeClass,ulRef,locRef) {
	this.parent = LiItem;
	this.parent(id,innerHtml,passiveClass,activeClass);
		
	this.isUlRefLiItem = true;
	
	this.locRef = locRef;
	
	this.ulRef = null;
	if(ulRef.isUlItem) {		
		ulRef.controler = this;
		this.ulRef = ulRef;
	}
	
	this.writeHtmlRef = function() {
		return this.ulRef.writeHtml();		
	}
	
	this.onMouseOverImpl = function() {
		this.activate();
	
		var objRef = getHtmlObject(this.ulRef.id);
		var swPosition = getSWPosition(this.id)		
				
		this.ulRef.isActive = true;		
		this.ulRef.activate();
				
		move(this.ulRef.id,swPosition);
	}
	
	this.onMouseOutImpl = function(evt) {
		this.ulRef.isActive = false;
		setTimeout("passivate('" + this.ulRef.id + "','" + this.id + "');",20);		
	}
	
	this.ulRef.onMouseOverImpl = function(evt) {
		this.controler.isActive = true;
		this.controler.activate();
	}
	
	this.ulRef.onMouseOutImpl = function(evt) {
		this.controler.isActive = false;
		setTimeout("passivate('" + this.id + "','" + this.controler.id + "');",20);
	}
				
	this.onClickImpl = function(evt) {
		if(this.locRef) location.href = this.locRef;
	}
}

var LocRefLiItem = function(id,innerHtml,passiveClass,activeClass,locRef) {
	this.parent = LiItem;
	this.parent(id,innerHtml,passiveClass,activeClass);
		
	this.isLocRefLiItem = true;
	
	this.locRef = locRef;
	
	this.onMouseOverImpl = function() {
		this.activate();	
	}
	
	this.onMouseOutImpl = function(evt) {
		this.passivate();
	}
	
	this.onClickImpl = function(evt) {
		if(this.locRef) location.href = this.locRef;
	}
}