dropMenu = function(sufix, title) {
	this.id = Math.round(Math.random() * (new Date).valueOf()) + '';
	dropMenu.cash[this.id] = this;
	this.objects = [];
	this.objects[0] = document.getElementById('mainbox'		+ sufix);
	this.objects[1] = document.getElementById('scrollbox'	+ sufix);
	this.objects[2] = document.getElementById('upbutton'	+ sufix);
	this.objects[3] = document.getElementById('downbutton'	+ sufix);
	this.objects[4] = document.getElementById('select'		+ sufix);
	this.objects[5] = document.getElementById('maintable'	+ sufix);
	this.objects[6] = document.getElementById('scrollbutton'+ sufix);
	this.sufix = sufix;
	this.title = title;
	this.cursor = window.navigator.appName.match(/explorer/ig) ? 'hand' : 'pointer';
	this.butcolor = 'blue';
	this.disabled = false;
	this.disableTitle = '';
	this.disableClass = '';
	this.state = 0;
	this.getScroll();
	this.initButtons();
	this.timer = null;
	this.hidetimer = null;
	this.hideinterval = 15000;
	this.wheelSet();
	this.wheel = false;
	this.value = null;
	this.flag = false;
	this.selectIndex = -1;
	this.selectInput = null;
	
	this.onSelect = function() {};
	
	this.clickHandler = new Function(
		'event',
		'if (dropMenu.scrollId[\'ieNotHide\']) { dropMenu.scrollId = []; return false; }' + 
		'if (!event) event = window.event;'+
		'var flag = false;'+
		'var src = event.srcElement ? event.srcElement : event.target;'+
		'if (src.id == \'scrollbutton' + sufix + '\') return false;' +
		'while (src = src.parentNode) {'+
		'	if ((src.id == \'mainbox' + sufix + '\') || (src.id == \'select' + sufix + '\')) {'+
		'		flag = true; break;' +
		'	}'+
		'}'+
		'if (!flag) dropMenu.cash[\'' + this.id +  '\'].hide();'
	);
	return this.id;
}

dropMenu.cash = [];
dropMenu.path = '';
dropMenu.scrollId = [];
dropMenu.initialize = false;
dropMenu.init = function() {
	if (!dropMenu.initialize) {
		window.onresize = new Function('event', 'for (var id in dropMenu.cash) dropMenu.cash[id].hide();');
	}
	dropMenu.initialize = true;
}

dropMenu.absolute = function(oObject) {
	var oPos = {x : oObject.offsetLeft, y : oObject.offsetTop};
	if (oObject.offsetParent) {
		var oTemp = dropMenu.absolute(oObject.offsetParent);
		oPos.x += oTemp.x;
		oPos.y += oTemp.y;
	}
	return oPos;
}

dropMenu.prototype.wheelSet = function() {
	if (!navigator.appName.match(/microsoft/i)) {
		this.objects[0].addEventListener('DOMMouseScroll', new Function('event', 	'	if ((event.detail * -1) > 0) {							' +
																					'		dropMenu.cash[\'' + this.id +  '\'].wheel = true;	' +
																					'		dropMenu.cash[\'' + this.id +  '\'].goUp();			' +
																					'	} else {												' +
																					'		dropMenu.cash[\'' + this.id +  '\'].wheel = true;	' +
																					'		dropMenu.cash[\'' + this.id +  '\'].goDown();		' +
																					'	}														' +
																					'	event.preventDefault();'), false);
	}
	this.objects[0].onmousewheel = new Function('event',	'	if (!event) event = window.event;						' +
															'	if (event.wheelDelta > 0) {								' +
															'		dropMenu.cash[\'' + this.id +  '\'].wheel = true;	' +
															'		dropMenu.cash[\'' + this.id +  '\'].goUp();			' +
															'	} else {												' +
															'		dropMenu.cash[\'' + this.id +  '\'].wheel = true;	' +
															'		dropMenu.cash[\'' + this.id +  '\'].goDown();		' +
															'	}														' +
															'	event.returnValue = false;');
 }


dropMenu.prototype.getScroll = function() {
	this.maxScroll = this.objects[1].scrollHeight - this.objects[1].offsetHeight;
}

dropMenu.prototype.initButtons = function() {
	if (this.maxScroll > 0) {
		if ((this.state == 0) || (this.state == 1)) {
			this.objects[3].src = dropMenu.path + 'but.down.gray.gif';
			this.objects[3].style.cursor = this.cursor;
		}
		this.objects[3].onmouseover = new Function('this.src = "' + dropMenu.path + 'but.down.' + this.butcolor + '.gif"; dropMenu.cash[\'' + this.id +  '\'].wheel = false; dropMenu.cash[\'' + this.id +  '\'].goDown();');
		this.objects[3].onmouseout = new Function('this.src = "' + dropMenu.path + 'but.down.gray.gif"; dropMenu.cash[\'' + this.id +  '\'].stop();');
		this.scrollButton();
	}
	if (this.objects[1].scrollTop > 0) {
		if ((this.state == 0) || (this.state == -1)) {
			this.objects[2].src = dropMenu.path + 'but.up.gray.gif';
			this.objects[2].style.cursor = this.cursor;
		}
		this.objects[2].onmouseover = new Function('this.src = "' + dropMenu.path + 'but.up.' + this.butcolor + '.gif"; dropMenu.cash[\'' + this.id +  '\'].wheel = false; dropMenu.cash[\'' + this.id +  '\'].goUp();');
		this.objects[2].onmouseout = new Function('this.src = "' + dropMenu.path + 'but.up.gray.gif"; dropMenu.cash[\'' + this.id +  '\'].stop();');
	}
	if (this.maxScroll <= this.objects[1].scrollTop) {
		this.objects[3].src = dropMenu.path + 'but.down.lightgray.gif';
		this.objects[3].onmouseover = null;
		this.objects[3].onmouseout = null;
		this.objects[3].style.cursor = 'default';
	}
	if (this.objects[1].scrollTop == 0) {
		this.objects[2].src = dropMenu.path + 'but.up.lightgray.gif';
		this.objects[2].onmouseover = null;
		this.objects[2].onmouseout = null;
		this.objects[2].style.cursor = 'default';
	}
}

dropMenu.prototype.scrollParameters = function() {
	var parameters = { upPos : 0, btPos : 0, Yt : 0, Yb : 0, path : 0, dX : 0, dY : 0, delta : 0, dScroll : 0 };
	
	parameters.upPos = dropMenu.absolute(this.objects[2]);
	parameters.btPos = dropMenu.absolute(this.objects[3]);
		
	parameters.Yt = parameters.upPos.y + this.objects[2].height;
	parameters.Yb = parameters.btPos.y - this.objects[6].height - 1;
		
	parameters.path = parameters.Yb - parameters.Yt;
	
	parameters.delta = parameters.path / this.maxScroll;
	parameters.dScroll = Math.round(this.objects[1].scrollTop * parameters.delta);
		
	parameters.dX = parameters.upPos.x + Math.round((this.objects[2].width - this.objects[6].width) / 2);
	parameters.dY = parameters.upPos.y + this.objects[2].height + parameters.dScroll;
	
	return parameters;
}

dropMenu.prototype.scrollButton = function() {
	if (this.maxScroll > 0) {
		var dmsl = document.getElementById('dropMenuScrollAll' + this.sufix);
		if (dmsl) dmsl.className = 'dropMenuScrollLine';
		
		var parameters = this.scrollParameters();
				
		this.objects[6].style.top = (this.maxScroll == this.objects[1].scrollTop) ? parameters.btPos.y - this.objects[6].height - 1 : parameters.dY + 1;
		this.objects[6].style.left = parameters.dX;
		this.objects[6].style.display = '';
	}
}

dropMenu.prototype.scrollDrag = function(event) {
	if (!event) event = window.event;
	if (document.addEventListener) {
		document.addEventListener("mousemove", dropMenu.scrollMove, true);
		document.addEventListener("mouseup", dropMenu.scrollStop, true);
	} else if (document.attachEvent) {
		document.attachEvent("onmousemove", dropMenu.scrollMove);
		document.attachEvent("onmouseup", dropMenu.scrollStop);
	}
	
	dropMenu.scrollId['id'] = this.id;
	dropMenu.scrollId['y'] = event.clientY - dropMenu.absolute(this.objects[6]).y;
	
	if (event.stopPropagation) event.stopPropagation();
	else event.cancelBubble = true;
	if (event.preventDefault) event.preventDefault();
	else event.returnValue = false;
}

dropMenu.scrollMove = function(event) {
	if (!event) event = window.event;
	var parameters = dropMenu.cash[dropMenu.scrollId['id']].scrollParameters();
	var Pos = event.clientY - dropMenu.scrollId['y'];
	var setPos;
	
	if ((Pos >= parameters.Yt) && (Pos <= parameters.Yb)) {
		dropMenu.cash[dropMenu.scrollId['id']].objects[6].style.top = Pos + "px";
		setPos = Math.round((Pos - parameters.Yt) / parameters.delta);
		if (setPos > dropMenu.cash[dropMenu.scrollId['id']].maxScroll) setPos = dropMenu.cash[dropMenu.scrollId['id']].maxScroll;
		if (setPos < 0) setPos = 0;
		dropMenu.cash[dropMenu.scrollId['id']].objects[1].scrollTop = setPos;
		dropMenu.cash[dropMenu.scrollId['id']].initButtons();
	}

	if (event.stopPropagation) event.stopPropagation();
	else event.cancelBubble = true;
	if (event.preventDefault) event.preventDefault();
	else event.returnValue = false;
}

dropMenu.scrollStop = function(event) {
	if (!event) event = window.event;
	
	if (event.stopPropagation) event.stopPropagation();
	else event.cancelBubble = true;
	if (event.preventDefault) event.preventDefault();
	else event.returnValue = false;
	
	if (document.removeEventListener) {
		document.removeEventListener("mousemove", dropMenu.scrollMove, true);
		document.removeEventListener("mouseup", dropMenu.scrollMove, true);
	}  else if (document.detachEvent) {
		document.detachEvent("onmousemove", dropMenu.scrollMove);
		document.detachEvent("onmouseup", dropMenu.scrollMove);
	}
	if (dropMenu.scrollId['id']) {
		dropMenu.cash[dropMenu.scrollId['id']].stop();
		dropMenu.scrollId = [];
		if (window.navigator.appName.match(/explorer/ig)) dropMenu.scrollId['ieNotHide'] = true;
	}
}

dropMenu.prototype.goDown = function() {
	if (this.maxScroll > this.objects[1].scrollTop)	{
		var delta = this.wheel ? 100 : 50;
		this.state = -1;
		this.objects[1].scrollTop += 10;
		if (!this.wheel) this.timer = window.setTimeout('dropMenu.cash[\'' + this.id +  '\'].goDown()', delta);
	} else this.stop();
	this.initButtons();
	if (this.hidetimer) {
		window.clearTimeout(this.hidetimer);
		this.hidetimer = window.setTimeout('dropMenu.cash[\'' + this.id +  '\'].hide();', this.hideinterval);
	}
}

dropMenu.prototype.goUp = function() {
	if (this.objects[1].scrollTop > 0)	{
		var delta = this.wheel ? 100 : 50;
		this.state = 1;
		this.objects[1].scrollTop -= 10;
		if (!this.wheel) this.timer = window.setTimeout('dropMenu.cash[\'' + this.id +  '\'].goUp()', delta);
	} else this.stop();
	this.initButtons();
	if (this.hidetimer) {
		window.clearTimeout(this.hidetimer);
		this.hidetimer = window.setTimeout('dropMenu.cash[\'' + this.id +  '\'].hide();', this.hideinterval);
	}
}

dropMenu.prototype.goTo = function(param) {
	switch (param) {
		case 'top' :
			this.objects[1].scrollTop = 1;
			this.goUp();
		break;
		case 'down' :
			this.objects[1].scrollTop = this.maxScroll - 1;
			this.goDown();
		break;
		case 'select' :
			this.objects[1].scrollTop = this.selectIndex*20;
			this.initButtons();
		break;
	}
}

dropMenu.prototype.stop = function() {
	this.state = 0;
	if (this.timer) window.clearTimeout(this.timer);
}

dropMenu.prototype.show = function() {
	var pos = dropMenu.absolute(this.objects[4]);
	var dbsw = document.body.scrollWidth;
	this.objects[0].style.top = pos.y + 20;
	this.objects[0].style.display = '';	
	var leftPos = pos.x;//(pos.x + Math.round(this.objects[4].offsetWidth / 2 )) - Math.round(this.objects[0].offsetWidth / 2);
	this.objects[0].style.left = leftPos;
	if (leftPos + this.objects[0].offsetWidth > dbsw) leftPos -= (leftPos + this.objects[0].offsetWidth) - dbsw;
	this.objects[0].style.left = leftPos;
	this.getScroll();
	this.initButtons();
	this.hidetimer = window.setTimeout('dropMenu.cash[\'' + this.id +  '\'].hide();', this.hideinterval);
	if (document.addEventListener) document.addEventListener('click', this.clickHandler, true);
	else document.attachEvent('onclick', this.clickHandler);
	this.goTo('select');
}

dropMenu.prototype.hide = function() {
	this.objects[0].style.display = 'none';
	this.objects[6].style.display = 'none';
	if (this.timer) window.clearTimeout(this.timer);
	if (this.hidetimer) window.clearTimeout(this.hidetimer);
	if (document.removeEventListener) document.removeEventListener('click', this.clickHandler, true);
	else document.detachEvent('onclick', this.clickHandler);
}

dropMenu.prototype.select = function(index, id, flag) {
	var item = document.getElementById('dropMenuItem' + this.sufix + index);
	if (item) {
		var i = 0, obj;
		while(obj = document.getElementById('dropMenuItem' + this.sufix + (i++))) obj.className = 'dropMenuItem';
		item.className = 'dropMenuItemSel';
		var name = item.innerHTML.replace(/<[^>]+>/ig, '');
		this.objects[4].className = 'dmTitleSelected';
		this.objects[4].innerHTML = '<a href="#" onclick="dropMenu.cash[\'' + this.id +  '\'].show(); return false;">' + name + '<img src="' + dropMenu.path + 'but.down.' + this.butcolor + '.top.gif" width="16" height="12" style="margin-left: 10px;" /></a>';
		this.selectIndex = index;
		this.value = id;
		if (flag != 'underfined') this.flag = flag;
		if (this.selectInput) this.selectInput.value = id;
		this.onSelect();
	}
	this.hide();
}

dropMenu.prototype.choose = function(id) {
	var link = document.getElementById('dropMenuItem' + this.sufix + 'Link' + id);
	if (link && link.onclick) {
		var tmpSelect = this.onSelect;
		this.onSelect = function() {};
		link.onclick();
		this.onSelect = tmpSelect;
	}
}

dropMenu.prototype.disable = function() {
	if (this.disabled) return ;
	this.disableTitle = this.objects[4].innerHTML;
	this.disableClass = this.objects[4].className;
	this.objects[4].innerHTML = this.title + '<img src="' + dropMenu.path + 'but.down.lightgray.top.gif" width="16" height="12" style="margin-left: 10px;" />';
	this.objects[4].className = 'dmTitleDis';
	this.hide();
	this.disabled = true;
}

dropMenu.prototype.enable = function() {
	this.objects[4].innerHTML = this.disableTitle;
	this.objects[4].className = this.disableClass;
	this.disabled = false;
}

dropMenu.prototype.zero = function() {
	var item = document.getElementById('dropMenuItem' + this.sufix + this.selectIndex);
	if (item) item.className = 'dropMenuItem';
	this.selectIndex = -65535;
	if (!this.disabled)	this.objects[4].innerHTML = '<a href="#" onclick="dropMenu.cash[\'' + this.id +  '\'].show(); return false;" onmouseover="document.getElementById(\'_dropbut' + this.sufix + '\').src=\'' + dropMenu.path + 'but.down.' + this.butcolor + '.top.gif\'" onmouseout="document.getElementById(\'_dropbut' + this.sufix + '\').src=\'' + dropMenu.path + 'but.down.gray.top.gif\'">' + this.title + '<img src="' + dropMenu.path + 'but.down.gray.top.gif" width="16" height="12"  id="_dropbut' + this.sufix + '" style="margin-left: 10px;" /></a>';
	this.objects[4].className = !this.disabled ? 'dmTitle' : 'dmTitleDis';
}

dropMenu.prototype.change = function(html) {
	this.goTo('top');
	this.objects[1].innerHTML = html;
	this.objects[4].className = 'dmTitle';
	this.objects[4].innerHTML = '<a href="#" onclick="dropMenu.cash[\'' + this.id +  '\'].show(); return false;">' + this.title + '<img src="' + dropMenu.path + 'but.down.gray.gif" width="16" height="12" style="margin-left: 10px;" /></a>';
	this.selectIndex = -65535;
	this.objects[1].style.height = (this.objects[1].style.height == '199px') ? '200px' : '199px';
	this.getScroll();
	this.initButtons();
	this.hide();
}
