function f_c_startMenu( top, left, menuArray){

	o_winManager.o_taskbar.startButton = new f_c_button( START_BUTTON_CONTENT, UP, "butUp1", "butDown1", START_BUTTON_WIDTH, BUTTON_HEIGHT, BUTTON_TOP, START_BUTTON_LEFT, o_winManager.o_taskbar.taskbarWin.htmlFrameObj, null);
	o_winManager.o_taskbar.startButton.onmousedown = function(event){
		o_winManager.o_taskbar.taskbarWin.htmlFrameObj.f_register_for_repaint();
		event.cancelBubble = true;
		event.preventDefault();
	}
	o_winManager.o_taskbar.startButton.htmlObj.onmouseup = null;

	this.top  					= top;
	this.left 					= left;
	this.state					= false;
	if(!f_c_startMenu.menu){ 
		f_c_startMenu.menu = [];
	}
	f_c_startMenu.menu[f_c_startMenu.menu.length] = this;
	
	this.menuId					= f_c_startMenu.menu.length - 1;
	this.lists 					= [];
	this.menuArray 			= menuArray;
	this.construct();
}

f_c_startMenu.MENU_ARRAY_ID_INDEX		= 0;
f_c_startMenu.MENU_ARRAY_TEXT_INDEX		= 1;
f_c_startMenu.MENU_ARRAY_IMAGE_INDEX	= 2;
f_c_startMenu.MENU_ARRAY_CLASS_INDEX	= 3;
f_c_startMenu.MENU_ARRAY_ACTION_INDEX	= 4;
f_c_startMenu.BASE_MENU_ID 				= "main";

f_c_startMenu.prototype.releaseMenu = function(){
	for(var i in this.lists){
		if(this.lists[i].window)
			this.lists[i].window.del();
	}
	Item.unRegisterItems();
	f_c_startMenu.menu = [];
	o_winManager.o_taskbar.startButton.del();
}

f_c_startMenu.prototype.construct = function(){
	var menuHTML = "";
	for(var i in this.menuArray){
		if(i == "item")
			break;
		if(i == f_c_startMenu.BASE_MENU_ID){
			this.lists[i] = this.baseStartMenu = new List( this, i, List.BASE_MENU, this.top, this.left);
		}
		else{
			this.lists[i] = new List( this, i, List.REGULAR_MENU, this.top, this.left);
		}
	}

	for(var i in this.menuArray){
		if(i == "item")
			break;
		this.lists[i].construct();
	}
}

f_c_startMenu.prototype.close = function(){
	if(this.baseStartMenu.selectedItem && this.baseStartMenu.selectedItem.childList)
		this.baseStartMenu.selectedItem.childList.close();
	this.state				= false;
	o_winManager.o_taskbar.startButton.f_buttonUp();
	this.baseStartMenu.hide();
}

f_c_startMenu.prototype.open = function(){
	this.state				= true;
	this.baseStartMenu.show( this.left, this.top);
	o_winManager.o_taskbar.startButton.f_buttonDown();
}

function List( menu, listId, type, top, left){
	this.top  				= top;
	this.left 				= left;
	this.menu 				= menu;
	this.id 					= "L" + List.counter++;
	this.type				= type;
	this.parentItem		= null;
	this.selectedItem		= null;
	this.className			= null;
	this.listArray			= menu.menuArray[listId];
	if( this.type == List.BASE_MENU){
		this.className	= List.BASE_MENU_CLASS;
	}
	else{
		this.className	= List.SUBMENU_CLASS;
	}
	this.window				= null;
}

List.BASE_MENU_CLASS 	= "menu";
List.SUBMENU_CLASS 		= "subf_c_startMenu";
List.BASE_MENU				= 1;
List.REGULAR_MENU			= 2;
List.counter				= 0;

List.prototype.construct = function(){
	var len 	= this.listArray.length;
	var ar 	= this.listArray;
	this.html = "";
	this.html += 	frame_style1 + "<body onselectStart='return false' class=start_menu topmargin=0 leftmargin=0 scroll=no style='margin:0;padding:0;overflow:hidden'>\n"+
						"<table width=" + START_MENU_WIDTH + "  border=0 cellspacing=0 cellpadding=0>\n" +
						"<tr>";
	if(this.type == List.BASE_MENU)
		this.html += "<td rowspan=100 width=20 valign=top style='background-image:url(" + location.protocol + "//" + location.host + "/images/start_menu_left2.gif);background-repeat:no-repeat'><img id=startMenuIcon src="+ location.protocol + "//" + location.host +"/images/spacer.gif width=20 height=20></td>\n";
	for( var i=0; i < len; i++){
		try{
			this.html += (new Item( this, ar[i], this.id)).construct();
		}
		catch(e){}
	}
	this.html += "</tr></table></body>\n";
}

List.prototype.visualConstruct = function(left, tp){
	top.html = this.html;
	this.window = new f_c_window( "javascript:top.html", START_MENU_ITEM_HEIGHT * this.listArray.length, START_MENU_WIDTH, tp, left, "style_outerWindowStartMenu", window, null, true, START_MENU_ZINDEX++);
}

List.prototype.show = function(x, y){
	if(this.window){
		this.window.show();
		this.window.moveTo( x, y);
	}
	else{
		this.visualConstruct( x, y);
	}
}

List.prototype.hide = function(){
	if(this.window)
		this.window.hide();
}

List.prototype.open = function( fromItem, fromHTMLElement){ //fromItem -> HTMLElement
//
//	if(!this.isVisible())
//		return;
//	
	
	var coords = Item.getObjectCoords( fromHTMLElement);

	
	this.show(	coords[0] + parseInt(fromItem.parentList.window.htmlLayerObj.style.left) + fromHTMLElement.offsetWidth, 
					coords[1] + parseInt(fromItem.parentList.window.htmlLayerObj.style.top));
	this.parentItem = fromItem;
	for(var i=0; i < f_c_startMenu.menu.length; i++){
		if(this.menu == f_c_startMenu.menu[i])
			continue;
		f_c_startMenu.menu[i].close();
	}
}

List.prototype.close = function(){
	if( this.selectedItem && this.selectedItem.childList)
		this.selectedItem.childList.close();
	this.selectedItem = null;
	
	this.hide();
	
	if(this.parentItem){
		this.parentItem.putOff();
		this.parentItem = null;
	}
}

List.prototype.isVisible = function(){
	return this.window.isVisible;
}

List.prototype.moveTo = function( x, y){
	this.window.moveTo(x, y);
}

List.prototype.putOn = function(){}
List.prototype.putOff = function(){}

function Item( parentList, menuArray, listIndex, HTMLelement){
	this.HTMLelement				= HTMLelement;
	this.id 							= Item.registerItem(listIndex, this);
	this.action						= function(){ 
												try{
													menuArray[ f_c_startMenu.MENU_ARRAY_ACTION_INDEX]();
												}
												catch(e){}
											};
	this.listIndex					= listIndex;
	this.menu						= parentList.menu;
	this.parentList 				= parentList;
	this.menuArray					= menuArray;
	this.OFF_CLASS 				= menuArray[ f_c_startMenu.MENU_ARRAY_CLASS_INDEX];
	this.ON_CLASS 					= menuArray[ f_c_startMenu.MENU_ARRAY_CLASS_INDEX] + "_on";

	this.childList 				= this.menu.lists[ menuArray[ f_c_startMenu.MENU_ARRAY_ID_INDEX]];
}

Item.prototype.construct = function(){
	var el = "";
	if(this.id == "i0"){
		el += "<td class=" + this.OFF_CLASS;
		el += " height=" + START_MENU_ITEM_HEIGHT;
		el += " width=100%";
		el += " nowrap id=" + this.id;
		el += " onmouseover='top.Item.onMouseOver(this,event)'";
		el += " onmouseout='top.Item.onMouseOut(this,event)'";
		el += " onclick='top.Item.onClick(this)' onselectstart='return false'";
		el += " listId='" + this.listIndex + "'>";
		el += this.menuArray[ f_c_startMenu.MENU_ARRAY_TEXT_INDEX];
		el += "<img src=" + ( this.childList ? START_MENU_POINTER.src : window[this.menuArray[ f_c_startMenu.MENU_ARRAY_IMAGE_INDEX]].src );
		el += " width=25 height=25 vspace=1 align=absmiddle style='margin-left:8px;' ondragstart='return false'></td>\n";
	}
	else{
		el += "</tr><tr><td class=" + this.OFF_CLASS;
		el += " height=" + START_MENU_ITEM_HEIGHT;
		el += " width=100%";
		el += " nowrap id=" + this.id;
		el += " onmouseover='top.Item.onMouseOver(this,event)'";
		el += " onmouseout='top.Item.onMouseOut(this,event)'";
		el += " onclick='top.Item.onClick(this)'";
		el += " listId='" + this.listIndex + "'>";
		el += this.menuArray[ f_c_startMenu.MENU_ARRAY_TEXT_INDEX];
		el += "<img src=" + ( this.childList ? START_MENU_POINTER.src : window[this.menuArray[ f_c_startMenu.MENU_ARRAY_IMAGE_INDEX]].src );
		el += " width=25 height=25 vspace=1 align=absmiddle style='margin-left:8px;' ondragstart='return false'></td>\n";
	}
	return el;
}

Item.prototype.executeAction = function(){
	this.action();
	top.f_repaint();
}

Item.prototype.putOn = function(){
	this.parentList.window.htmlFrameObj.document.getElementById(this.id).className = this.ON_CLASS;
	this.parentList.putOn( this);
}

Item.prototype.putOff = function(){
	this.parentList.window.htmlFrameObj.document.getElementById(this.id).className = this.OFF_CLASS;
	this.parentList.putOff( this);
}

Item.counter = [];
Item.onMouseOver = function( HTMLelement, e){
	var item = Item.items[HTMLelement.getAttribute("listId")][HTMLelement.id];

	if(item.parentList.selectedItem && item.parentList.selectedItem.childList)
		item.parentList.selectedItem.childList.close();
	if(item.childList){
		item.childList.open( item, HTMLelement);
	}
	item.parentList.selectedItem = item;
	if(item.parentList.parentItem)
		item.parentList.parentItem.putOn();
	item.putOn();
}

Item.onMouseOut = function( HTMLelement, e){
	var item = Item.items[HTMLelement.getAttribute("listId")][HTMLelement.id];
	item.putOff();
}

Item.onClick = function( HTMLelement){
	Item.items[HTMLelement.getAttribute("listId")][HTMLelement.id].executeAction();
}

Item.registerItem = function(listId, item){
	var id;
	if(!this.items){
		this.items = [];
	}
	if(!this.items[listId]){
		this.items[listId] = [];
	}
	if(!this.counter[listId]){
		this.counter[listId] = 0;
	}
	
	id = "i" + this.counter[listId];
	this.items[listId][id] = item;
	this.counter[listId]++;
	return id;
}

Item.unRegisterItems = function(){
	this.items = [];
}

Item.getObjectCoords = function( HTMLelement){
   var o 		= HTMLelement;
   var accTop  = o.offsetTop;
   var accLeft = o.offsetLeft;
   
	while((o = o.offsetParent) != null){
		accTop  += o.offsetTop;
		accLeft += o.offsetLeft;
	}
	return [parseInt(accLeft), parseInt(accTop)];
}
