// Modified by Curtis Palmer - JUNE 2010

// Copyright 2001 Dan Pupius dan@pupius.net http://www.pupius.net
// This script was released at DHTMLCentral.com
// Permission granted to SimplytheBest.net to feature the script in the DHTML script collection
// Courtesy of SimplytheBest.net - http://simplythebest.net/scripts/

// DotMenu
// provides cross-browser functionality
//======================================
function getObjectRef(name) {
  if(document.getElementById) return document.getElementById(name);
  else if(document.all) return document.all[name];
  else return null;
}

// general functions to assist the script
//========================================
function show(name) {
  var el = getObjectRef(name);
  if(el) el.style.visibility = "visible";
}
function hide(name) {
  var el = getObjectRef(name);
  if(el) el.style.visibility = "hidden";
}
function getWidth(name) {
  var el = getObjectRef(name);
  return el.offsetWidth;
}
function getHeight(name) {
  var el = getObjectRef(name);
  return el.offsetHeight;
}
function moveMe(name,x,y) {
  var el = getObjectRef(name);
  if(el) { el.style.top = parseInt(y); el.style.left = parseInt(x); }
}
function moveBy(name,x,y) {
  var el = getObjectRef(name);
  if(el) { el.style.top = parseInt(el.style.top) + parseInt(y); el.style.left = parseInt(el.style.left) + parseInt(x); }
}

// Creates the menu objects
//==========================
var menuCount = 0;
function menuObject(name,x,y,caption, r, parent) {
  if ( (!document.getElementById&&!document.all) || navigator.userAgent.indexOf("Opera")>-1) return;
  document.write('<div id="divDot' + menuCount + '" class="dotempty" style="top: ' + y + '; left: ' + x + '"></div>');
  document.write('<div id="divCap' + menuCount + '" class="caption" style="top: 0; left: 0">' + caption + '</div>');
  
  this.name = name;
  this.parent = parent;
  this.ref = "divDot" + menuCount;
  this.caption = "divCap" + menuCount;
  if(r) this.radius = r + 8; // -- added value to expand radius
  else this.radius = 400;
  this.subMenus = new Array();
  this.state = 0;
  this.moving = false;
  if(this.parent) this.action = "null";
  else this.action = "toggle";
  if(this.parent) this.startAngle = parent.startAngle + 12; // -- sets rotation of 3rd level expansion
  else this.startAngle = 0;

  getObjectRef(this.ref).objRef = this.name;
  
  this.show = function() { show(this.ref); }
  this.hide = function() { hide(this.ref); }
  this.moveMe = function(x,y) { if(this.parent) { x += this.parent.x(); y += this.parent.y(); } moveMe(this.ref,x,y); }
  this.moveBy = function(x,y) { moveBy(this.ref,x,y); }
  this.x = function() { return parseInt(getObjectRef(this.ref).style.left); }
  this.y = function() { return parseInt(getObjectRef(this.ref).style.top); }
  this.w = function() { return getWidth(this.ref); }
  this.h = function() { return getHeight(this.ref); }

  this.showCaption = function() {
    moveMe(this.caption, this.x() - (getWidth(this.caption)/2) + (this.w()/2), (this.y() + this.h() + 5)); // -- added value to separate from dot
    show(this.caption);
  }
  this.hideCaption = function() {
    hide(this.caption);
  }
  this.setCaption = function(c) { getObjectRef(this.caption).innerHTML = c;}
 
  this.addItem = function(c,action,r) {
    getObjectRef(this.ref).className = "dot";
    if(!r) r = this.radius/2;
    var sub = new menuObject(this.name + ".subMenus[" + this.subMenus.length + "]",0,0,c,r,this);
    sub.parent = this;
    sub.action = action;
    sub.moveMe(0,0);
    this.subMenus[this.subMenus.length] = sub;
    return sub;
  }
  
  this.expand = function() {
    if(this.subMenus.length > 0) {
      var p = true;
      if(this.parent) {
        p = !this.parent.moving;
        for(var i=0; i<this.parent.subMenus.length;i++)
          p = p && ((this.parent.subMenus[i].state==0) || (this.parent.subMenus[i].state==this.parent.subMenus[i].subMenus.length)) && (this.parent.subMenus[i].moving==false);
      } else var o = false;
      
      if((!this.parent || this.parent.state == this.parent.subMenus.length) && p) {
        if(this.parent) this.collapseAll(this.name);
        
        var diff = 360 / this.subMenus.length;
        for(var i=0;i<this.subMenus.length;i++){
          this.subMenus[i].moveMe(0,0);
          this.subMenus[i].show();
          this.moving = true;
          this.subMenus[i].slide(this.subMenus[i].radius * cos(degToRad((diff*i)+this.startAngle)), this.subMenus[i].radius * sin(degToRad((diff*i)+this.startAngle)), this.name + ".subMenus[" + i + "].showCaption();" + this.name + ".moving=false;" + this.name + ".state+=1;");
        }
        if(this.parent){
          getObjectRef(this.parent.ref).style.filter = "alpha (opacity=33)";
          getObjectRef(this.parent.ref).style.MozOpacity = "33%";

          getObjectRef(this.parent.ref).className = "dotoff";
          getObjectRef(this.parent.caption).style.filter = "alpha (opacity=33)";
          getObjectRef(this.parent.caption).style.MozOpacity = "33%";
          for(i=0;i<this.parent.subMenus.length;i++) {
              getObjectRef(this.parent.subMenus[i].ref).style.filter = "alpha (opacity=66)";
              getObjectRef(this.parent.subMenus[i].ref).style.MozOpacity = "66%";
              getObjectRef(this.parent.subMenus[i].caption).style.filter = "alpha (opacity=66)";
              getObjectRef(this.parent.subMenus[i].caption).style.MozOpacity = "66%";        
          }
          if(this.parent.parent) {
            for(i=0;i<this.parent.parent.subMenus.length;i++) {
              getObjectRef(this.parent.parent.subMenus[i].ref).style.filter = "alpha (opacity=33)";
              getObjectRef(this.parent.parent.subMenus[i].ref).style.MozOpacity = "33%";
              getObjectRef(this.parent.parent.subMenus[i].ref).className = "dotoff";
              getObjectRef(this.parent.parent.subMenus[i].caption).style.filter = "alpha (opacity=33)";        
              getObjectRef(this.parent.parent.subMenus[i].caption).style.MozOpacity = "33%";
            }
            getObjectRef(this.parent.parent.ref).style.MozOpacity = "33%";
            getObjectRef(this.parent.parent.ref).style.MozOpacity = "33%";
            getObjectRef(this.parent.parent.ref).className = "dotoff";
          }
        }
        getObjectRef(this.ref).style.filter = "alpha (opacity=66)";
        getObjectRef(this.caption).style.filter = "alpha (opacity=66)";  
        getObjectRef(this.ref).style.MozOpacity = "66%";
        getObjectRef(this.caption).style.MozOpacity = "66%"; 
      }
    }  
  }
  this.collapse = function() {
    var p = true;
    p = !this.moving;
    for(var i=0; i<this.subMenus.length;i++)
      p = p && (this.subMenus[i].state==0)  && (this.subMenus[i].moving==false);
    if(p && this.subMenus.length > 0) {
      for(var i=0;i<this.subMenus.length;i++){
        this.subMenus[i].hideCaption();
        this.moving = true;
        this.subMenus[i].slide(0, 0, this.name + ".subMenus[" + i + "].hide();" + this.name + ".moving=false;" + this.name + ".state-=1;");
      }
      if(this.parent){
        getObjectRef(this.parent.ref).style.filter = "alpha (opacity=66)";
        getObjectRef(this.parent.ref).style.MozOpacity = "66%";
        if(this.parent.subMenus.length != 0)
          getObjectRef(this.parent.ref).className = "dot";
        else
          getObjectRef(this.parent.ref).className = "dotempty";
        getObjectRef(this.parent.caption).style.filter = "alpha (opacity=66)";
        getObjectRef(this.parent.caption).style.MozOpacity = "66%";
        for(i=0;i<this.parent.subMenus.length;i++) {
          getObjectRef(this.parent.subMenus[i].ref).style.filter = "alpha (opacity=100)";
          getObjectRef(this.parent.subMenus[i].ref).style.MozOpacity = "100%";
          if(this.parent.subMenus[i].subMenus.length != 0) 
            getObjectRef(this.parent.subMenus[i].ref).className = "dot";
          else
            getObjectRef(this.parent.subMenus[i].ref).className = "dotempty";
          getObjectRef(this.parent.subMenus[i].caption).style.filter = "alpha (opacity=100)";        
          getObjectRef(this.parent.subMenus[i].caption).style.MozOpacity = "100%";
        }
        if(this.parent.parent) {
          for(i=0;i<this.parent.parent.subMenus.length;i++) {
            getObjectRef(this.parent.parent.subMenus[i].ref).style.filter = "alpha (opacity=66)";
            getObjectRef(this.parent.parent.subMenus[i].ref).style.MozOpacity = "66%";
            if(this.parent.parent.subMenus[i].subMenus.length != 0)
              getObjectRef(this.parent.parent.subMenus[i].ref).className = "dot";
            else
              getObjectRef(this.parent.parent.subMenus[i].ref).className = "dotempty";
            getObjectRef(this.parent.parent.subMenus[i].caption).style.filter = "alpha (opacity=66)";        
            getObjectRef(this.parent.parent.subMenus[i].caption).style.MozOpacity = "66%";
          }
        }
      }
      getObjectRef(this.ref).style.filter = "alpha (opacity=100)";
      getObjectRef(this.caption).style.filter = "alpha (opacity=100)";       
      getObjectRef(this.ref).style.MozOpacity = "100%";
      getObjectRef(this.caption).style.MozOpacity = "100%";
    }
  }

  this.collapseAll = function(except) {
    for(var i=0;i<this.parent.subMenus.length;i++) {
      if(this.parent.subMenus[i].name!=except && this.parent.subMenus[i].state==this.parent.subMenus[i].subMenus.length) {
        this.parent.subMenus[i].collapse();
      }    
    }
  }
  this.toggle = function(e) {
    if(document.all) id = window.event.srcElement;
    else id = e.target;
    var dot = eval(id.objRef);
    if(dot.state==0 && !dot.moving) dot.expand();
    else if(dot.state==dot.subMenus.length && !dot.moving) dot.collapse()
  }
  this.doAction = function(e) {
    if(document.all) id = window.event.srcElement;
    else id = e.target;
    var dot = eval(id.objRef);
    if(dot.action == "toggle") dot.toggle(e);
    else eval(dot.action);
  }
  //change these if you want to change the events that trigger the actions
  //========================================================================
  //getObjectRef(this.ref).onmousemove = this.toggle;
  getObjectRef(this.ref).onmouseup = this.doAction;
  this.slide = function(xx,yy,func) {
    if(!func) func = "";
    var px = this.parent.x();
    var py = this.parent.y();
    var x = xx - this.x() + px;
    var y = yy - this.y() + py;
    var d = sqrt(square(xx-this.x() + px) + square(yy-this.y() + py));
    var v = d/8;
    if(v<1) v = 1;
    if( (Math.abs(x) < v) && (Math.abs(y) < v) ) {
      moveMe(this.ref,xx + px,yy + py);      
      if(func != "") eval(func);
    } else {    
      var a = round(atan(x,y));
      dx = round(v * cos(degToRad(a)));
      dy = round(v * sin(degToRad(a)));
      this.moveBy(dx,dy);
      setTimeout(this.name + ".slide(" + xx + "," + yy + ", '" + func + "');",10);    
    }
  }
  // Preoading the windows filters.
  if (menuCount==0 && document.all) document.all[this.ref].style.filter = "alpha (opacity=100)";
  menuCount++;
  return this;
}
// Math functions
//================
var pi = Math.PI;
function square(x) { return (x*x); }
function sqrt(x) { return Math.sqrt(x); }
function round(x) { return Math.round(x); }
function rand(x,y) { return (round(Math.random()*(y-x)) + x); }
function cos(x) { return Math.cos(x) }
function sin(x) { return Math.sin(x) }
function degToRad(x) { return ( x/(360/(2*pi)) ); }
function radToDeg(x) { return ( x*(360/(2*pi)) ); }
function atan(s,t) {
  if( s == 0.0 && t > 0.0)
    angle = 90.0;
  else if(s == 0.0 && t < 0.0) 
    angle = 270.0;
  else if (s < 0.0 ) 
    angle = 180.0 + radToDeg(Math.atan(t/s));
  else if (s > 0.0 && t < 0.0)
    angle = 360.0 + radToDeg(Math.atan(t/s));
  else {
    if(s==0.0) s=0.00001;
    angle = radToDeg(Math.atan(t/s));
  }
  if(angle < 0.0) angle += 360.0;
  return angle;
}
//get dimentions of the page
if(document.all) pageWidth = document.documentElement.offsetWidth - 20; // -- changed from .body. to .documentElement. to work with IE8
else pageWidth = innerWidth;
if(document.all) pageHeight = document.documentElement.offsetHeight - 4; // -- changed from .body. to .documentElement. to work with IE8
else pageHeight = innerHeight;

//Create main menu
var menu = new menuObject("menu",pageWidth/2,pageHeight/2,"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ start }",pageHeight/2); // added multiple nbsp to shift text right
menu.startAngle = -45;
//show menu and caption
menu.show();
menu.showCaption();
//Add submenus
menu.addItem("A Little<br>About Me","toggle");
menu.addItem("A Few Of<br>My Projects","toggle");
menu.addItem("Public Speaking<br>Presentation<br>Samples","toggle");
menu.addItem("Portfolio<br>Samples","toggle");

menu.subMenus[0].addItem("Recommendations","toggle");
menu.subMenus[0].addItem("Recognition","toggle");
menu.subMenus[0].addItem("LinkedIn Profile","location='http://www.linkedin.com/in/curtispalmer/'");
menu.subMenus[0].addItem("BHAM Wiki listing","location='http://bhamwiki.com/w/Curtis_Palmer'");
menu.subMenus[0].addItem("Contact Me","toggle");

menu.subMenus[0].subMenus[0].addItem("Received","location='http://www.linkedin.com/profile?viewProfile=&key=360879&authToken=HuOa&authType=name#recommendations'");
menu.subMenus[0].subMenus[0].addItem("Given","location='http://www.linkedin.com/profile?viewRecs=&key=360879'");

menu.subMenus[0].subMenus[1].addItem("Small Business Advocate<br>of the Year 2007","location='http://birmingham.bizjournals.com/birmingham/stories/2007/05/14/story10.html'");
menu.subMenus[0].subMenus[1].addItem("TechBirmingham<br>departure","location='http://www.bizjournals.com/birmingham/stories/2007/10/29/daily4.html'");

menu.subMenus[0].subMenus[4].addItem("Email me","location='mailto:curtis@curtispalmer.com'");
menu.subMenus[0].subMenus[4].addItem("Schedule a meeting<br>with me","location='http://www.tungle.me/curtispalmer'");

menu.subMenus[1].addItem("UrbanReversi","toggle");
menu.subMenus[1].addItem("Birmingham<br>Startup","toggle");
menu.subMenus[1].addItem("Blogs","toggle");
menu.subMenus[1].addItem("Alabama-India<br>TechVenture","toggle");
menu.subMenus[1].addItem("Ecycling Day","location='http://birmingham.bizjournals.com/birmingham/stories/2006/01/23/focus1.html'");
menu.subMenus[1].addItem("Genexodus<br>Book Project","location='http://genexodus.wordpress.com/'");

menu.subMenus[1].subMenus[0].addItem("Blog","location='http://urbanreversi.wordpress.com/'");
menu.subMenus[1].subMenus[0].addItem("Videos","toggle");
menu.subMenus[1].subMenus[0].addItem("Photos","location='http://www.flickr.com/groups/urbanreversi/pool/'");
menu.subMenus[1].subMenus[0].addItem("Press","location='http://main.uab.edu/show.asp?durki=94833'");

menu.subMenus[1].subMenus[0].subMenus[1].addItem("Conflux<br>NYC 1","location='http://www.youtube.com/watch?v=8MiZmC0kw2g'");
menu.subMenus[1].subMenus[0].subMenus[1].addItem("Sidewalk BHM","location='http://www.youtube.com/watch?v=9To6yhvmDUA'");
menu.subMenus[1].subMenus[0].subMenus[1].addItem("Conflux<br>NYC 2","location='http://www.youtube.com/watch?v=nJP0-HgqJDk'");

menu.subMenus[1].subMenus[1].addItem("APT Documentary<br>Video","location='http://www.aptv.org/VideoRoom/viewprogram.asp?FileID=920'");
menu.subMenus[1].subMenus[1].addItem("Photos","location='http://www.flickr.com/groups/startupweekend/pool/'");
menu.subMenus[1].subMenus[1].addItem("Blog","location='http://birminghamstartup.wordpress.com/'");

menu.subMenus[1].subMenus[2].addItem("Musings<br>on Birmingham","location='http://curtispalmer.wordpress.com/'");
menu.subMenus[1].subMenus[2].addItem("MotoQuser","location='http://motoq.wordpress.com/'");
menu.subMenus[1].subMenus[2].addItem("ComplyMD","location='http://complymd.wordpress.com/'");
menu.subMenus[1].subMenus[2].addItem("one://B&quot;HAM","location='http://onebham.wordpress.com/'");

menu.subMenus[1].subMenus[3].addItem("Alabama &quot;angels&quot;<br>to test India","location='http://birmingham.bizjournals.com/birmingham/stories/2006/07/10/story2.html'");
menu.subMenus[1].subMenus[3].addItem("VCII-TiE<br>VC-PE Summit<br>presentation","location='http://www.slideshare.net/curtispalmer/cii-bangalore-nov06'");
menu.subMenus[1].subMenus[3].addItem("Alabama tech<br>group adds<br>VC summit<br>to India trip","location='http://birmingham.bizjournals.com/birmingham/stories/2006/10/02/story6.html'");
menu.subMenus[1].subMenus[3].addItem("&quot;TechVenture&quot;<br>scores<br>in India","location='http://birmingham.bizjournals.com/birmingham/stories/2006/11/27/story3.html'");

menu.subMenus[2].addItem("Financing<br>Your Invention","location='http://www.slideshare.net/curtispalmer/financing-your-invention'");
menu.subMenus[2].addItem("Birmingham Operation<br>Realworld Explorers","location='http://www.slideshare.net/curtispalmer/birmingham-ore'");
menu.subMenus[2].addItem("more...","location='http://www.slideshare.net/curtispalmer/'");
menu.subMenus[2].addItem("LinkedIn<br>for Professional Use","location='http://http://www.slideshare.net/curtispalmer/shelby-county-16june09linkedin4professionaluse'");
menu.subMenus[2].addItem("U R TechBirmingham","location='http://www.slideshare.net/curtispalmer/u-r-techbirmingham'");
menu.subMenus[2].addItem("ComplyMD<br>ICD-10<br>Positioning","location='http://www.slideshare.net/curtispalmer/complymd-icd10-positioning'");
menu.subMenus[2].addItem("CII-TiE<br>VC-PE Summit","location='http://www.slideshare.net/curtispalmer/cii-bangalore-nov06'");
menu.subMenus[2].addItem("Technology Growth<br>in Birmingham","location='http://www.slideshare.net/curtispalmer/uab-mk435-19-apr06'");

menu.subMenus[3].addItem("Video<br>Production","toggle");
menu.subMenus[3].addItem("Graphic<br>Design","toggle");
menu.subMenus[3].addItem("User<br>Interfaces","toggle");
menu.subMenus[3].addItem("Writing<br>Samples","toggle");
menu.subMenus[3].addItem("Press<br>Releases","toggle");

menu.subMenus[3].subMenus[0].addItem("2006 Ecycling<br>Day PSA","location='http://www.youtube.com/watch?v=-6JIS4iAoto'");
menu.subMenus[3].subMenus[0].addItem("Change Your<br>Lifestyle PSA","location='http://www.youtube.com/watch?v=B3oQh-0BpIU'");
menu.subMenus[3].subMenus[0].addItem("Change Your<br>Mind PSA","location='http://www.youtube.com/watch?v=Wdit1SQ8kWk'");
menu.subMenus[3].subMenus[0].addItem("Change Your<br>Future PSA","location='http://www.youtube.com/watch?v=K4Xslmn98Ng'");

menu.subMenus[3].subMenus[1].addItem("I (heart)<br>Urban Reversi<br>shirt design","location='http://www.flickr.com/photos/techbirmingham/242047399/'");
menu.subMenus[3].subMenus[1].addItem("TechMixer<br>postcard","location='http://www.flickr.com/photos/techbirmingham/469413388/in/pool-techmixer'");
menu.subMenus[3].subMenus[1].addItem("Urban Reversi<br>@ CONFLUX 2006<br>postcard","location='http://www.flickr.com/photos/techbirmingham/244362043/'");
menu.subMenus[3].subMenus[1].addItem("ComplyMD<br>logo design","location='https://www.complymd.com/logo.png'");

menu.subMenus[3].subMenus[2].addItem("TechBirmingham<br>(circa 2007)","location='http://web.archive.org/web/20070201232734/http://techbirmingham.com/'");
menu.subMenus[3].subMenus[2].addItem("&quot;Sweet Home Alabama:<br>The Music of Muscle Shoals&quot;<br>film documentary website<br>(circa 2010)","location='http://www.sweethomealabamadocumentary.com/'");
menu.subMenus[3].subMenus[2].addItem("ComplyMD<br>(circa 2008)","location='http://www.youtube.com/user/ComplyMD'");
menu.subMenus[3].subMenus[2].addItem("WebMD portals<br>(circa 1999)","location='http://web.archive.org/web/19990427083701/http://webmd.com/'");

menu.subMenus[3].subMenus[3].addItem("Elevated<br>Highway 280<br>op-ed","location='http://curtispalmer.wordpress.com/2007/02/07/elevatedhighway280/'");
menu.subMenus[3].subMenus[3].addItem("Technology in<br>Birmingham -<br>tomorrow&quot;s growth","location='http://birmingham.bizjournals.com/birmingham/stories/2003/03/17/focus2.html'");

menu.subMenus[3].subMenus[4].addItem("Birmingham Well<br>Represented at<br>HIMMS ’08","location='http://complymd.wordpress.com/2008/02/24/birmingham-ala-well-represented-at-himms08/'");
menu.subMenus[3].subMenus[4].addItem("Birmingham<br>Hotspots<br>Unveiled","location='http://www.prweb.com/releases/2004/11/prweb175580.htm'");
menu.subMenus[3].subMenus[4].addItem("ComplyMD - Necessity<br>Leads to Invention of<br>New Healthcare<br>Software","location='http://www.prweb.com/releases/2008/02/prweb702883.htm'");
menu.subMenus[3].subMenus[4].addItem("TechBirmingham<br>Ecycling Day a<br>Huge Success","location='http://www.prweb.com/releases/2005/04/prweb234838.htm'");
menu.subMenus[3].subMenus[4].addItem("Brooklyn's Streets<br>Become Digital<br>Playground","location='http://www.prweb.com/releases/2006/09/prweb438200.htm'");







