//==============================================================
//  Commons
//==============================================================

function findSection() {
  var section = $('body').attr('class')
  return section
}

function findExhibit() {
  var exhibit = $('#wrapper').attr('class')
  return exhibit
}

//==============================================================
//  Navigation
//==============================================================

function setMenu() {
  if (findSection() == 'section-1' || findSection() == 'section-7' || findSection() == 'section-8' || findSection() == 'contact' || findSection() == 'order') {
    $('#sidebar #menu ul').click(showElements)
                          .find('li')
                          .not('.section-title')
                          .toggle()
    if (findSection() == 'contact' || findSection() == 'newsletter' || findSection() == 'order') {
      switch(findSection()) {
        case 'contact':
          $('#section-1 li.section-title a').addClass('selected')
          break
        case 'newsletter':
          $('#section-1 li.section-title a').addClass('selected')
          break
        case 'order':
          $('#what li.section-title a').addClass('selected')
          break
      }      
    } else {
      $('#' + findSection() + ' li.section-title a').addClass('selected')
    }    
  } else {
    $('#what li.section-title a').addClass('selected')
    $('#mn-' + findSection() + ' a').attr('class','selected')
  }

  $('#what li').not('.section-title').find('a').click(showThumbnails)
}

function showThumbnails() {
  var section = $(this).attr('href')
  
  if (findSection() == section) {
    return false
  }
  
  if (findSection() == "order") {
    $('#img-description').hide()
  }

  hideThumbnails()
  
  if (findSection() == 'section-1' || findSection() == 'section-7') {
    $('#content').width('435px').css('padding','0 0 0 330px')
  }
  
  $('#' + section).show()
  $('#submenus').show()
  $('#what li').not('.section-title').find('a').attr('class','deselected')
  $(this).attr('class','selected')
  $('body').attr('class',section)
  hideImages()
  return false
}

function showElements() {
  hideImages()
  $('#menu .selected').attr('class','deselected')
  if ($(this).find('li').not('.section-title').css('display') == "none") {
    $(this).find('li').not('.section-title').toggle()
    $(this).find('li.section-title a').addClass('selected')
  }  
}

//==============================================================
//  Thumbnails
//==============================================================

function setThumbnails() {
  $('#submenus a').mouseover(function() {
                    $(this).css('opacity','0.5')})
                  .mouseout(function() {
                    $(this).css('opacity','1')})
  
  if ($('#' + findExhibit())) {
    $('#' + findExhibit() + ' a').unbind('mouseover')
                                 .unbind('mouseout')
  }
  
  if ($('#' + findExhibit())) {
    $('#' + findExhibit() + ' a').css('opacity','0.5') 
  }
}

function displayThumbnailMenu(section) {
  if ($('#' + findExhibit())) {
    $('#' + findExhibit() + ' a').css('opacity','0.5') 
  }
  $('#submenus').show()
  $('#' + section).show()
}

function hideThumbnails() {
  $('#submenus').hide().find('ul').hide()
}

//==============================================================
//  Images
//==============================================================

function hideImages() {
  if (findSection() != 'section-6') {
    if ($('#img-container').css('display') != 'none') {
      $('#img-container').hide()
    }
    
    if (findSection() != "order") {
      if ($('#img-description').css('display') != 'none') {
        $('#img-description').hide()
      }
    }
  }  
}