menu = new Object();
url = new Object();
menu["Main"] = [
      "X86",
      "ARM",
      "Accessories",
      "Dev Kits",
      "App Kits",
      "Legacy",
      "Custom",
      "Enclosures",
      "Peripherals"
     ];

menu["ARM"] = [
      "TS-7800",
      "TS-72XX",
      "TS-73XX",
      "TS-7400"
      ];

menu["X86"] = [
      "TS-5XXX", "TS-3XXX"
      ];
menu["Peripherals"] = [
      "Power/Memory",
      "Network",
      "Serial",
      "Data Aquisition",
      "Multi-function",
      "Production"
      ];
menu["Dev Kits"] = [
      "KIT-ARM",
      "KIT-X86"
      ];
url["Dev Kits"] = [
		   "http://www.embeddedarm.com/products/board-detail.php?product=KIT-ARM",
		   "http://www.embeddedarm.com/products/board-detail.php?product=KIT-X86"
		   ];
menu["App Kits"] = [
      "TS-COMBOX",
      "TS-PLC",
      "TS-PLC-MASTER",
      "TS-TPC-7390",
      "TS-WIFIBOX"
      ];
menu["Enclosures"] = [
      "TS-ENC100",
      "TS-ENC200",
      "TS-ENC530",
      "TS-ENC540",
      "TS-ENC550",
      "TS-ENC560",
      "TS-ENC720",
      "TS-ENC730"
      ];
url["Enclosures"] = [
		     "http://www.embeddedarm.com/products/board-detail.php?product=TS-ENC100",
		     "http://www.embeddedarm.com/products/board-detail.php?product=TS-ENC200",
		     "http://www.embeddedarm.com/products/board-detail.php?product=TS-ENC530",
		     "http://www.embeddedarm.com/products/board-detail.php?product=TS-ENC540",
		     "http://www.embeddedarm.com/products/board-detail.php?product=TS-ENC550",
		     "http://www.embeddedarm.com/products/board-detail.php?product=TS-ENC560",
		     "http://www.embeddedarm.com/products/board-detail.php?product=TS-ENC720",
		     "http://www.embeddedarm.com/products/board-detail.php?product=TS-ENC730"
		     ];

menu["Accessories"] = [
      "Power Supply",
      "Pre-programmed Media",
      "Cables/Connectors",
      "DiskOnChip Media",
      "Miscellaneous",
      "Board-Specific"
      ];
menu["TS-5XXX"] = [ "TS-5700", "TS-5600", "TS-5500", "TS-5400", "TS-5300" ];
menu["TS-3XXX"] = [ "TS-3400", "TS-3300", "TS-3200", "TS-3100" ];
menu["Legacy"] = ["TS-2XXX", "Buffers"];
url["Legacy"] = ["http://www.embeddedarm.com/products/legacy.php#ts-2000-series","http://www.embeddedarm.com/products/legacy.php#buffers"];

menu["Power/Memory"] = ["TS-POE100", "TS-NVRAM2", "TS-NVRAM", "TS-12W", 
      "TS-BAT3", "TS-RF2-CF"];
menu["Network"] = ["TS-MODEM2", "TS-MODEM", "TS-GSM1", "TS-ETH10", 
      "TS-ETH100", "TS-ETH2", "TS-CAN1", "TS-RF2-AERO", "TS-RF2-ZIGBEE"];
menu["Serial"] = ["TS-SER1", "TS-SER2", "TS-SER4", "TS-ISO485"];
menu["Data Aquisition"] = ["TS-ADC16", "TS-ADC24", "TS-RELAY8", "TS-9700", 
      "TS-DIO24", "TS-DIO64"];
menu["Multi-function"] = ["TS-7KV", "TS-9500", "TS-9600"];
menu["Production"] = ["TS-9300", "TS-9420", "TS-9422"];
menu["Power Supply"] = ["PS-18VDC-REG","PS-5VDC-1AMP","PS-5VDC-2_5REG","PS-5VDC-REG"];
menu["Pre-programmed Media"]= ["SD-2GB-USB-7800","SD-2GB-USB-LCDR","SD-512-7800",
			       "SD-512-LCDR","CF-1GB","SD-512-7300","USB-FLASH-1GB"];
menu["Cables/Connectors"]= ["CB7-05","RC-3418","RC-5018","RC-DB25","RC-DB9","RC-KIT-SER2"];
menu["DiskOnChip Media"]= ["DOC-32M","DOC-32M-XT"];
menu["Miscellaneous"]= ["GR64","KPAD","LCD-LED","MT5600SMI-XL34","MT5600SMI-XL92",
			"OP-IDE-KIT2","WIFI-B-CARD","WIFI-G-USB"];
menu["Board-Specific"]= ["TS-5620"];


menu["TS-72XX"] = [ "TS-7200", "TS-7250", "TS-7260"];
menu["TS-73XX"] = ["TS-7300", "TS-7350", "TS-7370", "TS-7390"];

menu["TS-POE100"] = ["Schematic","Manual","Info"];
url["TS-POE100"] = [
		    "http://www.embeddedarm.com/documentation/ts-poe100-schematic.pdf",
		    "http://www.embeddedarm.com/documentation/ts-poe100-manual.pdf",
		    "http://www.embeddedarm.com/products/board-detail.php?product=TS-POE100"
	   ];
menu["TS-NVRAM2"] = ["Schematic","Manual","Info"
	   ];
url["TS-NVRAM2"] = [
           "http://www.embeddedarm.com/documentation/ts-nvram2-schematic.pdf",
           "http://www.embeddedarm.com/documentation/ts-nvram2-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-NVRAM2"
	   ];
menu["TS-NVRAM"] = ["Mechanical Drawing","Info"
	   ];
url["TS-NVRAM"] = [
	   "http://www.embeddedarm.com/documentation/ts-nvram-mechanical.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-NVRAM"
	   ];
menu["TS-12W"] = ["Schematic","Manual","Info"
	   ];
url["TS-12W"] = [
           "http://www.embeddedarm.com/documentation/ts-12w-schematic.pdf",
           "http://www.embeddedarm.com/documentation/ts-12w-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-12W"
	   ];
menu["TS-BAT3"] = ["Schematic","Manual","Info"
	   ];
url["TS-BAT3"] = [
           "http://www.embeddedarm.com/documentation/ts-bat3-schematic.pdf",
	   "http://www.embeddedarm.com/about/resource.php?item=42",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-BAT3"
	   ];
menu["TS-RF2-CF"] = ["Schematic","Getting Started","Info"
	   ];
url["TS-RF2-CF"] = [
           "http://www.embeddedarm.com/documentation/ts-rf2-schematic.pdf",
           "http://www.embeddedarm.com/about/resource.php?item=339",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-RF2-CF"
	   ];

menu["TS-MODEM2"] = ["Schematic","Manual","Info","MultiTech SW Guide", "MultiTech HW Guide" ];
url["TS-MODEM2"] = [
           "http://www.embeddedarm.com/documentation/ts-modem2-schematic.pdf",
           "http://www.embeddedarm.com/documentation/ts-modem2-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-MODEM2",
	   "http://www.embeddedarm.com/documentation/third-party/ts-modem2_developerguide-gsm-gprs-ip-commands-s000333b.pdf",
	   "http://www.embeddedarm.com/documentation/third-party/ts-modem2_developerguide-universalsocketconnectivity(rev.c).pdf"
	   ];
menu["TS-MODEM"] = ["Schematic","Manual","Info" ];
url["TS-MODEM"] = [
           "http://www.embeddedarm.com/documentation/ts-modem-schematic.pdf",
           "http://www.embeddedarm.com/documentation/ts-modem-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-MODEM2",
	   ];
menu["TS-GSM1"] = ["Schematic","Manual","Info" ];
url["TS-GSM1"] = [
           "http://www.embeddedarm.com/documentation/ts-gsm1-schematic.pdf",
           "http://www.embeddedarm.com/documentation/ts-gsm1-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-GSM1",
	   ];
menu["TS-ETH10"] = ["Schematic","Manual","Info" ];
url["TS-ETH10"] = [
           "http://www.embeddedarm.com/documentation/ts-eth10-schematic.pdf",
           "http://www.embeddedarm.com/documentation/ts-eth10-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-ETH10",
	   ];
menu["TS-ETH100"] = ["Manual","Info" ];
url["TS-ETH100"] = [
           "http://www.embeddedarm.com/documentation/ts-eth100-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-ETH100",
	   ];
menu["TS-ETH2"] = ["Getting Started","Info" ];
url["TS-ETH2"] = [
	   "http://www.embeddedarm.com/about/resource.php?item=365",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-ETH2",
	   ];
menu["TS-CAN1"] = ["Schematic","Manual","Info"
	   ];
url["TS-CAN1"] = [
           "http://www.embeddedarm.com/documentation/ts-can1-schematic.pdf",
           "http://www.embeddedarm.com/documentation/ts-can1-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-CAN1"
	   ];
menu["TS-RF2-AERO"] = ["Schematic","Getting Started","Info" ];
url["TS-RF2-AERO"] = [
           "http://www.embeddedarm.com/documentation/ts-rf2-schematic.pdf",
	   "http://www.embeddedarm.com/about/resource.php?item=338",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-RF2-AERO",
	   ];
menu["TS-RF2-ZIGBEE"] = ["Schematic","Getting Started","Info" ];
url["TS-RF2-ZIGBEE"] = [
           "http://www.embeddedarm.com/documentation/ts-rf2-schematic.pdf",
	   "http://www.embeddedarm.com/about/resource.php?item=340",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-RF2-ZIGBEE",
	   ];
menu["TS-SER1"] = ["Schematic","Manual","Info"
	   ];
url["TS-SER1"] = [
           "http://www.embeddedarm.com/documentation/ts-ser1-schematic.pdf",
           "http://www.embeddedarm.com/documentation/ts-ser1-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-SER1"
	   ];
menu["TS-SER2"] = ["Schematic","Manual","Info"
	   ];
url["TS-SER2"] = [
           "http://www.embeddedarm.com/documentation/ts-ser2-schematic.pdf",
           "http://www.embeddedarm.com/documentation/ts-ser2-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-SER2"
	   ];
menu["TS-SER4"] = ["Schematic","Manual","Info","Mechanical Drawing"
	   ];
url["TS-SER4"] = [
           "http://www.embeddedarm.com/documentation/ts-ser4-schematic.pdf",
           "http://www.embeddedarm.com/documentation/ts-ser4-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-SER4",
	   "http://www.embeddedarm.com/documentation/ts-ser4-mechanical.pdf"
	   ];
menu["TS-ISO485"] = ["Schematic","Manual","Info"
	   ];
url["TS-ISO485"] = [
           "http://www.embeddedarm.com/documentation/ts-iso485-schematic.pdf",
           "http://www.embeddedarm.com/documentation/ts-iso485-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-ISO485"
	   ];

menu["TS-ADC16"] = ["Getting Started","Info"
	   ];
url["TS-ADC16"] = [
           "http://www.embeddedarm.com/about/resource.php?item=344",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-ADC16"
	   ];
menu["TS-ADC24"] = ["Getting Started","Info"
	   ];
url["TS-ADC24"] = [
           "http://www.embeddedarm.com/about/resource.php?item=345",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-ADC24"
	   ];
menu["TS-RELAY8"] = ["Manual","Info"
	   ];
url["TS-RELAY8"] = [
           "http://www.embeddedarm.com/documentation/ts-relay8-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-RELAY8"
	   ];
menu["TS-9700"] = ["Schematic","Manual","Info"
	   ];
url["TS-9700"] = [
           "http://www.embeddedarm.com/documentation/ts-9700-schematic.pdf",
           "http://www.embeddedarm.com/documentation/ts-9700-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-9700"
	   ];
menu["TS-DIO24"] = ["Schematic","Manual","Info"
	   ];
url["TS-DIO24"] = [
           "http://www.embeddedarm.com/documentation/ts-dio24-schematic.pdf",
           "http://www.embeddedarm.com/documentation/ts-dio24-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-DIO24"
	   ];
menu["TS-DIO64"] = ["Schematic","Manual","Info", "Mechanical Drawing"
	   ];
url["TS-DIO64"] = [
           "http://www.embeddedarm.com/documentation/ts-dio64-schematic.pdf",
           "http://www.embeddedarm.com/documentation/ts-dio64-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-DIO64",
	   "http://www.embeddedarm.com/documentation/ts-dio64-mechanical.pdf"
	   ];

menu["TS-7KV"] = ["Schematic","Manual","Info"
	   ];
url["TS-7KV"] = [
           "http://www.embeddedarm.com/documentation/ts-7kv-schematic.pdf",
           "http://www.embeddedarm.com/documentation/ts-7kv-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-7KV"
	   ];
menu["TS-9500"] = ["Schematic","Manual","Info",
	   ];
url["TS-9500"] = [
           "http://www.embeddedarm.com/documentation/ts-9500-schematic.pdf",
           "http://www.embeddedarm.com/documentation/ts-9500-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-9500"
	   ];
menu["TS-9600"] = ["Schematic","Manual","Info",
	   ];
url["TS-9600"] = [
           "http://www.embeddedarm.com/documentation/ts-9600-schematic.pdf",
           "http://www.embeddedarm.com/documentation/ts-9600-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-9600"
	   ];

menu["TS-9300"] = ["Schematic","Manual","Info",
	   ];
url["TS-9300"] = [
           "http://www.embeddedarm.com/documentation/ts-9300-schematic.pdf",
           "http://www.embeddedarm.com/documentation/ts-9300-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-9300"
	   ];
menu["TS-9420"] = ["Schematic","Getting Started","Info",
	   ];
url["TS-9420"] = [
           "http://www.embeddedarm.com/documentation/ts-9420-schematic.pdf",
	   "http://www.embeddedarm.com/about/resource.php?item=341",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-9420"
	   ];
menu["TS-9422"] = ["Schematic","Manual","Info",
	   ];
url["TS-9422"] = [
           "http://www.embeddedarm.com/documentation/ts-9422-schematic.pdf",
           "http://www.embeddedarm.com/documentation/ts-9422-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-9422"
	   ];

menu["TS-COMBOX"] = ["Manual","Info"
	   ];
url["TS-COMBOX"] = [
           "http://www.embeddedarm.com/documentation/ts-combox-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-COMBOX"
	   ];
menu["TS-PLC"] = ["Ladder Logic Tutorial","Manual","Info"
	   ];
url["TS-PLC"] = [
           "http://www.embeddedarm.com/about/resource.php?item=148",
           "http://www.embeddedarm.com/about/resource.php?item=312",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-PLC"
	   ];
menu["TS-PLC-MASTER"] = ["Info"
	   ];
url["TS-PLC-MASTER"] = [
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-PLC-MASTER"
	   ];
menu["TS-TPC-7390"] = ["LCD Getting Started","Manual","Info","Mechanical Drawing","Schematic"
	   ];
url["TS-TPC-7390"] = [
           "http://www.embeddedarm.com/about/resource.php?item=370",
           "http://oz.embeddedarm.com/~michael/support/tpc7390.html",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-TPC-7390",
	   "http://www.embeddedarm.com/documentation/ts-tpc-7390-mechanical.pdf",
	   "http://www.embeddedarm.com/documentation/ts-7390-schematic.pdf"
	   ];
menu["TS-WIFIBOX"] = ["Manual","Info"
	   ];
url["TS-WIFIBOX"] = [
           "http://www.embeddedarm.com/documentation/ts-wifibox-manual.pdf",
           "http://www.embeddedarm.com/products/board-detail.php?product=TS-WIFIBOX"
	   ];
menu["TS-7800"] = ["Datasheet","Schematic","Mechanical Drawing","Manual","Getting Started","Info"
	   ];
url["TS-7800"] = [
           "http://www.embeddedarm.com/documentation/ts-7800-datasheet.pdf",
           "http://www.embeddedarm.com/documentation/ts-7800-schematic.pdf",
           "http://www.embeddedarm.com/documentation/ts-7800-mechanical.pdf",
	   "http://www.embeddedarm.com/about/resource.php?item=303",
	   "http://www.embeddedarm.com/documentation/ts-7800-gs-sheet.pdf",
	   "http://www.embeddedarm.com/products/board-detail.php?product=TS-7800"
	   ];
menu["TS-7400"] = ["Datasheet","Schematic","Mechanical Drawing","Quick Manual","TS-9441 Schematic","Full Manual","Info"
	   ];
url["TS-7400"] = [
           "http://www.embeddedarm.com/documentation/ts-7400-datasheet.pdf",
           "http://www.embeddedarm.com/documentation/ts-7400-schematic.pdf",
           "http://www.embeddedarm.com/documentation/ts-7400-mechanical.pdf",
	   "http://www.embeddedarm.com/about/resource.php?item=302",
	   "http://www.embeddedarm.com/documentation/ts-9441-schematic.pdf",
	   "http://www.embeddedarm.com/documentation/ts-7400-manual.pdf",
	   "http://www.embeddedarm.com/products/board-detail.php?product=TS-7400",
	   ];

/*

menu[""] = ["Schematic","Manual","Info"
	   ];
url[""] = [
           "",
           "",
           ""
	   ];
*/
url["TS-3XXX"] = [
		  "http://www.embeddedarm.com/products/board-detail.php?product=TS-3400",
		  "http://www.embeddedarm.com/products/board-detail.php?product=TS-3300",
		  "http://www.embeddedarm.com/products/board-detail.php?product=TS-3200",
		  "http://www.embeddedarm.com/products/board-detail.php?product=TS-3100"
		  ];
url["TS-5XXX"] = [
		  "http://www.embeddedarm.com/products/board-detail.php?product=TS-5700",
		  "http://www.embeddedarm.com/products/board-detail.php?product=TS-5600",
		  "http://www.embeddedarm.com/products/board-detail.php?product=TS-5500",
		  "http://www.embeddedarm.com/products/board-detail.php?product=TS-5400",
		  "http://www.embeddedarm.com/products/board-detail.php?product=TS-5300"
		  ];

menu["TS-7200"] = ["Schematic","Mechanical Drawing","Data Sheet","Manual","Info"];
url["TS-7200"] = [
		  "http://www.embeddedarm.com/documentation/ts-7200-schematic.pdf",
		  "http://www.embeddedarm.com/documentation/ts-7200-mechanical.pdf",
		  "http://www.embeddedarm.com/documentation/ts-7200-datasheet.pdf",
		  "http://www.embeddedarm.com/documentation/ts-7200-manual.pdf",
		  "http://www.embeddedarm.com/products/board-detail.php?product=TS-7200"
		  ];
menu["TS-7250"] = ["Schematic","Mechanical Drawing","Data Sheet","Manual","Info"];
url["TS-7250"] = [
		  "http://www.embeddedarm.com/documentation/ts-7250-schematic.pdf",
		  "http://www.embeddedarm.com/documentation/ts-7250-mechanical.pdf",
		  "http://www.embeddedarm.com/documentation/ts-7250-datasheet.pdf",
		  "http://www.embeddedarm.com/documentation/ts-7250-manual.pdf",
		  "http://www.embeddedarm.com/products/board-detail.php?product=TS-7250"
		  ];
menu["TS-7260"] = ["Schematic","Mechanical Drawing","Data Sheet","Manual","Info"];
url["TS-7260"] = [
		  "http://www.embeddedarm.com/documentation/ts-7260-schematic.pdf",
		  "http://www.embeddedarm.com/documentation/ts-7260-mechanical.pdf",
		  "http://www.embeddedarm.com/documentation/ts-7260-datasheet.pdf",
		  "http://www.embeddedarm.com/documentation/ts-7260-manual.pdf",
		  "http://www.embeddedarm.com/products/board-detail.php?product=TS-7260"
		  ];

menu["TS-7300"] = ["Schematic","Mechanical Drawing","Data Sheet","Manual","Info"];
url["TS-7300"] = [
		  "http://www.embeddedarm.com/documentation/ts-7300-schematic.pdf",
		  "http://www.embeddedarm.com/documentation/ts-7300-mechanical.pdf",
		  "http://www.embeddedarm.com/documentation/ts-7300-datasheet.pdf",
		  "http://www.embeddedarm.com/documentation/ts-7300-manual.pdf",
		  "http://www.embeddedarm.com/products/board-detail.php?product=TS-7300"
		  ];

menu["TS-7350"] = ["Schematic","Mechanical Drawing","Manual","Info"];
url["TS-7350"] = [
		  "http://www.embeddedarm.com/documentation/ts-7350-schematic.pdf",
		  "http://www.embeddedarm.com/documentation/ts-7350-mechanical.pdf",
		  "http://www.embeddedarm.com/about/resource.php?item=371",
		  "http://www.embeddedarm.com/products/board-detail.php?product=TS-7350"
		  ];
menu["TS-7370"] = ["Schematic","Info","Manual"];
url["TS-7370"] = [
		  "http://www.embeddedarm.com/documentation/ts-7370-schematic.pdf",
		  "http://www.embeddedarm.com/products/board-detail.php?product=TS-7370",
		  "http://www.embeddedarm.com/about/resource.php?item=371"
		  ];
menu["TS-7390"] = ["Schematic","Mechanical Drawing","Manual","Info"];
url["TS-7390"] = [
		  "http://www.embeddedarm.com/documentation/ts-7390-schematic.pdf",
		  "http://www.embeddedarm.com/documentation/ts-7390-mechanical.pdf",
		  "http://oz.embeddedarm.com/~michael/support/tpc7390.html",
		  "http://www.embeddedarm.com/products/board-detail.php?product=TS-7390"
		  ];
txtcolor="#ffff00";
function PieMenu(innerRadius, outerRadius, items, canvas, rot, color, subcolor) {
  this._centerX = 0;
  this._centerY = 0;
  this._numSpokes = items.length;
  this._items = items;
  this._innerRadius = innerRadius;
  this._outerRadius = outerRadius;
  this._visible = false;
  this._ctx = canvas.getContext("2d");
  this._lastChosen = null;
  this._oldSlice = null;
  this._subMenuVisible = false;
  this._sep = 0.00;
  this._rot = rot;
  this._color = color;
  this._subcolor = subcolor;
}
PieMenu.prototype = {
  start: function( x, y ) {
    this.setCenter(x, y);
    this.draw();
    this._visible = true;
  },
  stop: function() {
    this.undraw();
  },
  simMouse: function(choice) {
	this._lastChosen = choice;
	if (this._oldSlice != null) {
	    this.eraseSubMenu();
	}
	this._oldSlice = choice;
	if (choice != null) {
	    this.drawSubMenu();
	}
  },

  onMouseUp: function( x, y ) {
    this.onMouseMove(x,y);
    this._lastChosen = this.getSliceNumFromPoint(x, y);
    //redrawCanvas(this._ctx);
    //this._visible = false;
  },
  onMouseMove: function( x, y ) {
    if (!this._visible) {
      return;
    }

    var slice = this.getSliceNumFromPoint(x, y);

    if (slice != this._oldSlice) {
	if (this._oldSlice != null) {
	    this.eraseSubMenu();
	}
	this._oldSlice = slice;
	if (slice != null) {
	    this.drawSubMenu();
	}
    }
  },
  getLastChosen: function() {
    return this._lastChosen;
  },
  setCenter: function( x, y ) {
    this._centerX = x;
    this._centerY = y;
  },
  moveToPolar: function( angle, distance ) {
    this._ctx.moveTo( this._centerX + distance * Math.cos(angle),
                      this._centerY + distance * Math.sin(angle) );
  },
  lineToPolar: function( angle, distance ) {
    this._ctx.lineTo( this._centerX + distance * Math.cos(angle),
                      this._centerY + distance * Math.sin(angle) );
  },
  renderTextPolar: function( angle, distance, text, pt, rot,color) {
    var signx,signy,ang;

    pt = pt*7/8;
    this._ctx.save();
    this._ctx.mozTextStyle = ""+pt+"pt Arial";
    this._ctx.fillStyle = color;
    if (rot == 1) { // perpendicular
	signx = Math.cos(angle) > 0;
	signy = Math.sin(angle) > 0;
	/*
	if (signx == 1 && signy == 1) {
	    angle -= Math.PI/2; // 3,4
	} else 
	if (signx == 0 && signy == 1) { // 5,6
	    angle -= Math.PI/2;
	} else
	if (signx == signy) {
	    angle += Math.PI/2; // 3,4,7
	} else {
	    angle += Math.PI / 2;  // 0,1,2,5,6
	}
	*/

	this._ctx.beginPath();
	ang = this._ctx.mozMeasureText(text)/(distance-pt/2)/2;
	if (signy > 0) {
	    this._ctx.arc(this._centerX,this._centerY,distance+pt/2,
			  angle+ang,angle-ang,true);
	} else {
	    this._ctx.arc(this._centerX,this._centerY,distance-pt/2,
			  angle-ang,angle+ang,false);
	}
	this._ctx.mozTextAlongPath(text,false);
	this._ctx.closePath();
	this._ctx.restore();
	return;
    }
    this._ctx.translate(this._centerX + distance * Math.cos(angle),
                     this._centerY + distance * Math.sin(angle));

    if (rot == -1) { // parallel

	if (Math.cos(angle) < 0) {
	    angle += Math.PI;
	}
    }
    if (rot != 0) {
	this._ctx.rotate(angle);
    }
    // measureText once FireFox 3.1 comes out...
    this._ctx.translate(-this._ctx.mozMeasureText(text)/2,pt/2);
    this._ctx.mozDrawText(text);
    this._ctx.restore();
  }, 
  drawsector : function(x,y,angle1,angle2,inner,outer) {
      this._ctx.beginPath();

      this.moveToPolar(angle1, inner);
      this.lineToPolar(angle1, outer);
      this._ctx.arc(x,y,outer,angle1,angle2,false);
      this.lineToPolar(angle2, inner);
      this._ctx.arc(x,y,inner,angle2,angle1,true);
      
      this._ctx.fill();
      this._ctx.stroke();

  },
  draw: function() {
    var angle = - Math.PI/this._numSpokes - Math.PI/2;
    var incr = Math.PI * 2 / this._numSpokes;
    this._ctx.fillStyle = "rgb(90,0,90)";
    this._ctx.strokeStyle = "rgb(255,255,255)";
    this._ctx.lineWidth = 2

    this._ctx.fillStyle = this._color;
    for (var theta = 0; theta < this._numSpokes; theta++) {
	this.drawsector(this._centerX,this._centerY,angle+this._sep,angle+incr-this._sep,this._innerRadius,this._outerRadius);
	this.renderTextPolar( angle+incr/2 , (this._outerRadius-this._innerRadius)/2+this._innerRadius, this._items[theta],14,this._rot,txtcolor);
	angle += incr;
    }
  },

  undraw: function() {
    var angle = - Math.PI/this._numSpokes - Math.PI/2;
    var incr = Math.PI * 2 / this._numSpokes;
    this._ctx.fillStyle = "rgb(255,255,255)";
    this._ctx.strokeStyle = "rgb(255,255,255)";
    this._ctx.lineWidth = 2

    for (var theta = 0; theta < this._numSpokes; theta++) {
	this.drawsector(this._centerX,this._centerY,angle+this._sep,angle+incr-this._sep,this._innerRadius,this._outerRadius);
	angle += incr;
    }
  },

  drawSubMenu: function() {
    var angle = -Math.PI / this._numSpokes - Math.PI/2;
    var incr = Math.PI * 2 / this._numSpokes;
    var theta = this._oldSlice;

    this._ctx.fillStyle = this._subcolor;
    this._ctx.strokeStyle = "rgb(255,255,255)";
    this._ctx.lineWidth = 2;

    this.drawsector(this._centerX,this._centerY,theta*incr+angle+this._sep,theta*incr+angle+incr-this._sep,this._innerRadius,this._outerRadius);
    this.renderTextPolar( theta*incr+angle+incr/2 , (this._outerRadius-this._innerRadius)/2+this._innerRadius, this._items[theta],14,this._rot,txtcolor);
  },

  eraseSubMenu: function() {
    var angle = -Math.PI / this._numSpokes - Math.PI/2;
    var incr = Math.PI * 2 / this._numSpokes;
    var theta = this._oldSlice;

    this._ctx.fillStyle = this._color;
    this._ctx.strokeStyle = "rgb(255,255,255)";
    this._ctx.lineWidth = 2;

    this.drawsector(this._centerX,this._centerY,theta*incr+angle+this._sep,theta*incr+angle+incr-this._sep,this._innerRadius,this._outerRadius);
    this.renderTextPolar( theta*incr+angle+incr/2 , (this._outerRadius-this._innerRadius)/2+this._innerRadius, this._items[theta],14,this._rot,txtcolor);
  },

  getSliceNumFromPoint: function( x, y ) {
    var deltaX = x - this._centerX;
    var deltaY = y - this._centerY;
    var distance = Math.sqrt( deltaX * deltaX + deltaY * deltaY );
    if (distance < this._innerRadius)
      return null;

    var angle = Math.atan2( deltaX, -1 * deltaY );
     if (angle < 0 ) {
      angle += Math.PI * 2;
    }
    var sliceWidth = Math.PI * 2 / this._numSpokes;
    angle += sliceWidth/2

    if (distance > this._outerRadius) { // && this._subMenuVisible) {
        return null; // this._numSpokes + 1;
    }

    var sliceNum = Math.floor( angle  / sliceWidth );
    while (sliceNum >= this._numSpokes)
      sliceNum -= this._numSpokes;
    while (sliceNum < 0)
      sliceNum += this._numSpokes;
    return sliceNum;
  }
};

var bmu_xmin, bmu_xmax, bmu_ymin, bmu_ymax, bmu_sel;

function bmu_test(x,y) {
    return (x >= bmu_xmin && x <= bmu_xmax
	    && y >= bmu_ymin && y <= bmu_ymax);
}

function redraw_BMU(context,sel) {
  var txt="Bookmarkify URL";
  context.mozTextStyle = "12pt bold courier new";
  var w=context.mozMeasureText(txt);

  if (sel) {
      context.fillStyle = "#a000a0";
  } else {
      context.fillStyle = "#800080";
  }
  bmu_sel = sel;
  bmu_xmin = 600-w-10;
  bmu_xmax = 600;
  bmu_ymin = 550;
  bmu_ymax = 600;
  //context.fillRect(600-w-10,550,w+10,50);
  context.fillRect(600-w-10,550+10,w+10,50-20);
  context.fillRect(600-w,550,w-10,50);

  context.beginPath();
  context.arc(600-w,550+10,10,0,2*Math.PI,false);
  context.moveTo(600-w,600-10);
  context.arc(600-w,600-10,10,0,2*Math.PI,false);
  context.moveTo(600-10,550+10);
  context.arc(600-10,550+10,10,0,2*Math.PI,false);
  context.moveTo(600-10,600-10);
  context.arc(600-10,600-10,10,0,2*Math.PI,false);
  context.fill();

  context.save();
  context.translate(600-w-5,580);
  context.fillStyle = "white";
  context.mozDrawText(txt);
  context.restore();
}

function redrawCanvas(context) {
  context.clearRect(0, 0, 600, 600);
  bmu_sel = false;
  redraw_BMU(context,false);

  /*
  context.beginPath();
  context.moveTo(1, 1);
  context.lineTo(599, 1);
  context.lineTo(599, 599);
  context.lineTo(1, 599);
  context.lineTo(1, 1);
  context.stroke();
  */
}


function writeOnCanvas( message, canvas ) {
  var ctx = canvas.getContext("2d");
  redrawCanvas(ctx);
  ctx.mozTextStyle = "14pt sans serif";
  ctx.fillStyle = "black";
  ctx.save();
  ctx.translate(250, 250);
  ctx.mozDrawText(message);
  ctx.restore();
}

function bookmark(event) {
    window.open("?"+menu1, "_self", "",true);
    if (event) {
	event.returnValue = false;
    }
    return false;
}

