function g(id) {return document.getElementById(id)}
function gg(o, t) {return o.getElementsByTagName(t)}
Object.toArray = function(o) {
   var r = [], l = o.length, i = 0
   if (o.length) {
      for (; i < l; i++) r.push(o[i])
   } else {
      for(i in o) r.push([i, o[i]])
   }
   return r
}
Array.prototype.copy = function(o) {
   return this.concat();
}
function addAttr(o, a) {if (typeof o == 'object') o[a[0]] = a[1]; return o}
if (!Array.prototype.reduce)
{
   Array.prototype.reduce = function(fun , initial)
   {
      var len = this.length;
      var i = 0;
      if (arguments.length >= 2) var rv = arguments[1];
      else
         do
         {
            if (i in this)
            {
               rv = this[i++];
               break;
            }
            if (++i >= len)
               throw new TypeError();
         }
         while (true);
      for (; i < len; i++)
         if (i in this) rv = fun.call(null, rv, this[i], i, this);
      return rv;
   }
}
Array.prototype.pack = function(n){
   a  = this.copy(), rv = []
   while(a.length) rv.push(a.splice(0, n))
   return rv
}
function n(/*o, s, [attr,val...]*/) {
   var v = Object.toArray(arguments).pack(2), e = v.shift()
   return v.reduce(addAttr, e[0].appendChild(document.createElement(e[1])))
}
function addStyleSheet(path) {
   return n(gg(document, 'head').item(0), 'link', 'rel', 'stylesheet', 'type', 'text/css', 'href', path)
}
///////////////
function setStyle(name) {
	var oldStyle, newStyle = addStyleSheet('styles/' + name + '.css')
	if (oldStyle = g('tmpCss')) gg(document, 'head').item(0).removeChild(oldStyle)
	newStyle.id = 'tmpCss';
}
