//*****Collapse sidebar**************************************************//
function collapseSidebar() {
  jQuery('#sidebarNav ul').css({display: 'none'})
  jQuery('#sidebarNav .showMenu').toggle(
    function(){
      jQuery(this).parent().parent().find('ul').css({display: 'block'});
      jQuery(this).parent().addClass('selected');
      return false;
    },
    function(){
      jQuery(this).parent().parent().find('ul').css({display: 'none'});
      jQuery(this).parent().removeClass('selected');
      return false;
    }
  );
}
//*****Extend the footer to the bottom of the page**************************************************//
var prevHeight;
function extendFooter() {
  var footerHeight = jQuery('#footer').height();
  var pageHeight = jQuery(document.body).height();
  var windowHeight = jQuery(document).height();
  if(prevHeight == windowHeight){
    return;
  }
  prevHeight = windowHeight;
  var difference = windowHeight - pageHeight;
  if (pageHeight < windowHeight) {
    jQuery('#footer').height(footerHeight + difference);
  } else {
    jQuery('#footer').height('52px');
  }
}
//*****Switch the featured product on the homepage**************************************************//
function featuredProducts() {
  if (!document.getElementById('featuredRotation')) return false;
  var number;
  jQuery('#featuredRotation ul li a').click(function() {
    jQuery('#featuredRotation ul li a').removeClass('selected');
    jQuery(this).addClass('selected');
    number = jQuery(this).html();
    jQuery('.home-page-item').addClass('hide');
    jQuery('#featured'+number).removeClass('hide');
    return false;
  });
}

//*****Load all functions**************************************************//
jQuery(document).ready(function(){
  collapseSidebar();
  extendFooter();
  featuredProducts();
});
jQuery(window).bind('resize',extendFooter);
