/*
 | create your own build method to fit your menu design
 |
 | send questions to jchu@yahoo-inc.com
 */
 
/*
 | constructor
 | param: id - an identifier, w - width of the menu
 */ 
function ylib_List(id, w) {
 this.name=id;
 this.id = id+'_List';
 eval(_proxy_jslib_proxify_js((this.id+"=this"), 0, 0) );
 
 this.menu = null;
 this.items = new (Array)();
 this.h = 0;
 this.w = w;
 this.isOpen = 0;
 this.multiSelect = 0;
 this.isChild = 0;
 this.selectedIdx = null;
 this.pmenuIdx = null;
 this.pmenuItemIdx = null;
 this.lnk = '';
 this.css = '';
 this.div = '';
 this.color = new (Object)();

 this.add = ylib_listAdd;
 this.init = ylib_listInit;
 this.over = ylib_listOver;
 this.out = ylib_listOut;
 this.down = ylib_listDown; 
 this.select = ylib_listSelect;
 this.deselect = ylib_listDeselect;
 this.turnOn = ylib_listTurnOn;
 this.turnOff = ylib_listTurnOff ;
 this.sLink = ylib_listSetLink;
 this.onSelect = _proxy_jslib_new_function();
 this.build = _proxy_jslib_new_function();
}

/*
 | items (array) [text, value]
 | p - parent menu index, index instead of object b/c of performance concern
 | idx - parent menu item index
 */
function ylib_listAdd(items,p,idx) {
 if (items==null) return;
 if (p!=null) {
   this.pmenuIdx = p;
   this.pmenuItemIdx = idx;
   this.isChild=1;
 }
 var l = items.length;
 for (var i=0; i<l; i++) {
    _proxy_jslib_assign('', this.items, (i), '=', ( new (Array)()));
    _proxy_jslib_handle(this.items, (i), 0, 0).selected = 0;
    _proxy_jslib_handle(this.items, (i), 0, 0).hasChild = 0;
    _proxy_jslib_handle(this.items, (i), 0, 0).childIdx = -1;
    _proxy_jslib_handle(this.items, (i), 0, 0).text =  _proxy_jslib_handle(items, (i), 0, 0)[0];
    _proxy_jslib_assign('',  _proxy_jslib_handle(this.items, (i), 0, 0), 'value', '=', (  _proxy_jslib_handle(items, (i), 0, 0)[1]));
    _proxy_jslib_handle(this.items, (i), 0, 0).lnk = '<a href="'+ _proxy_jslib_handle(items, (i), 0, 0)[1]+'"  onfocus="'+this.id+'.over('+i+')" onblur="'+this.id+'.out('+i+')">'+ _proxy_jslib_handle(items, (i), 0, 0)[0]+'</a>';
    _proxy_jslib_handle(this.items, (i), 0, 0).y = this.h;
   this.h += this.itemH;
 } 
}

function ylib_listInit() {
  // activate each item
  var oItem=null;
  this.handle = ylib_getObj(this.id+this.handle);
  for (var i=0; i<this.items.length; i++) {
    oItem = ylib_getObj(this.id+i);
    // set mouseevents
    ylib_addEvt(oItem, "mouseover", _proxy_jslib_new_function(this.id+".over("+i+")"),false);
    ylib_addEvt(oItem, "mouseout", _proxy_jslib_new_function(this.id+".out("+i+")"),false);
    if (oBw.ns) oItem.captureEvents(Event.MOUSEDOWN)  
 ylib_addEvt(oItem, "mousedown", _proxy_jslib_new_function(this.id+".down("+i+")"),false);
  }
}

function ylib_listOver(idx) {
  if (this.menu&&this.menu.hideTimerID!=null) { clearTimeout(this.menu.hideTimerID); this.menu.hideTimerID=null; }
  if (! _proxy_jslib_handle(this.items, (idx), 0, 0).selected) { this.turnOn(ylib_getObj(this.id+idx));	}

  if (this.isOpen && idx!=this.selectedIdx) {
    if (this.menu!=null) this.menu.hide(this); // close menus when rolling over other items in the parent menu
    this.deselect(this.selectedIdx);
    if ( _proxy_jslib_handle(this.items, (idx), 0, 0).hasChild) this.select(idx);
  }
}

function ylib_listOut(idx) {
 if (! _proxy_jslib_handle(this.items, (idx), 0, 0).selected) { this.turnOff(ylib_getObj(this.id+idx)) }
 if (this.isChild) this.menu.hideMenu();
}

function ylib_listDown(idx) { 
  _proxy_jslib_assign('',  _proxy_jslib_handle(window, 'location', '', 0, 0), 'href', '=', (  _proxy_jslib_handle( _proxy_jslib_handle(this.items, (idx), 0, 0), 'value', '', 0, 0)));
 return false;
}

function ylib_listSelect(idx) {
  var oItem =  _proxy_jslib_handle(this.items, (idx), 0, 0)
  if (oItem==null) return;
  oItem.selected = 1;
  this.selectedIdx = idx;
  this.onSelect(ylib_getObj(this.id+idx));
}

function ylib_listDeselect(idx) {
  oItem =  _proxy_jslib_handle(this.items, (idx), 0, 0);
  if (oItem==null) return;
  oItem.selected = 0;
  this.turnOff(ylib_getObj(this.id+idx));
  this.selectedIdx = null
}

function ylib_listTurnOn(o) {
 ylib_setStyle(o,"backgroundColor",this.color.onBg);
 this.sLink(o,true);
}

function ylib_listTurnOff(o) {
 ylib_setStyle(o,"backgroundColor",this.color.offBg);
 this.sLink(o,false);
}

function ylib_listSetLink(o,isOver) {
 if(oBw.win && (oBw.ie||oBw.dom)) {
  lnk= _proxy_jslib_handle(o, 'getElementsByTagName', '', 1, 0)("a");
  lnk[0].style.textDecorationUnderline=isOver;
  this.lnk= (isOver)?  _proxy_jslib_handle(lnk[0], 'href', '', 0, 0):"";
 }
}
 ;
_proxy_jslib_flush_write_buffers() ;