//BEGIN CLASS Menustrip
//public
function Menustrip(q_OnSelectMenuitem){
if(Menustrip_ok(q_OnSelectMenuitem)){
	//Public Methods
	this.paint=Menustrip_paint;
	this.OnSelectMenuitem=q_OnSelectMenuitem;
	this.setMenuitem=Menustrip_setMenuitem;
	this.disableMenuitem=Menustrip_disableMenuitem;
	this.removeMenuitem=Menustrip_removeMenuitem;
	this.setProgress=Roller_setprogress;
	this.setStatus=Roller_setstatus;
	this.resize=Menustrip_resize;
	this.doAccesskey=Menustrip_doAccesskey;
	this.getKeycommand=Menustrip_getKeycommand;
	this.auditMenus=Menustrip_auditMenus;
}//end if
}//end function

function Menustrip_ok(q_OnSelectMenuitem){
if((q_OnSelectMenuitem)){
	return true;
}else{
	alert("Menustrip error: All event functions must be defined.");
	return false;
}//end if
}//end function

//public
function Menustrip_paint(q_obj,q_menulist,q_roller,q_imgbase){
//initializes the Menustrip graphics
//matches with _html function

if(Menustrip_paint_ok(q_obj,q_menulist)){
	//create the object in the target region
	q_obj.onclick=Menustrip_OnClick;
	q_obj.mainobject=this;
	//Private object pointers
	this.myImgbase=q_imgbase;
	this.myContainer=q_obj;
	this.myMenulist=q_menulist;
	this.myRoller=q_roller;
	var graphicshtml=Menustrip_html(q_obj,q_menulist,this.myImgbase);
	if(q_roller==true){
		graphicshtml=graphicshtml+Roller_html(this.myImgbase);
	}//end if
	q_obj.innerHTML=graphicshtml;
	q_menu=document.getElementById("Menustrip_menu");
	q_menu.myMenunumber=-1;
	var q_objectname=q_obj.id;
	if(navigator.userAgent.indexOf("Gecko")){
		var q_doc=document;//Netscape problem, cant find the parent document like IE does.
	}else{
		var q_doc=q_obj.document;//better way
	}//end if
	this.myTable=q_doc.getElementById(q_objectname + "_Table");	
	return "";
}//end if
}//end function
function Menustrip_paint_ok(q_obj,q_menulist){
//initializes the Menustrip graphics
//matches with _html function
if(q_obj){
}else{
	alert("Menustrip_paint error: Destination layer must be present before initializing.");
	return false;
}//end if
if(q_menulist.length==0){
	alert("Menustrip_paint error: Menustrip content requires a menulist.");
	return false;
}//end if
return true;
}//end function

//public
function Menustrip_setMenuitem(q_old,q_new){
for (var q_r=0;q_r<this.myMenulist.length;q_r++){
for (var q_c=0;q_c<this.myMenulist[q_r].length;q_c++){
	if(this.myMenulist[q_r][q_c]==q_old){
		this.myMenulist[q_r][q_c]=q_new;
	}//end if
}//next
}//next
}//end function

//public
function Menustrip_disableMenuitem(q_old,q_title){
var q_old2=q_old.replace("_","");
q_title=replace(q_title," ","");
for (var q_r=0;q_r<this.myMenulist.length;q_r++){
for (var q_c=0;q_c<this.myMenulist[q_r].length;q_c++){
	if(this.myMenulist[q_r][q_c].replace("_","")==q_old2){
		this.myMenulist[q_r][q_c]="<font color=gray title="+q_title+">"+q_old+"</font>";
	}//end if
}//next
}//next
}//end function

//public
function Menustrip_removeMenuitem(q_old){
for (var q_r=0;q_r<this.myMenulist.length;q_r++){
for (var q_c=0;q_c<this.myMenulist[q_r].length;q_c++){
	if(Menustrip_namesEqual(this.myMenulist[q_r][q_c],q_old)){
		arrayDelete(this.myMenulist[q_r],q_c);
	}//end if
}//next
}//next
}//end function

function Menustrip_namesEqual(a,b){
return (a.toLowerCase().replace("_","")==b.toLowerCase().replace("_",""));
}//end function

//private
function Menustrip_html(q_obj,q_menulist,q_imgbase){
//renders an empty Menustrip with scale, titles and grid. This does not create the object
//type layerproperties=Array(name,visibility,left,top,width,height,src)
//q_html="<table style='font:menu;' cellspacing=0><tr>";
q_html="<table style='font-family:Tahoma,Arial,Helvetica,Verdana; font-size:11px;' cellspacing=0><tr>";
q_left=0;
for (i=0;i<q_menulist.length;i++){
//q_html=q_html+replace(d,"z_val",q_menulist[i][0]);
q_width=q_menulist[i][0].length*5.5;

q_html=q_html+"<td style='width:"+q_width+"px; padding: 3px 8px 3px 8px;' onmousemove='this.style.cursor=\"default\";this.style.backgroundColor=\"#1030B0\";this.style.color=\"#FFFFFF\";Menustrip_MenuMainRefresh(event,this,\""+i+"\","+q_left+");' onmouseout='this.style.backgroundColor=\"#F0F0F0\";this.style.color=\"#000000\";' onclick='Menustrip_MenuMainClick(event,this,\""+i+"\","+q_left+");'>"+q_menulist[i][0].replace(" ","&nbsp;")+"</td>";
q_left=q_left+q_width+16;
}//next
q_html=q_html+"</tr></table>";

q_html=q_html + "<div id='Menustrip_pynt' style='visibility:visible; left:776px; top:0px; width:248px; height:20px; background-image:url("+q_imgbase+"menustrip_pynt.gif); position:absolute;'></div>";
if(IE()){
	q_html=q_html + "<div id='Menustrip_menu' style='visibility:hidden; left:0px; top:19px; font-family:Tahoma,Arial,Helvetica,Verdana; font-size:11px; background-color:#FFFFFF; position:absolute; border-style:solid; border-width:1px; border-color:#808080; padding: 2px 2px 2px 2px; filter: alpha(opacity=95); filter: progid:DXImageTransform.Microsoft.Alpha(opacity=95); -moz-opacity:0.95;'></div>";
}else{
	q_html=q_html + "<div id='Menustrip_menu' style='visibility:hidden; left:0px; top:19px; font-family:Tahoma,Arial,Helvetica,Verdana; font-size:11px; background-color:#FFFFFF; position:absolute; border-style:solid; border-width:1px; border-color:#808080; padding: 2px 2px 2px 2px; -moz-opacity:0.95;'></div>";
}//end if
return q_html;

}//end function

function Menustrip_resize(q_width,q_scale){
//var q_menustrip=this.container;
if(this.myContainer){
	this.myContainer.style.width=q_width;
}//end if

var q_roller=div("Roller");
if(q_roller){
	var q_left=(q_width-373)/2;
	if(q_left<140){
		q_left=140;
	}//end if
	q_roller.style.left=q_left;
}//end if

var q_obj=div("Menustrip_pynt");
if(q_obj){
	q_obj.style.width=248*q_scale;
	q_obj.style.left=(q_width-q_obj.offsetWidth);
	if(q_roller){
		if(q_obj.offsetLeft<q_roller.offsetLeft+q_roller.offsetWidth){
			q_obj.style.visibility="hidden";
		}else{
			q_obj.style.visibility="visible";
		}//end if
	}//end if
}//end if
}//end function

function Roller_html(q_baseurl){
var q_html="";
q_html=q_html + "<div id='Roller' style='visibility:visible; left:325px; top:1px; width:373px; height:18px; position:absolute; background-image:url("+q_baseurl+"roller.gif);'>\n";
q_html=q_html + "<img id='Rollerplay' src='"+q_baseurl+"rollerplay.gif' style='visibility:visible; left:5px; top:2px; width:18px; height:14px; position:absolute;' onmouseout='touchbut(this);' onmouseover='touchbut(this);' onclick='Roller_onbutton(event,this,\"Play\")' title='Play'>\n";
q_html=q_html + "<img id='Rollerstop' src='"+q_baseurl+"rollerstop.gif' style='visibility:visible; left:28px; top:2px; width:18px; height:14px; position:absolute;' onmouseout='touchbut(this);' onmouseover='touchbut(this);' onclick='Roller_onbutton(event,this,\"Stop\")' title='Stop'>\n";
q_html=q_html + "<img id='Rollerpause' src='"+q_baseurl+"rollerpause.gif' style='visibility:visible; left:50px; top:2px; width:18px; height:14px; position:absolute;' onmouseout='touchbut(this);' onmouseover='touchbut(this);' onclick='Roller_onbutton(event,this,\"Pause\")' title='Pause'>\n";
q_html=q_html + "<img id='Rollerinfo' src='"+q_baseurl+"rollerinfo.gif' style='visibility:visible; left:72px; top:2px; width:18px; height:14px; position:absolute;' onmouseout='touchbut(this);' onmouseover='touchbut(this);'  onclick='Roller_onbutton(event,this,\"Help\")' title='Help'>\n";
q_html=q_html + "<div id='Rollerstatus' style='visibility:visible; left:96px; top:2px; width:180px; height:12px; position:absolute; font-family:Tahoma,Arial; font-size:11px;'></div>\n";
q_html=q_html + "<img id='Rollercover' src='"+q_baseurl+"roller_cover.gif' style='visibility:visible; left:280px; top:3px; width:92px; height:12px; position:absolute;'>\n";
q_html=q_html + "</div>\n";
return q_html;
}//emnd function

function Roller_setprogress(q_percent){
var q_obj=document.getElementById("Rollercover");
if(q_obj){
	if(q_percent){
	}else{
		q_percent=100;
	}//end if
	if(q_percent>100){
		q_wid=0;
	}else if(q_percent<0){
		q_wid=92;
	}else{
		q_wid=92-Math.floor(q_percent*92/100);
	}//end if
	q_obj.style.width=q_wid;
	q_obj.style.left=372-q_wid;
}//end if
}//end function

function Roller_setstatus(q_str){
var q_obj=document.getElementById("Rollerstatus");
if(q_obj){
document.getElementById("Rollerstatus").innerHTML=q_str;
}//end if
}//end function

function Roller_onbutton(event,q_obj,q_menutext){
var q_source=getsrcElement(event);
if(event){
event.cancelBubble=true;
}//end if
q_Menustrip=q_obj.parentNode.parentNode.mainobject;
q_Menustrip.OnSelectMenuitem(q_menutext,q_source);
}//end function

function Menustrip_MenuMainClick(event,q_obj,q_menunumber,q_left){
q_menu=document.getElementById("Menustrip_menu");
if(q_menu.style.visibility=="visible"){
Menustrip_MenuHide();
}else{
	q_me=q_obj.parentNode.parentNode.parentNode.parentNode.mainobject;
	Menustrip_MenuShow(q_me,q_menunumber,q_left);
}//end if
if(event){
event.cancelBubble=true;
}//end if
}//end function

function Menustrip_MenuMainRefresh(event,q_obj,q_menunumber,q_left){
q_menu=document.getElementById("Menustrip_menu");
if(q_menu){
	if((q_menu.style.visibility=="visible")&&(q_menu.myMenunumber!=q_menunumber)){
		q_me=q_obj.parentNode.parentNode.parentNode.parentNode.mainobject;
		Menustrip_MenuShow(q_me,q_menunumber,q_left);
	}//end if
}//end if
if(event){
event.cancelBubble=true;
}//end if
}//end function

function Menustrip_OnClick(event,obj){
Menustrip_MenuHide();
if(event){
event.cancelBubble=true;
}//end if
}//end function

function Menustrip_MenuShow(q_obj,q_menunumber,q_left){
q_menu=document.getElementById("Menustrip_menu");
q_menu.myMenunumber=q_menunumber;
q_menu.style.left=q_left;
q_menu.innerHTML=Menustrip_Menucontent(q_obj.myMenulist[q_menunumber]);
q_menu.style.visibility="visible";
}//end function

function Menustrip_MenuHide(){
q_menu.myMenunumber=-1;
q_menu=document.getElementById("Menustrip_menu");
q_menu.style.visibility="hidden";
}//end function

function Menustrip_Menucontent(q_menulist){
var q_html=new Array();
//q_html[q_html.length]="<table style='font-family:Tahoma,Arial,Helvetica,Verdana; font-size:11px; width:130px;' cellpadding=0 cellspacing=0>";
for (i=1;i<q_menulist.length;i++){

//if(q_menulist[i]=="<hr>"){
//	q_html[q_html.length]="<tr><td colspan=2 style='padding: 0px 3px 0px 3px; '><hr></td></tr>";
//}else if(q_menulist[i].indexOf("<font color=gray>")>-1){	
//	q_html[q_html.length]="<tr><td style='padding: 2px 12px 2px 12px;' onmousemove='this.style.backgroundColor=\"#1030B0\";this.style.color=\"#C0C0C0\";this.style.cursor=\"default\";' onmouseout='this.style.backgroundColor=\"#FFFFFF\";this.style.color=\"#000000\";' >"+q_menulist[i]+"</td><td></td></tr>";
//	q_html=q_html+"<div style='padding: 2px 12px 2px 12px;'>"+q_menulist[i]+"</div>";
//}else{
//	q_html[q_html.length]="<tr><td style='padding: 2px 12px 2px 12px;' onmousemove='this.style.backgroundColor=\"#1030B0\";this.style.color=\"#FFFFFF\";this.style.cursor=\"default\";' onmouseout='this.style.backgroundColor=\"#FFFFFF\";this.style.color=\"#000000\";' onclick='Menustrip_MenuClick(event,this,\""+menuClean(q_menulist[i])+"\");'>"+menuTag(q_menulist[i])+"</td><td width=30>"+menuAlt(q_menulist[i])+"</td></tr>";
//}//end if

if(q_menulist[i]=="<hr>"){
	q_html[q_html.length]="<div style='padding: 0px 3px 0px 3px; width:100px;'><hr></div>";
}else if(q_menulist[i].indexOf("<font color=gray>")>-1){	
	q_html[q_html.length]="<div style='padding: 2px 12px 2px 12px;' onmousemove='this.style.backgroundColor=\"#1030B0\";this.style.color=\"#C0C0C0\";this.style.cursor=\"default\";' onmouseout='this.style.backgroundColor=\"#FFFFFF\";this.style.color=\"#000000\";' >"+q_menulist[i]+"</div>";
	q_html[q_html.length]="<div style='padding: 2px 12px 2px 12px;'>"+q_menulist[i]+"</div>";
}else{
	q_html[q_html.length]="<div style='padding: 2px 12px 2px 12px;' onmousemove='this.style.backgroundColor=\"#1030B0\";this.style.color=\"#FFFFFF\";this.style.cursor=\"default\";' onmouseout='this.style.backgroundColor=\"#FFFFFF\";this.style.color=\"#000000\";' onclick='Menustrip_MenuClick(event,this,\""+menuClean(q_menulist[i])+"\");'>"+menuTag(q_menulist[i])+"</div>";
}//end if

}//next
//q_html[q_html.length]="</table>";
return q_html.join("");
}//end function

function Menustrip_MenuClick(event,q_obj,q_menutext){
var q_source=getsrcElement(event);
if(event){
event.cancelBubble=true;
}//end if
q_Menustrip=q_obj.parentNode.parentNode.mainobject;
Menustrip_MenuHide();

q_Menustrip.OnSelectMenuitem(q_menutext,q_source);
}//end function

function menuTag(q_menutext){
return q_menutext.replace(/(_)([a-z,A-Z])/,"<u>$2</u>");
}//end function

function menuAlt(q_menutext){
//return q_menutext.replace(/(_)([a-z,A-Z])/,"<u>$2</u>");
myRe=/(_)([a-z,A-Z])/;
myArray = myRe.exec(q_menutext);
return (myArray)?"Alt"+myArray[0].replace("_","-"):"";

}//end function

function menuClean(q_menutext){
	return q_menutext.replace("_","");
}//end function

function hasKeycommand(menuitem,k){
if(menuitem>""){
	return menuitem.toLowerCase().indexOf("_"+String.fromCharCode(k).toLowerCase())>-1;
}else{
	return false;
}//end if
}//end function

function Menustrip_doAccesskey(k){
if(window.event){
	if(("13,27,32,37,38,39,40,46,113,").indexOf(k+",")>-1 || window.event.altKey || window.altKey){
		var q_cmd=this.getKeycommand(k);
		if(q_cmd){
			this.OnSelectMenuitem(q_cmd,null);
		}//end if
	}else{
	
	}//end if
}//end if
}//end function

function Menustrip_getKeycommand(k){
switch(k){//37=left 38=up 39=right 40=down
case 13:return "KeyEnter";
case 27:return "KeyEscape";
case 32:return "KeySpace";
case 37:return "KeyArrowleft";
case 38:return "KeyArrowup";
case 39:return "KeyArrowright";
case 40:return "KeyArrowdown";
case 46:return "KeyDelete";
case 113:return "KeyF2";
default:
	for (var i=0;i<this.myMenulist.length;i++){
	for (var j=0;j<this.myMenulist[i].length;j++){
		if(hasKeycommand(this.myMenulist[i][j],k)){
			return menuClean(this.myMenulist[i][j]);
		}//end if
	}//next
	}//next
	return null;
}//end switch
}//end function

function Menustrip_auditMenus(list){
var arg=list.split(",");
for(ix=0;ix<arg.length;ix=ix+2){
if(!include(arg[ix])){
	this.removeMenuitem(arg[ix+1]);
}//end if
}//next
}//end function

gLoadedMenustrip=true;
//END CLASS
