/**
*
* egDropDownPropertyList Class
*/
function egDropDownPropertyList(id, posX, posY, width, height, container, value, selectionType) {
	 this.objName = 'dropDownPropertyList_'+id;
	 this.id = id;
	 this.selectedItem = null;
   this.selectedItemIndex = null;
	 this.preSelectedItem = value;
	 this.selectionType = selectionType; /* 'INDEX', 'LABEL'  */
	 this.tabsContainers = new Array();
	 this.x = posX;
	 this.y = posY;
	 this.width = 0;
	 this.height = 0;
	 this.tabs = 0;


	 this.getHeight = egWindow_getHeight;
	 this.getWidth  = egWindow_getWidth;

	 this.show = egWindow_show;
	 this.hide = egWindow_hide;
	 this.moveTo = egWindow_moveTo;
	 this.displayAt = egWindow_displayAt;

	 this.oldBoxName = null;
	 this.itemsList = new Array();


	 this.addListItem = egDropDownPropertyList_addListItem;
	 this.showList = egDropDownPropertyList_showList;
	 this.hideList = egDropDownPropertyList_hideList;
	 this.setPressed = egDropDownPropertyList_setPressed;
	 this.setUnPressed = egDropDownPropertyList_setUnPressed;
	 this.setActive = egDropDownPropertyList_setActive;
	 this.setInactive = egDropDownPropertyList_setInactive;
	 this.selectListItem = egDropDownPropertyList_selectListItem;


	 this.maxHeight = 200;
	 
   if (!container) {
      container = 'easy-GUI_mainLayer';
   }

	 divRoot = document.getElementById(container);

	 divRoot.innerHTML += '<div id="'+this.id+'" class="egDropDownListBoxFrame" style="z-index: 200;">'
		+'	<div class="egDropDownBoxFrame">'
		+'		<div id="'+this.id+'_box" class="egDropDownTextBox" onmouseover="javascript:' + this.objName + '.setActive(document.getElementById(\''+this.id+'_button\'));" onmouseout="javascript:' + this.objName + '.setInactive(document.getElementById(\''+this.id+'_button\'));" onmousedown="javascript:' + this.objName + '.setPressed(document.getElementById(\''+this.id+'_button\'));" onclick="javascript:cancelBubble(arguments[0]);" onmouseup="javascript:' + this.objName + '.setUnPressed(document.getElementById(\''+this.id+'_button\'));">'
		+'				<div style="position: absolute;"></div>'
		+'		</div>'
		+'		<div id="'+this.id+'_button" class="egDropDownButton" onmouseover="javascript:' + this.objName + '.setActive(this);" onmouseout="javascript:' + this.objName + '.setInactive(this);" onmousedown="javascript:' + this.objName + '.setPressed(this);" onclick="javascript:cancelBubble(arguments[0]);" onmouseup="javascript:' + this.objName + '.setUnPressed(this);"></div>'
		+'	</div>'
		+'	<div id="'+this.id+'_list" class="egDropDownList" style="display: none; overflow: auto; max-height: ' + this.maxHeight + 'px;"></div>'
		+'</div>';

	 div = document.getElementById(this.id);
	 div.style.width = width+'px';
	 div.style.left = posX+'px';
	 div.style.top  = posY+'px';
	 div = document.getElementById(this.id+'_box');
	 div.style.width = (width-17)+'px';
	 div = document.getElementById(this.id+'_button');
	 div.style.right = '1px';
}

function egDropDownPropertyList_addListItem(title, container, action) {
  divBox = document.getElementById(this.id+'_box');
  divList = document.getElementById(this.id+'_list');
  display = 'none';

  if(this.selectionType == 'INDEX' && parseInt(this.preSelectedItem) === this.tabs) {
    this.selectedItem = this.tabs;
    display = 'block';
    this.oldBoxName = this.id+'_list_item_'+this.tabs+'_box';
  }

  if(this.selectionType == 'LABEL' && this.preSelectedItem == title) {
    this.selectedItem = this.tabs;
    display = 'block';
    this.oldBoxName = this.id+'_list_item_'+this.tabs+'_box';
  }

  divBox.innerHTML += '<div id="'+this.id+'_list_item_'+this.tabs+'_box" style="display: '+ display +'; position: absolute;">'+title+'</div>';
  divList.innerHTML += '<div id="'+this.id+'_list_item_'+this.tabs+'" class="egDropDownListItem" onmouseover="javascript:' + this.objName + '.setActive(this);" onmouseout="javascript:' + this.objName + '.setInactive(this);" onmouseup="javascript:' + this.objName + '.selectListItem(this, ' + this.tabs + ');' + action + ';">'+title+'</div>';
	this.tabsContainers[this.tabs] = container;
  this.tabs++;
}

function egDropDownPropertyList_showList(){
	egHideDropDownListBox();
	egDropDownListBoxObject = this;
	var div = document.getElementById(this.id+'_list');
	div.style.display = 'block';
	if(div.offsetHeight > this.maxHeight){
		div.style.height = this.maxHeight+'px';
	}
}

function egDropDownPropertyList_hideList(){
	document.getElementById(this.id+'_list').style.display = 'none';
}

function egDropDownPropertyList_setPressed(item){
  var pos = 0;

	if( (pos = item.className.indexOf('Pressed')) < 0 ) {
		item.className = item.className + 'Pressed';
	}
	this.showList();
}

function egDropDownPropertyList_setUnPressed(item){
	var pos = 0;

	if( (pos = item.className.indexOf('Pressed')) > 0 ) {
		item.className = item.className.substring(0, pos);
	}
}

function egDropDownPropertyList_setActive(item){
	var pos = 0;

	if( (pos = item.className.indexOf('Hover')) < 0 ) {
		item.className = item.className + 'Hover';
	}
}

function egDropDownPropertyList_setInactive(item){
	var pos = 0;

	if( (pos = item.className.indexOf('Hover')) > 0 ) {
		item.className = item.className.substring(0, pos);
	}
}

function egDropDownPropertyList_hideList(){
	document.getElementById(this.id+'_list').style.display = 'none';
}

function egDropDownPropertyList_selectListItem(item, index){
	boxName = item.id + '_box';
	if(this.oldBoxName) {
		document.getElementById(this.oldBoxName).style.display = 'none';
	}
	document.getElementById(boxName).style.display = 'block';
	this.oldBoxName = boxName;

	var itemMark = this.id+'_list_item_';

	if( (pos = item.id.indexOf(itemMark)) >= 0 ) {
		this.selectedItem = item.id.substring(itemMark.length);
	}

	this.hideList();

	if(this.selectedItem) {
		if(this.tabsContainers[this.selectedItemIndex]) {
			document.getElementById(this.tabsContainers[this.selectedItemIndex]).style.display = 'none';
		}
	}
	if(this.tabsContainers[index]) {
		document.getElementById(this.tabsContainers[index]).style.display = 'block';
	}

	this.selectedItem = item;
	this.selectedItemIndex = index;
}