Array.prototype.random = function() {
  return this[Math.floor(Math.random() * this.length)];
}

function $(e) {
  if(typeof e=='string') e = document.getElementById(e);
  return e
  };

var rand = function(num) {
  return Math.floor(Math.random() * num);
}
  
var addEvent = (function() {
  if ( window.addEventListener ) {
    return function(el, type, fn) {
      el.addEventListener(type, fn, false);
    };
  } else if ( window.attachEvent ) {
    return function(el, type, fn) {
      var f = function() {
        fn.call(el, window.event);
      };
      el.attachEvent('on'+type, f);
    };
  } else {
    return function(el, type, fn) {
      element['on'+type] = fn;
    }
  }
})();

var xhr = (function() {
if (window.XMLHttpRequest) {
  // Firefox、Safari、Internet Explorer 7.0など向け
  xhr = new XMLHttpRequest();
} else {
  // Internet Explorer 6.0以前向け
  try {
    xhr = new ActiveXObject("Msxml2.XMLHTTP"); // 6.0用
  } catch(e) {
    try {
      xhr = new ActiveXObject("Microsoft.XMLHTTP"); // 5.5以前用
    } catch(e) {
      return null;
    }
  }
}
})();

var Util = {
toFullSize: function(str) {
  return str.replace(/([a-zA-Z])/g, function(m0, m1) {
    return String.fromCharCode(m1.charCodeAt(0) + 65248);
  });
},
toHalfSize: function(str) {
  return str.replace(/([ａ-ｚＡ-Ｚ])/g, function(m0, m1) {
    return String.fromCharCode(m1.charCodeAt(0) - 65248);
  });
},
keys: function(obj) {
  var ary = [];
  for (var k in obj) {
    ary.push(k);
  }
  return ary;
},
random: function(ary) {
  return ary[Math.floor(Math.random() * ary.length)];
}
}

var createElm = function(tag, attr, css) {
  var elm = document.createElement(tag);
  var style = elm.style;
  for (var k in attr) {
    elm.setAttribute(k, attr[k]);
  }
  for (var k in css) {
    style[k] = css[k];
  }
  return elm;
}

var typingMotion = function(elm, str, sec) {
  if (typeof str != "string") return;
  sec = sec || 100;
  var i = 0;
  var interval = setInterval(function() {
    if (i > str.length) clearInterval(interval);
    elm.appendChild(document.createTextNode(str.charAt(i)));
    i++;
  }, sec);
  return elm;
}