var menu = null;

function Menu(section,subsection,layeredFlash) {
  var self = this;
  this.menu = null;
  this.menuID = 'menu'; 
  if (typeof(layeredFlash)=='undefined') {
    layeredFlash = false;
  } else {
    layeredFlash &= flash.hasVersion(5);
  }
  this.containers = [];
  this.frames = [1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,4,3,2,1];
  this.tweens = [];
  this.menuGroups = [];
  this.menuHeight = [];
  this.menuItems = [];
  this.items = [];
  this.itemCount = 0;
  
  this.createTweens = function() {
    for (var i=0; i<this.containers.length; i++) {
      this.tweens[i] = [0];
      this.tmp = 0;
      menuOffset = ua.isIE?10:9;
      for (var j=0; j<this.frames.length; j++) {
        this.tmp += ((this.menuHeight[i]+menuOffset)*(this.frames[j]*.01));
        this.tweens[i][this.tweens[i].length] = parseInt(this.tmp);
      }
      this.tweens[i][this.tweens[i].length] = this.menuHeight[i]+menuOffset;
    }
  }
  
  this.findNode = function(n) {
    if (!n || !n.nodeType) return null;
    while (n.nodeType==3 && n.parentNode) {
      n = n.parentNode;
    }
    return n;
  }
  
  this.isChildOfId = function(targetId, target) {
    if (!target) return false;
    do {
      if (target.id && target.id.indexOf(targetId)+1) {
        return true;
      } else if (target.parentNode) {
        target = target.parentNode;
      }
    } while (target.parentNode && target.parentNode.nodeName != 'BODY');
    return false;
  }
  
  this.init = function() {
    this.menu = document.getElementById(this.menuID);
    itemsTmp = this.menu.getElementsByTagName('li');
    for (var i=0; i<itemsTmp.length; i++) {
      if (itemsTmp[i].className && itemsTmp[i].className.indexOf('nav-groups')+1) {
        this.menuGroups[this.menuGroups.length] = itemsTmp[i];
        if (this.menuGroups[this.menuGroups.length-1].getElementsByTagName('ul').length) this.itemCount++;
      }
    }
    if (this.supported) {
      for (i=0; i<this.itemCount; i++) {
        if (section != i) {
          document.getElementById('sub-group'+i).style.paddingTop = '0px';
        } else if (section == i && subsection+1) {
          document.getElementById('nav-group'+i).getElementsByTagName('a')[subsection].className = 'active';
        }
      }
    }
    for (i=0; i<this.itemCount; i++) {
      this.containers[i] = this.menuGroups[i].getElementsByTagName('ul')[0];
      this.menuHeight[i] = this.containers[i].offsetHeight; 
      this.menuItems[i] = new this.MenuItem(i);
      if (this.supported) {
        this.menuItems[i].show();
        if (section !=i) {
          this.containers[i].style.marginTop = ((this.menuHeight[i])*-1)+'px';
        }
      } else {
        this.menuItems[i].move = this.menuItems[i].moveStatic;
        if (section == i && subsection+1) {
          document.getElementById('nav-group'+i).getElementsByTagName('a')[subsection].className = 'active';
        }
      }
      if ('nav-group'+section != this.menuGroups[i].id) {
        handler = this.menuItems[i].eventHandler;
        this.menuGroups[i].getElementsByTagName('a')[0].onmouseover = handler;
        this.menuGroups[i].getElementsByTagName('a')[0].onmouseout = handler;
        this.menuGroups[i].getElementsByTagName('div')[1].onmouseout = handler;
      } else {
        this.menuItems[i].show();
      }
    }
  }
  
  this.ns6Fix = function() {
    document.getElementById(this.menuID).style.width='100%';
  }
  
  this.MenuItem = function(menuIndex) {
    this.direction = null;
    this.menuIndex = menuIndex;
    this.frameIndex = 0;
    this.defaultClassName = '';
    this.timers = [];
    this.active = 0;
    var me = this;
    
    this.animate = function() {
      if (this.frameIndex<0 || this.frameIndex>self.tweens[this.menuIndex].length) {
        this.frameIndex = 0;
      } else {
        if (this.frameIndex >= self.tweens[this.menuIndex].length) {
        } else {
          self.containers[this.menuIndex].style.marginTop = (self.menuHeight[menuIndex]*-1)+(this.direction==1?0:-1)+(self.tweens[this.menuIndex][this.frameIndex])+'px';
        }
      }
      this.frameIndex += this.direction;
    }

    this.reset = function(msg) {
      this.active = 0;
      this.timers = [];
      if (this.frameIndex >= self.tweens[this.menuIndex].length) {
        this.frameIndex = self.tweens[this.menuIndex].length-1;
      }
    }
    
    this.clearTimers = function() {
      for (var i=0; i<this.timers.length; i++) {
        clearTimeout(this.timers[i]);
      }
      this.timers = [];
    }

    this.eventHandler = function(e) {
      e = e||window.event;
      if (e.relatedTarget || e.target) {
        var eRelatedTarget = self.findNode(e.relatedTarget);
        var eTarget = self.findNode(e.target);
      }
      if (e.type == 'mouseover' && !e.srcElement) {
        if (e.target == this) {
          me.move(1);
        } else if (e.target) {
        }
      } else if (e.type == 'mouseover') {
        me.move(1);
      } else if (e.type == 'mouseout' && !e.srcElement) {
        if (e.target == this) {
          if (!menu.isChildOfId('nav-group'+me.menuIndex,eRelatedTarget)) {
            me.move(-1);
          }
        } else if (!menu.isChildOfId('nav-group'+me.menuIndex,eRelatedTarget)) {
          me.move(-1);
        }
      } else if (e.type == 'mouseout') {
        if (!menu.isChildOfId('nav-group'+me.menuIndex,e.toElement)) {
          me.move(-1);
        }
      }
    }
    
    this.hide = function() {
      with (self.containers[me.menuIndex].style) {
        if (visibility != 'hidden') visibility = 'hidden';
      }
    }
    
    this.show = function() {
      with (self.containers[me.menuIndex].style) {
        if (visibility != 'visible') visibility = 'visible';
      }
    }
    
    this.moveStatic = function(direction,evt) {
      if (direction==1) {
        me.show();
      } else {
        me.hide();
      }
    }
    
    this.move = function(direction) {
      if (this.active == 0) {
        this.clearTimers();
        if (this.frameIndex>1 && direction==1) {
          return false;
        } 
        this.active = 1;
        this.direction = direction;
        this.timeout = 0;
        for (var i=0; i<self.tweens[this.menuIndex].length; i++) {
          this.timeout += 20;
          this.timers[this.timers.length] = setTimeout("menu.menuItems["+this.menuIndex+"].animate()",this.timeout);
        }
        this.timers[this.timers.length] = setTimeout("menu.menuItems["+this.menuIndex+"].reset()",this.timeout);
      } else {
        this.clearTimers();
        this.reset();
        this.timeout = 0;
        this.direction = (this.direction==-1?1:-1);
        if (this.direction==1) {
          for (var i=this.frameIndex; i<self.tweens[this.menuIndex].length; i++) {
            this.timeout += 20;
            this.timers[this.timers.length] = setTimeout("menu.menuItems["+this.menuIndex+"].animate()",this.timeout);
          }
        } else {
          for (var i=this.frameIndex; i>0; i--) {
            this.timeout += 20;
            this.timers[this.timers.length] = setTimeout("menu.menuItems["+this.menuIndex+"].animate()",this.timeout);
          }
        }
        this.timers[this.timers.length] = setTimeout("menu.menuItems["+this.menuIndex+"].reset()",this.timeout);
      }
    }
    
  } 

  this.supported = true;
  
  if (ua.isMac && layeredFlash) {
    this.supported = false;
    return null;
  }
  
  if (ua.isMac && (ua.isSafari || ua.isIE || ua.equivalentMozilla < 1.0)) {
    this.supported = false;
  } else if (ua.isMac && ua.equivalentMozilla>=1.1 && !layeredFlash) {
    this.supported = true;
  } else if (ua.isMac) {
    this.supported = false;
  } else if (ua.isWin32) {
    if ((ua.isNS && ua.equivalentMozilla<1.1) || ua.isNS6x) {
      this.supported = false;
    }
  }
  
  if (ua.isNS6x) {
    setTimeout("menu.ns6Fix()",20); 
  }
  
  if (layeredFlash) {
    if (ua.isWin) {
      if (!ua.isNS && !ua.isIE) {
        return false;
      }
    }
    if (ua.isNS && ua.equivalentMozilla < 1) {
      return false;
    }
  }
  
  this.init();
  this.createTweens();
}

window.onload = function()
{
  menu = new Menu(-1,-1,true);
}

function FlashLibrary(){
    var t = this;
    var activeX = false;
    t.ieAutoInstall = false;
    t.hasVersion = function(ver){
        t.swf = false;
        if(!ver) ver = 0;
        var n = navigator;
        if(n.plugins && n.plugins.length > 0){
            var m,tp,d,v;
            m = n.mimeTypes;
            tp = 'application/x-shockwave-flash';
            if(m && m[tp] && m[tp].enabledPlugin && m[tp].enabledPlugin.description){
                d = m[tp].enabledPlugin.description;
                v = d.charAt(d.indexOf('.')-1);
                t.swf = (v >= ver) ? true : false;
            }
        }else if(n.appVersion.indexOf("Mac") == -1 && window.execScript){
            for(var i=ver; i<=7&&i!=1&&t.swf!=true; i++){
                execScript('on error resume next: flash.swf=IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash'+((i==0)?'':'.'+i)+'"))','VBScript');

            }
            if(t.swf) {
                activeX = true;
           }


        }else{
            t.swf = false;
        }
        return t.swf;
    }
    t.getPluginTag = function(swfFile,width,height,bgcolor,ver,altFormat,params){
        var s = '';
        var safari = (navigator.userAgent.toLowerCase().indexOf('safari') != - 1);
        var win = (navigator.appVersion.toLowerCase().indexOf("win")!=-1);
        var ie = (navigator.appName=="Microsoft Internet Explorer");
        if(t.hasVersion(ver) && swfFile || (win && ie && swfFile && t.ieAutoInstall)){
            var additionalParams = '';
            if(params && params.length>0){
                var pArray = params.split(",");
                for(var i=0; i<pArray.length; i++){
                    var ta = pArray[i].substr(0,pArray[i].indexOf('='));
                    var v = pArray[i].substr(pArray[i].indexOf('=')+1,pArray[i].length);
                    additionalParams += (activeX)?'\t<param name="' + ta + '" value="' + v + '" />\n': ' '+ ta + '="' + v + '"';
                }
            }
            if(activeX){
                s = '<object id="flashObj" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,21,0" width="'+width+'" height="'+height+'">\n';
                s += '\t<param name="movie" value="'+swfFile+'" />\n';
                s += '\t<param name="quality" value="high" />\n';
                s += '\t<param name="menu" value="false" />\n';
                s += '\t<param name="bgcolor" value="'+bgcolor+'" />\n';
                s += additionalParams;
                s += altFormat;
                s += '</object>\n';
                return s;
            }else{
                s = '<embed id="flashObj" src="'+swfFile+'" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" bgcolor="'+bgcolor+'"'+additionalParams+(safari?' class="safari"':'')+'></embed>\n';
                return s;
            }
        }else{
            return altFormat;
        }
    }
    t.embedMovie = function(swfFile,width,height,bgcolor,ver,altFormat,params){
        document.write(flash.getPluginTag(swfFile,width,height,bgcolor,ver,altFormat,params));
        }
}
var flash = new FlashLibrary();

function BrowserDetect() {
  var ua = navigator.userAgent.toLowerCase();
  this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
  this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);
  this.isKonqueror   = (ua.indexOf('konqueror') != -1);
  this.isSafari      = (ua.indexOf('safari') != - 1);
  this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
  this.isOpera       = (ua.indexOf('opera') != -1);
  this.isIcab        = (ua.indexOf('icab') != -1);
  this.isAol         = (ua.indexOf('aol') != -1);
  this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) );
  this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
  this.isFirebird    = (ua.indexOf('firebird/') != -1);
  this.isFirefox     = (ua.indexOf('firefox/') != -1); 
  this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
  this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
  this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
  this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
  this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
  this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
  this.versionMinor = parseFloat(navigator.appVersion);
  if (this.isGecko && !this.isMozilla) {
    this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
  } else if (this.isMozilla) {
    this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
  } else if (this.isIE && this.versionMinor >= 4) {
    this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
  } else if (this.isKonqueror) {
    this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
  } else if (this.isSafari) {
    this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
  } else if (this.isOmniweb) {
    this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
  } else if (this.isOpera) {
    this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
  } else if (this.isIcab) {
    this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
  }
  this.versionMajor = parseInt(this.versionMinor);
  this.isDOM1 = (document.getElementById);
  this.isDOM2Event = (document.addEventListener && document.removeEventListener);
  this.mode = document.compatMode ? document.compatMode : 'BackCompat';
  this.isWin    = (ua.indexOf('win') != -1);
  this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
  this.isMac    = (ua.indexOf('mac') != -1);
  this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
  this.isLinux  = (ua.indexOf('linux') != -1);
  this.isNS4x = (this.isNS && this.versionMajor == 4);
  this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
  this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
  this.isNS4up = (this.isNS && this.versionMinor >= 4);
  this.isNS6x = (this.isNS && this.versionMajor == 6);
  this.isNS6up = (this.isNS && this.versionMajor >= 6);
  this.isNS7x = (this.isNS && this.versionMajor == 7);
  this.isNS7up = (this.isNS && this.versionMajor >= 7);
  this.isIE4x = (this.isIE && this.versionMajor == 4);
  this.isIE4up = (this.isIE && this.versionMajor >= 4);
  this.isIE5x = (this.isIE && this.versionMajor == 5);
  this.isIE55 = (this.isIE && this.versionMinor == 5.5);
  this.isIE5up = (this.isIE && this.versionMajor >= 5);
  this.isIE6x = (this.isIE && this.versionMajor == 6);
  this.isIE6up = (this.isIE && this.versionMajor >= 6);
  this.isIE4xMac = (this.isIE4x && this.isMac);
}
var ua = new BrowserDetect();