// Drop-down menu

	var DIVS;

	function MenuDropDown(){
		//this.testField = document.getElementById('test');
		this.imagePath = '/images/menu/';
		this.divs = new Array();
		this.divs.push(new Array('ju2uw9'));
		this.divs.push(new Array('ie1je6'));
		this.divs.push(new Array('lu43j2'));
		this.divs.push(new Array('6rpx68'));
		this.divs.push(new Array('y187fv'));
		for(var i=0; i<this.divs.length; i++) {
			this.divs[i][1] = document.getElementById('div_'+this.divs[i][0]);
			this.divs[i][2] = 1; // timeout
			this.divs[i][3] = document.getElementById(this.divs[i][0]); // images
		}
		DIVS = this.divs;
	}
	
	MenuDropDown.prototype.show = function (obj) {
		var numero = this.getDivNumero(obj.id);
		var div    = this.divs[numero][1];
        
        if (div!=null) {
            div.style.display = '';
		    if (obj.id.indexOf('div_')==-1) {
			    div.style.width = (obj.offsetWidth - 2) + 'px';
			    div.style.top   = (this.findPosY(obj) + obj.offsetHeight - 1) + 'px';
			    div.style.left  = (this.findPosX(obj) + 1) + 'px';
			    //this.testField.value = obj.src;
		    }
        }
		this.manage(numero,true);
	}
	
	MenuDropDown.prototype.hide = function (obj) {
		var numero = this.getDivNumero(obj.id);
		this.manage(numero,false);
	}
	
	MenuDropDown.prototype.manage = function (numero,flag) {
		var temp = this.divs[numero][3].src.split('/');
		temp = temp[temp.length-1].split('.');
		var ext  = temp[temp.length-1];
		var name = temp[0];
		/*
		temp = temp.shift();
		var name = '';
		var last = temp.length-1;
		for(var i=0; i<last; i++)
			name += temp[i]+'.';
		name += temp[last];
		*/
		var new_name = (-1==(index=name.indexOf('_on'))) ? name : name.substr(0,index);
		//this.testField.value = new_name + " ("+name+")";
		if (flag)
		{
			if (this.divs[numero][1]!=null) this.divs[numero][1].style.visibility = 'visible';
			this.divs[numero][3].src = this.imagePath + new_name + '_on.' + ext;
			clearTimeout(this.divs[numero][2]);
		}
		else
		{
			this.divs[numero][2] = setTimeout("if (DIVS["+numero+"][1]!=null) DIVS["+numero+"][1].style.visibility = 'hidden'; clearTimeout(DIVS["+numero+"][2]); DIVS["+numero+"][3].src = '"+this.imagePath+ new_name + "." + ext+"';",300);
		}
	}
	
	MenuDropDown.prototype.getDivNumero = function (id) {
		id = this.getId(id);
		var div = false;
		for(var i=0; i<this.divs.length; i++)
			if (this.divs[i][0]==id) {
				div = true; break;
			}
		if (div) return i;
		else return div;
	}
	
	MenuDropDown.prototype.getId = function (id) {
		if (id.indexOf('div_')==-1)
			return id;
		else 
			return id.substr(4,id.length-1);
	}
	
	MenuDropDown.prototype.findPosX = function(obj) {
		var curleft = 0;
		if (obj.offsetParent)	
			while (obj.offsetParent)		{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		else if (obj.x)	curleft += obj.x;
		return curleft;
	}
	
	MenuDropDown.prototype.findPosY = function(obj) {
		var curtop = 0;
		if (obj.offsetParent)
			while (obj.offsetParent) {
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		else if (obj.y)	curtop += obj.y;
		return curtop;
	}
    
    MenuDropDown.prototype.ShowCurrentChapter = function (id) {
        this.show(document.getElementById(id));
    }
    
    MenuDropDown.prototype.body_resize = function (id) {
        this.hide(document.getElementById(id));
        this.show(document.getElementById(id));
    }

	var menu = new MenuDropDown();