/* made by RJ - emperor */
$(function() {
  var oOpenMenu;

  function selectOption() {
    var hash = this.href.split('#')[1];
    $.history.load(hash);
    var id = $(this).index('.dropdown ul li a');
    showImageNo(id);
    return false;
  };

  function showImage() {
    showImageNo($(this).index('.dropdown ul li a'));
  };

  function showImageNo(id) {
    $('.dropdown img').hide();
    $('.dropdown img').eq(id).show();
  };

  function showMenu() {
    oOpenMenu = $(this).parent('.dropdown').find('.content');
    oOpenMenu.slideToggle();
    return false;
  }

  function hideMenu() {
    if (oOpenMenu != null) {
      oOpenMenu.slideUp();
      oOpenMenu = null;
    }
  }

  $('.dropdown img').hide();
  $('.dropdown img').eq(0).show();
  $('.dropdown .content').hide();
  $('.dropdown .content a').hover(showImage);

  $('#whichProduct .dropdown .content a').click(selectOption);
  $('*').click(hideMenu);

  $('.dropdown a.dropdowntrigger').unbind('click').click(showMenu);

  $('div.results div.result').hide();
  $.history.init(function(hash) {
    if (hash != "") {
      $('div.results div.result').hide();
      $('#' + hash +"_res").show();
    }
  });

});
