jQuery(document).ready(function() {
  jQuery().backgroundSwitcher.init();
  jQuery().hideAllExcept.init();
});

// Hide All Except
jQuery.fn.hideAllExcept = {
  init: function() {
    var hash = window.location.hash;

    (!hash) ?
        jQuery('div.content').addClass('hide')
            : jQuery().hideAllExcept.hideShow(window.location.hash);

    jQuery('a.toggle').click(function() {
        var href = jQuery(this).attr('href');
        jQuery().hideAllExcept.hideShow(href);
        //jQuery().backgroundSwitcher.switchBackgrounds();
        window.location.hash = href;
        return false; // prevents the window from scrolling to the anchor
    });
      
  },
  hideShow: function(el) {
      //jQuery(el).removeClass('hide').siblings().addClass('hide');
      
      jQuery('div.content').addClass('hide');
      
      if (jQuery(el + "-content .content").hasClass('show')) {
        jQuery(el + "-content .content").hide("normal").removeClass('show').addClass('hide');
      } else {
        jQuery('.show').hide("normal").removeClass('show').addClass('hide');
        jQuery(el + "-content .content").show("normal").addClass('show').removeClass('hide');
      }
      
      jQuery('a.toggle').removeClass('active');
      jQuery('a[href="' + el + '"]').addClass('active');
  }
}


// Switch Background Image
jQuery.fn.backgroundSwitcher = {
  init: function() {
    jQuery().backgroundSwitcher.switchBackgrounds();
  },
  
  switchBackgrounds: function() {
    // var randNum = Math.ceil(Math.random()*6);
    jQuery('body').addClass('image' + Math.ceil(Math.random()*6));
  }
};

