// Select menus

flag = false;
curentlySelect = null;

function HideSelect()
{
	if (flag)
	{
		curentlySelect.style.display = 'none';
		curentlySelect.father.className = "select";
		flag = false;
		currentlySelect = null;
		document.body.onclick = null;
	}
}

function SelectBox(root, hiddenElement)
{
	flag = false;
	this.root = document.getElementById(root);
	this.hidden = document.getElementById(hiddenElement);
	this.topValue = this.root.getElementsByTagName('span')[0];
	this.option = this.root.getElementsByTagName('li');
}

SelectBox.prototype.GetValue = function()
{
	var v = this.option[0].id;
	var t = this.option[0].innerHTML;
	var arr = this.option
	for ( var i=0; i<arr.length; i++ )
	{
		if ( arr[i].className=='active' )
		{
			v = arr[i].id;
			t = arr[i].firstChild.data;
			break;
		}
	}
	v = v.substr( 1, v.length-1 );
	this.ChangeValue(v, t);
	this.ChangeSelected();
	this.root.onclick = this.RootClicker;
}

SelectBox.prototype.ChangeValue = function(value, title)
{
	this.topValue.innerHTML = title;
	this.hidden.value = value;
}

SelectBox.prototype.ChangeSelected = function ()
{
	var self = this;
	for ( var i=0; i<this.option.length; i++ )
	{
		this.option[i].cl = this.option[i].className;
		this.option[i].onclick = function()
		{
			var str = this.id;
			str = str.substr( 1, str.length-1 );
			self.ChangeValue(str, this.firstChild.data);
			if ( this.cl=='selectli' )
			{
				document.getElementById( 'price' ).innerHTML = str;
			}
		}
		this.option[i].onmouseover = function()
		{
				this.className = 'mouseover';
		}
		this.option[i].onmouseout = function()
		{
				this.className = this.cl;
		}
	}
}

SelectBox.prototype.RootClicker = function (ev)
{
	var obj = this.getElementsByTagName('ul')[0];
	if (obj.style.display != 'block')
	{
		HideSelect();
		flag = true;
		curentlySelect = obj;
		curentlySelect.father = this;
		obj.style.display = 'block';
		obj.style.width = (obj.parentNode.offsetWidth-12)+"px";
		document.body.onclick = HideSelect;
		(window.event) ? event.cancelBubble = true : ev.stopPropagation();
	}
	this.className = "select focus";
}

var selectsArray = new Array();

initSelects = function()
{
	var selects = document.getElementsByTagName( "DIV" );
	var count = selects.length;
	var c = 0;
	var cnt = 0;
	while( cnt<count )
	{
		if ( selects[cnt] && selects[cnt].className=="select" )
		{
			var id = selects[cnt].id;
			id = id.substr( 0, id.length-6 );
			selectsArray[c] = new SelectBox( id+'Select', id+'Input' );
			selectsArray[c].GetValue();
			selectsArray[c].root.style.zIndex = 999-c;
			c ++;
		}
		cnt++;
	}
};

// End.