var cspbFO=true;
var cspbTL=0;
var cspbTD=0;
var cspbGDH=0;
var cspbGD;
var cspbEIA=false;

function IMMenu(llave, cantidad) {
	this.llave		= llave;
	this.cantidad	= cantidad;
	this.autoClose	= true;
	this.closeAll	= true;
	this.colaspseHeight = true;
	var iDelay = 1000 ;
	var sDisplayTimer = null;
	var oLastItem = true;
	var iNSWidth = 100;
	
	this.useTabs = false;
	this.classTabsActive = "activate";
	this.classTabsInactive = "off";
	this.nameTab = "main";
	
	var enUso = false;
	var entrada		= new Array();
	var content		= new Array();
	
	isOPERA = (navigator.userAgent.indexOf('Opera') >= 0)? true : false;
	isIE    = (document.all && !isOPERA)? true : false;
	isDOM   = (document.getElementById && !isIE)? true : false;
	
	this.initArray = function() {
		for (x=0; x < this.cantidad; x++) {
			entrada [this.llave + "_" + x] = true;
		}
	}
	
	this.make_menu = function(id){
		if(cspbEIA){
			return;
		}
		if(this.closeAll) {
			this.hide_all();
		}
		if (entrada[this.llave + "_" + id]) {
			this.show (id);
			for (x=0; x < this.cantidad; x++){
				entrada [this.llave + "_" + x] = true;
			}
			if(this.autoClose) {
				entrada[this.llave + "_" + id] = false;
			}
		}else{
			if(this.autoClose) {
				this.hide(id);
			}
			entrada[this.llave + "_" + id]=true;
		} 
	}	
	
	this.hide_all = function() {
		for (i=0; i<this.cantidad;i++){
			this.hide(i);
		}
	}
	
	this.hide = function(id){
		if (isDOM) {
			el	= document.getElementById(this.llave +  "_" + id);
			if(this.useTabs) mainTab = document.getElementById(this.nameTab + this.llave +  "_" + id);
		} else if (isIE) {
			el = document.all[this.llave + "_" + id];
			if(this.useTabs) mainTab = document.all[this.nameTab + this.llave +  "_" + id];
		}
		cspbGD = el;
		try {
			if(this.useTabs && mainTab) mainTab.className=this.classTabsInactive;
		}
		catch(e){}
		el.style.display='none';
		return;
		
		if(this.colaspseHeight)
		{
			cspbGDH = el.offsetHeight;
		}
		else
		{
			cspbGDH = '';//el.offsetWidth;
		}
		objMenu = this;
		cspbEC(0);
	}

	
	
	this.show = function(id){
		
		if (isDOM) {
			el	= document.getElementById(this.llave +  "_" + id);
			if(this.useTabs) mainTab = document.getElementById(this.nameTab + this.llave +  "_" + id);
		} else if (isIE) {
			el = document.all[this.llave + "_" + id];
			if(this.useTabs) mainTab = document.all[this.nameTab + this.llave +  "_" + id];
		}
		try {
			if(this.useTabs && mainTab) mainTab.className = this.classTabsActive;
		}
		catch(e){}
		el.style.display = "";
		cspbGD=el;
		return;
		if(this.colaspseHeight)
		{
			cspbGDH = el.offsetHeight;
			el.style.height=1;
		}
		else
		{
			cspbGDH = el.offsetWidth;
			el.style.width=1;
		}
		objMenu = this;
		cspbEO(cspbGDH);
	}

	this.stopTimer = function () {
		clearTimeout(sDisplayTimer)
	}

	this.startTimer = function () {
	  this.stopTimer()
	  objMenu = this;
	  sDisplayTimer = setTimeout('callHideItem()',iDelay)
	}

	this.hideItem = function () {
		if (oLastItem) {
			this.hide_all();
		}
	}
}
var objMenu;
function callHideItem() {
	objMenu.hideItem();
}


function cspbEO(l){
	var RES=1;
	cspbEIA=true;
	cspbTL=l;

	if(cspbTL==0){
		if(objMenu.colaspseHeight)
		{
			cspbGD.style.height=cspbGDH;
		}
		else
		{
			cspbGD.style.width=cspbGDH;	
		}
		cspbEIA=false;
	} else{
		if(cspbTL<=RES){
			cspbTD=1;
		}else{
			cspbTD=parseInt(cspbTL/RES);
		}
		if(cspbGDH!=cspbTL){
			if(objMenu.colaspseHeight)
			{
				cspbGD.style.height=cspbGDH-cspbTL;
			}
			else
			{
				cspbGD.style.width=cspbGDH-cspbTL;
			}
		}
		setTimeout('cspbEO(cspbTL-cspbTD);',20);
	}
}

function cspbEC(l){
	var RES=6;
	cspbEIA=true;
	cspbTL=l;
	if(cspbGDH==cspbTL || cspbGDH<cspbTL){
		cspbGD.style.display='none';
		if(objMenu.colaspseHeight)
		{
			cspbGD.style.height=cspbGDH;
		}
		else
		{
			cspbGD.style.width=cspbGDH;
		}
		cspbEIA=false;
	}else{
		if((cspbGDH-cspbTL)<=RES){
			cspbTD=1;
		}else{
			cspbTD=parseInt((cspbGDH-cspbTL)/RES);
		}
		if(objMenu.colaspseHeight)
		{
			cspbGD.style.height = cspbGDH - cspbTL;
		}
		else
		{
			cspbGD.style.width = cspbGDH - cspbTL;
		}
		setTimeout('cspbEC(cspbTL+cspbTD);',10);
	}
}
function MakeMenu(llave, cantidad, colaspseHeight, initArray) {
	try
	{
		immenu = new IMMenu(llave, cantidad);
		if(initArray)
		{
			immenu.initArray();
		}
		immenu.colaspseHeight = colaspseHeight;
		return immenu;
	}
	catch(e)
	{
		return false;
	}
}

