var currMenu = null;
var currMenuItem = null;
var currMenu;
var currMenuItem;
var menuTimeOut;
var timeOutSec=.2;
var pointerName = (navigator.userAgent.indexOf("MSIE") != -1) ? "hand" : "pointer";

function destroyMenu(menuID, menuItemID) {
    if (menuTimeOut) clearTimeout(menuTimeOut);
    if (currMenu && menuID != currMenu) {
        document.getElementById(currMenu).style.cursor = "default";
    }
    if (currMenu && menuID != currMenu) {
        document.getElementById(currMenu).style.visibility = "hidden";
    }
    if (currMenuItem && menuItemID != currMenuItem) {
        document.getElementById(currMenuItem).style.cursor = "default";
    }
}
function cancelMenu() {
    if (menuTimeOut) {
        clearTimeout(menuTimeOut);
        menuTimeOut = null;
    }
    menuTimeOut = setTimeout('destroyMenu();', 1000 * timeOutSec);
}
function turnMenu(menuID) {
   if (currMenu) {
	   document.getElementById(currMenu).style.visibility = "hidden";
   }
    currMenu = menuID;
    if (menuID) {
        document.getElementById(menuID).style.visibility = "visible";
        currMenu = menuID;
    }
}

function createMenu(menuID) {
    destroyMenu(menuID);
    document.getElementById(menuID).style.cursor = pointerName;
    currMenuID = menuID;
    if (menuID) {
        document.getElementById(menuID).style.visibility = "visible";
        currMenuID = menuID;
    }
}
function createSubMenu(menuID, menuItemID) {
    if (menuTimeOut) {
        clearTimeout(menuTimeOut);
        menuTimeOut = null;
    }
    destroyMenu(menuID, menuItemID);
    document.getElementById(menuID).style.visibility = "visible";
    document.getElementById(menuItemID).style.cursor = pointerName;
    currMenu = menuID;
    currMenuItem = menuItemID;
}

function clearMenu() {
    if (currMenu) {
        document.getElementById(currMenu).style.visibility = "visible";
        currMenu = null;
    }
}

function collapse(expand)
{
	this.content =document.getElementById(expand).style;
	this.curHeight = 278;
		
	if (content.display == "block") {
			//close collapse
			 var contentIsOpen = false;
 			this.doOpenN = contentIsOpen;
			 this.fromHeight = curHeight;
			 this.toHeight = 0;
			stop(content);
			animateOption(expand,contentIsOpen,content);
			start(content,contentIsOpen);		
		} else {
			//open
			this.fromHeight = 0;
			this.toHeight = curHeight;
			var contentIsOpen = true;
			this.doOpenN = contentIsOpen;
			stop(content);
			animateOption(expand,contentIsOpen,content);
			start(content,contentIsOpen);
			}	
		return false;
}

function animateOption(zap,doOpen,content) {

	this.timer = null;
	this.interval = 0;
	this.stepCount = 0;
	this.fps = 0;
	this.steps = 10;
	this.duration = 500;
	this.onComplete = null;

	if (this.fps > 0){
		this.interval = Math.floor(1000 / this.fps);
		this.steps = parseInt((this.duration + (this.interval - 1)) / this.interval);
	} 
		else if (this.steps > 0)
			this.interval = this.duration / this.steps;									
	else{
			if (content.display == "none"){
				 content.visibility = "hidden";
				 content.display = "block";
			}
		content.height = "";
	}

	this.increment = (this.toHeight - this.fromHeight) / this.steps;
	this.overflow =content.overflow;

	content.height = this.fromHeight + "px";
	content.visibility = "visible";
	content.overflow = "hidden";
	content.display = "block";

}//end function


function start(content)
{
	var self = this;
	this.timer = setTimeout(function() { self.stepAnimation(content); }, this.interval);
};

function stepAnimation(content)
{
	++this.stepCount;

	this.animate(content);

	if (this.stepCount < this.steps)
		this.start();
	else if (this.onComplete)
		this.onComplete();
}

function stop(content)
{
	if (this.timer)
	{
		clearTimeout(this.timer);

		if (this.stepCount < this.steps)
			this.content.overflow = this.overflow;
	}
	this.timer = null;
}

function animate(conten)
{
	if (this.stepCount >= this.steps){
		if (!doOpenN)
		this.content.display = "none";
		this.content.overflow = this.overflow;
		this.content.height = this.toHeight + "px";
	}else{
		this.fromHeight += this.increment;
		this.content.height = this.fromHeight + "px";
	}
}

function changeBoxValue(selectedCategory)
{	
	if(!document.getElementsByTagName)
		return;

	var id_nm;
	var slidedownContentBox;
	for(var i=1;i<5;i++){
		id_nm = 'box0'+i;
		slidedowntBox= document.getElementById(id_nm);
		if(slidedowntBox){
				slidedowntBox.style.visibility='hidden';
				slidedowntBox.style.height='0px';
		}
	}

	var selectedBox='';
	if( (selectedCategory =='04') || (selectedCategory =='05')){
		selectedBox ='box01';
	}else if( (selectedCategory =='01')){
		selectedBox = 'box02';
	}else if( (selectedCategory =='02')){
		selectedBox = 'box03';		
	}else if( (selectedCategory =='03')){
		selectedBox = 'box04';
	}
	
	var target_id = document.getElementById(selectedBox);
	
	if(target_id){
		if(selectedCategory =='02'){
			target_id.style.top ='-3px';
		}else if(selectedCategory =='03'){
			target_id.style.top ='-10px';
		}else if(selectedCategory =='01'){
			target_id.style.top ='3px';
		}else if((selectedCategory =='04') || (selectedCategory =='05')){
			target_id.style.top ='7px';		
		}
	}
	

	var target_box = document.getElementsByTagName('a');
	for(var i=0; i<target_box.length; i++){
			var link = target_box[i];
			if (link.className == "dboxid"){
				link.setAttribute("onclick","slidedown_showHide('"+selectedBox+"');return false;")
				link.onclick = function() {
					var temp = new Function( "slidedown_showHide('"+selectedBox+"');return false;"); temp();}
			
			}
	}
}
