function $A(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) return iterable.toArray();
  var length = iterable.length || 0, results = new Array(length);
  while (length--) results[length] = iterable[length];
  return results;
}

Function.prototype.bind = function() {
  if (arguments.length < 2 && typeof arguments[0] == "undefined") return this;
  var __method = this, args = $A(arguments), object = args.shift();
  return function() {
    return __method.apply(object, args.concat($A(arguments)));
  }
};

/*function $$(id) {
  return document.getElementById(id);
}*/

function Element(tag, options) {
  var elem = document.createElement(tag);
  for(var i in options) {
    elem[i] = options[i];
  }
  
  return elem;
}

function mh_Utils() {
  
  this.objSelectToList = function(select) {
    var selected = "";
    var html = "";
    
    var i = 0;
    var j = select.options.length;
    while(i < j) {
      html += '<li><span class="mh_ComboBox">' + i + "</span><span>" + select.options[i].innerHTML + "</span></li>";
      
      ++i;
    }
    
    if(j > 0) {
      html = '<div id="mh_ComboBox_' + select.id + '" class="mh_ComboBox">' +
        "<h2>" + select.options[select.selectedIndex].innerHTML + "</h2>" +
        "<ul>" + html + "</ul>" +
        "</div>";
    }
    
    
    return html;
  };
  
  this.getLeft = function(elem) {
      xPos = elem.offsetLeft;
      
      tempEl = elem.offsetParent;
      while(tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
      }
    
      
      return xPos;
  };

  this.getTop = function(elem) {
    yPos = elem.offsetTop;
    
    tempEl = elem.offsetParent;
    while(tempEl != null) {
      yPos += tempEl.offsetTop;
      tempEl = tempEl.offsetParent;
    }
    
    
    return yPos;
  };
  
  this.loadJS = function(file, exec) {
    if(typeof eval(exec) != "function") {
      $.ajax({
        type: "GET",
        url: file,
        dataType: "script"
      });
    } else {
      eval(exec)();
    }
  };
  
  this.loadCSS = function(file, id) {
    var loaded = 0;
    if((id != undefined) && (id != "") && ($$(id) != undefined) && ($$(id) != null)) {
      loaded = 1;
    }
    
    if(loaded == 0) {
      var elem = "<link";

      if((id != undefined) && (id != "")) {
        elem += ' id="' + id + '"';
      }
      
      elem += ' href="' + file + '" rel="stylesheet" type="text/css" />';
      
      $(elem).appendTo("head");
    }
  };
}

var mh_util = new mh_Utils();