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.sufix = sufix;
	this.title = title;
	this.butcolor = 'blue';
	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 (!event) event = window.event;'+
		'var flag = false;'+
		'var src = event.srcElement ? event.srcElement : event.target;'+
		'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.initialize = false;
dropMenu.init = function() {
	if (!dropMenu.initialize) {
		/*if (!navigator.appName.match(/microsoft/i)) {
			//window.addEventListener('resize', new Function('event', 'alert("x");'));
		} else {*/
			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 = 'hand';
		}
		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();');
	}
	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 = 'hand';
		}
		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.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 - 5;
	this.objects[0].style.display = '';	
	var leftPos = (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';
	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 + '.gif" width="17" height="9" 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.disable = function() {
	this.disableTitle = this.objects[4].innerHTML;
	this.disableClass = this.objects[4].className;
	this.objects[4].innerHTML = this.title + '<img src="' + dropMenu.path + 'but.down.gray.gif" width="17" height="9" style="margin-left: 10px;" />';
	this.objects[4].className = 'dmTitle';
	this.hide();
}

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

dropMenu.prototype.zero = function() {
	var item = document.getElementById('dropMenuItem' + this.sufix + this.selectIndex);
	if (item) item.className = 'dropMenuItem';
	this.selectIndex = -65535;
	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="17" height="9" style="margin-left: 10px;" /></a>';
	this.objects[4].className = 'dmTitle';

}

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="17" height="9" 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();
}

