/**
 * DropDownMenu for global navi
 * Powered by hisato http://chibinowa.net/
 * http://sjam.chibinowa.net/eid/162
 */
var DropDownMenu = {
  /* 開くまでの待ち時間 */
  open_sleep: 100,
  /* 閉じるまでの待ち時間 */
  close_sleep: 500,

  timer: null,
  active_oid: null,

  // 開くメイン
  open: function(target_id)
  {
    // 開いているメニューを閉じる
    if (this.timer) {
      if (this.active_oid == target_id)
        clearTimeout(this.timer);
      else
        this._close();
    }
    this.active_oid = target_id;
    this.timer = setTimeout("DropDownMenu._open();", this.open_sleep);
    $(document.documentElement).bind("click", DropDownMenu._close);
  },

  // 閉じるメイン
  close: function()
  {
    if (this.timer)
      clearTimeout(this.timer);
    this.timer = setTimeout("DropDownMenu._close();", this.close_sleep);
  },

  _open: function()
  {
    var obj = document.getElementById(this.active_oid);
    obj.style.visibility = "visible";
  },

  _close: function()
  {
    document.getElementById(DropDownMenu.active_oid).style.visibility = "hidden";
    $(document.documentElement).unbind("click");
    clearTimeout(DropDownMenu.timer);
    delete DropDownMenu.timer;
  }

};
var parseUri =  function (str) {
  this.url = str;
  this.options = {
    strictMode: false,
    key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
    q:   {
      name:   "queryKey",
      parser: /(?:^|&)([^&=]*)=?([^&]*)/g
    },
    parser: {
      strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
      loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
    }
  }
  
  this.parse = function(){
    var o   = this.options,
      m   = o.parser[o.strictMode ? "strict" : "loose"].exec(this.url),
      uri = {},
      i   = 14;

    while (i--) uri[o.key[i]] = m[i] || "";

    uri[o.q.name] = {};
    uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
      if ($1) uri[o.q.name][$1] = $2;
    });

    return uri;
  }
  
  this.hier = function(strD){
    var u = strD;
    var c = u.split('/');
    c[0] = 'home';
    for(i = 0; i < c.length; i++){
     if(c[i].length == 0){
      c.splice(i,1);
     }
    }
    if (c[c.length - 1].match(/[^0-9]/g)) {
    }else{
      c.splice(c.length - 1,1);
    }
    return c.join(':');
    
  }

  this.type = function(strD){
    var u = strD;
    var c = u.split('/');
    c[0] = 'home';
    for(i = 0; i < c.length; i++){
     if(c[i].length == 0){
      c.splice(i,1);
     }
    }
    return 
    
  }

  
  this.itemID = function(strD){
    var u = strD;
    var c = u.split('/');
    c.reverse();
    for(i = 0; i < c.length; i++){
     if(c[i].length == 0){
      c.splice(i,1);
     }
    }
    if (c[0].match(/[^0-9]/g)) {
      return '';
      }else{
      return c[0];
    }
  }
  
};
