jQuery(document).ready(function () {

  setTheme();
  var validPages = new Array('home','artists');
  if(typeof jQuery.getUrlVar('p') != 'undefined'){
    requestedPage = jQuery.getUrlVar('p').toLowerCase();
    if(jQuery.inArray(requestedPage, validPages) >= 0){
      jQuery('#outer').attr('class',requestedPage);
    }
  }
  addTransparentLayers();
  setBrowserClass('body');
  jQuery('.isIE6 #logoAndLinks').supersleight();

});

jQuery.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return jQuery.getUrlVars()[name];
  }
});

function setBrowserClass(classElement){
  newClass = 'notIE';
  if(coreJS.isIE()){
    newClass = 'isIE isIE'+coreJS.isIE();
  }
  jQuery(classElement).addClass(newClass);
}

function setTheme(){
  // Ftom the image array contained within #backgroundImages, choose one at random and assign it as the background image to the body
  jQuery('body').css('background-image','url('+jQuery('#backgroundImages img')[Math.floor(Math.random() * (jQuery('#backgroundImages img').length))].src+')');
}



function addTransparentLayers(){
  var oElClass = 'opaque';
  jQuery('.setOpacity').each(
    function(){
      
      // If position value is 'static', make it 'relative'
      jQuery(this).css('position',(jQuery(this).css('position') == 'static') ? 'relative' : jQuery(this).css('position'));

      // Wrap existing content
      jQuery(this).wrapInner('<div class="solid"/>');
      
      // Create opaque element and add to dom
      newEl = jQuery("<div class='"+oElClass+"'>").appendTo(jQuery(this));
      
      // Size opaque element to match parent
      jQuery(newEl).css({'width' : jQuery(this).innerWidth()+'px', 'height' : jQuery(this).innerHeight()+'px'});
    }
  );
}


function coreJS(){
}

  coreJS.isIE = function(){
    if (jQuery.browser.msie) {
      return parseInt(jQuery.browser.version, 10);
    }
    else{
      return false;
    }
  }
  
  coreJS.isHome = function(){
    if(jQuery('body.home').length > 0) {
      return true;
    }
    else{
      return false;
    }
  }


/*
  Removed conditional logic in each iteration.
  Browser type/version should only be checked once, 
  and function only called in the case of IE6.
*/
jQuery.fn.supersleight = function(settings) {
  settings = jQuery.extend({
    imgs: true,
    backgrounds: true,
    shim: 'img/spacer.gif',
    apply_positioning: true
  }, settings);
  return this.each(function(){
    jQuery(this).find('*').andSelf().each(function(i,obj) {
      var self = jQuery(obj);
      // background pngs
      if (settings.backgrounds && self.css('background-image').match(/\.png/i) !== null) {
        var bg = self.css('background-image');
        var src = bg.substring(5,bg.length-2);
        var mode = (self.css('background-repeat') == 'no-repeat' ? 'crop' : 'scale');
        var styles = {
          'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')",
          'background-image': 'url('+settings.shim+')'
        };
        self.css(styles);
      };
      // image elements
      if (settings.imgs && self.is('img[src$=png]')){
        var styles = {
          'width': self.width() + 'px',
          'height': self.height() + 'px',
          'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='scale')"
        };
        self.css(styles).attr('src', settings.shim);
      };
      // apply position to 'active' elements
      if (settings.apply_positioning && self.is('a, input') && (self.css('position') === '' || self.css('position') == 'static')){
        self.css('position', 'relative');
      };
    });
  });
};

