// JScript source code

var iGroupCount=0;
var iItemCount=0;
var oWorkItem="";
var oDistinctMenu="";
var oDistinctGroup="";
var bOpenMenu=false;
var sScratchInclude='<div component="scratch" class=scratchx>DHTML Menu Sample #1</div>';
function fnInit(){
  return;
	oMenuContainer.style.setExpression("width","document.body.clientWidth-2");
	oMenuContainer.innerHTML='<div id=oScratch class="scratch"></div>';
	oScratch.style.top=document.body.clientHeight/2 - oScratch.offsetHeight/2;
	oScratch.style.left=document.body.clientWidth/2 - oScratch.offsetWidth/2;
	oScratch.innerHTML=sScratchInclude;
	fnAddMenuGroup("Account");
	fnAddMenuItem(1,"Log In","fnAccountLogin","document2");
	fnAddMenuItem(1,"Update Account Information","fnAccountUpdate","document2");
	fnAddMenuItem(1,"Create Account","fnAccountCreate","document2");
	fnAddMenuGroup("Items");
	fnAddMenuItem(2,"View/Edit","fnItemsViewEdit","document2");
	fnAddMenuItem(2,"Add","fnItemsAdd","document2");
	fnAddMenuItem(2,"~SPACER","Invalid");
	fnAddMenuItem(2,"Report Stolen","fnItemsStolen","document2");
	fnAddMenuItem(2,"Report Recovered","fnItemsRecovered","document2");
	fnAddMenuItem(2,"Report Sold","fnItemsSold","document2");
	if(oMenuContainer.innerHTML!=""){
		oMenuContainer.style.height=oLabel1.offsetHeight + oLabel1.offsetTop + 4;
	}
}

function fnSwitchMenu(){
	oWorkItem=event.srcElement;
	if(oWorkItem.component=="menulabel"){
		if((oDistinctMenu!=oWorkItem)&&(oDistinctMenu!="")){
			oDistinctGroup=eval("oGroup" + oDistinctMenu.groupid);
			oDistinctGroup.style.display="none";
			oDistinctMenu.menustatus="closed";
			oDistinctMenu.className="menulabel";
		}
		oDistinctMenu=oWorkItem;
		oDistinctGroup=eval("oGroup" + oWorkItem.groupid);
		if(oDistinctMenu.menustatus=="closed"){
			oDistinctMenu.menustatus="open";	
			oDistinctMenu.className="menulabel3";
			oDistinctGroup.style.display="block";
			if(bOpenMenu==false){
				bOpenMenu=true;
				oMenuContainer.setCapture();
			}
		}
		else{
			bOpenMenu=false;
			oMenuContainer.releaseCapture();
			oDistinctMenu.menustatus="closed";
			oDistinctGroup.style.display="none";
		}
	}
	if(oWorkItem.component=="menuitem"){
		if(oWorkItem.menuaction!="Invalid"){
			eval(oWorkItem.menuaction + "()");
		}
		oMenuContainer.releaseCapture();
		oDistinctMenu.click();
		oDistinctMenu.className="menulabel";
	}
	if(!oWorkItem.component){
		if(bOpenMenu==true){
			oDistinctMenu.className="menulabel";
			oMenuContainer.releaseCapture();
			oDistinctMenu.click();
			event.returnValue=false;
		}
	}
	if(oWorkItem.component=="scratch"){
		oScratch.style.display="none";
	}
}

function fnHighlight(){
	if((event.clientX>0)&&(event.clientY>0)&&(event.clientX<document.body.offsetWidth)&&(event.clientY<document.body.offsetHeight)){
		oWorkItem=event.srcElement;
		if(oWorkItem.component=="menulabel"){
			if(oWorkItem.className=="menulabel"){
				oWorkItem.className="menulabel2";
				if((oDistinctMenu!="")&&(oDistinctMenu.menustatus=="open")){
					fnSwitchMenu(oWorkItem);
					event.returnValue=false;
				}
			}
			else{
				if(oWorkItem.menustatus=="closed"){
					oWorkItem.className="menulabel";
				}
			}
		}
		if(oWorkItem.component=="menuitem"){
			if(oWorkItem.menustatus!="active"){
				oWorkItem.style.borderBottomColor="#505050";
				oWorkItem.style.borderRightColor="#505050";
				oWorkItem.style.borderTopColor="#CFCFCF";
				oWorkItem.style.borderLeftColor="#CFCFCF";
				oWorkItem.menustatus="active";
			}
			else{
				oWorkItem.style.borderColor="#000000";
				oWorkItem.menustatus="passive";
			}
		}
	}
	else{
		if((oDistinctMenu!="")&&(oDistinctMenu.menustatus=="open")){
			fnSwitchMenu();
			oDistinctMenu.className="menulabel";
			event.returnValue=false;
		}
	}
}

function fnAddMenuGroup(sGroupName){
	iGroupCount++;
	oMenuContainer.innerHTML+='<span groupid=' + iGroupCount + ' component="menulabel" id=oLabel' + iGroupCount + ' class="menulabel">' + sGroupName + '</span><div id=oGroup' + iGroupCount + ' class="menugroup"></div>';
	var oNewLabel=eval("oLabel" + iGroupCount);
	var oNewGroup=eval("oGroup" + iGroupCount);
	fnAlign(oNewLabel,oNewGroup);
}

function fnAlign(oLabel,oGroup){
	oLabel.menustatus="closed";
	oLabel.style.top=2;
	oLabel.style.left=75 * (iGroupCount-1) + 2;
	oGroup.style.top=oLabel.offsetHeight + oLabel.offsetTop+2;
	oGroup.style.left=oLabel.offsetLeft;
	oGroup.style.display="none";
}

function fnAddMenuItem(iGroupId,sItemName,sItemAction,sItemImage){
	iItemCount++;
	var sTmpSrc="";
	if(sItemImage + ""=="undefined"){
		sTmpSrc="canvas.gif";
	}
	else{
		sTmpSrc=sItemImage + ".gif";
	}
	var oNewGroup=eval("oGroup" + iGroupId);
	if(sItemName.indexOf("~")==-1){
		oNewGroup.innerHTML+='<span groupid=' + iGroupId + ' component="menuitem" id="oItem' + iItemCount + '" itemid=' + iItemCount + ' menuaction="' + sItemAction + '"> <img id="oItemImg' + iItemCount + '" src="/workshop/graphics/' + sTmpSrc + '" width=15 height=15 alt="">' + sItemName + '</span><br>';
		var oNewItem=eval("oItem" + iItemCount);
		oNewItem.style.fontSize="12";
		oNewItem.style.cursor="hand";
		oNewItem.style.backgroundColor="#000000";
		oNewItem.style.color="#FFFFFF";
		oNewItem.style.textDecoration="none";
		oNewItem.style.marginLeft="5px";
		oNewItem.style.width=parseInt(oNewGroup.currentStyle.width) - 15;
		oNewItem.style.border="1 solid";
		oNewItem.style.borderColor="#000000";
	}
	if(sItemName=="~SPACER"){
		oNewGroup.innerHTML+='<hr>';
	}
}

// These functions provide the ACTION for menu items.

function fnAccountLogin(){
    var x = 1;
}

function fnAccountUpdate(){
    var x = 1;
}

function fnAccountCreate(){
    var x = 1;
}

function fnItemsViewEdit(){
    var x = 1;
}

function fnItemsAdd(){
    var x = 1;
}

function fnItemsStolen(){
    var x = 1;
}

function fnItemsRecovered(){
    var x = 1;
}

function fnItemsSold(){
    var x = 1;
}
