var linkedCSS = new Array(), linkedJS = new Array();
var randomizer = (((location.href).search(/.loc\//i) != -1) ? '?r=' + Math.random() : '');

$.extend({
  headCSS : function(filename)
  {
    if (jQuery.inArray(filename, linkedCSS) == -1) {
      $('head').append('<link href="' + 
      filename + randomizer + 
      '" rel="stylesheet" media="all" />');
      linkedCSS = linkedCSS.concat([filename]);
    }
  },
  headJS : function(filename)
  {
    if (jQuery.inArray(filename, linkedJS) == -1) {
      $('head').append('<script type="text/javascript" src="' + 
      filename + randomizer + 
      '"></script>');
      linkedJS = linkedJS.concat([filename]);
    }
  },
  uid : function()
  {
    var ss = [], tok = [8, 4, 4, 4, 12];
    for(var i = 0; i < 5; i++) {
      var s = '';
      for (var j = 0; j < tok[i]; j++) {
        var r = parseInt(Math.random() * 16);
        r = r < 10 ? r : (
          r == 10 ? 'A' : (
          r == 11 ? 'B' : (
          r == 12 ? 'C' : (
          r == 13 ? 'D' : (
          r == 14 ? 'E' : 'F')))));
        s+= r;
      }
      ss = ss.concat([s]);
    }
    return ss.join('-').toUpperCase();
  },
  width : function()
  {
    return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
  },
  height : function()
  {
    return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;
  },
  scrollHeight : function()
  {
    var h = window.pageYOffset ||
            document.body.scrollTop ||
            document.documentElement.scrollTop;
    return h ? h : 0;
  },
  scrollWidth : function()
  {
     var w = window.pageXOffset ||
             document.body.scrollLeft ||
             document.documentElement.scrollLeft;
             
     return w ? w : 0;
  }
})


$.fn.extend({
  iframeCover : function()
  {
    if (!$.browser.msie) return;
    
    $.each($(this), function(){
    
    });
  },
  centrize : function(onresize)
  {
    onresize = onresize || false;
    var T = this;
    $(T).css('position', 'absolute');
    var setToCenter = function(elem, speed) {
      $(elem).animate({
        left: (($(window).width()  - $(elem).width())  / 2) + 'px',
        top : (($(window).height() - $(elem).height()) / 2 + $.scrollHeight()) + 'px'
      }, speed);
    }
    setToCenter($(T), 0);
    if (onresize) {
      $(window).resize(function(){
        setToCenter($(T), 'fast');
      });
      $(window).scroll(function(){
        setToCenter($(T), 0);
      });
    }
  },
  top : function(val)
  {
    if (val != undefined) {
      return parseInt($(this).css('top'));
    } else {
      val = val || 0;
      $(this).css('top', parseInt(val) + 'px');
      return parseInt(val)
    }
  },
  left : function(val)
  {
    if (val != undefined) {
      return parseInt($(this).css('left'));
    } else {
      val = val || 0;
      $(this).css('left', parseInt(val) + 'px');
      return parseInt(val)
    }
  }
})
