jQuery(document).ready(function($) {
   var active = null;
   var current = null;
   var inside = false;
   var insideZoom = false;
   var activeZoom = null;
   
   $("li.main").mouseover(function() {
      inside = true;
      if ($(this).hasClass('current')) {
         current = this;
      }
      if (active != this && active != null) {
         $(active).removeClass('active');
         if (active == current) {
            $(active).addClass('current');            
         }
         $kids_1 = $(active).children();
         $kids_1.each(function(i){
            if ($(this).hasClass("main")) {
               $(this).removeClass('active');
               if (active == current) {
                  $(this).addClass('current');            
               }
            }
         });
      }
      $(this).removeClass('current');
      $(this).addClass('active');
      
      var $kids = $(this).children();
      $kids.each(function(i){
         if ($(this).hasClass("main")) {
            $(this).addClass('active');
            if (active == current) {
               $(this).removeClass('current');               
            }
         }
         if ($(this).hasClass("submenu")) {
            $(this).show();
         }
      });
   });
   $("li.main").mouseout(function() {
      inside = false;
      if(active != this.id) {
         active = this;
      }
      var $kids = $(this).children();
      $kids.each(function(i){
         if ($(this).hasClass("submenu")) {
            $(this).hide();
         }
      });
   });
    
   $("div#container").mouseover(function(){
      if (active != null && inside == false) {
         $(active).removeClass('active');
         if (active == current) {
            $(active).addClass('current');
         }
         var $kids_1 = $(active).children();
         $kids_1.each(function(i){
            if ($(this).hasClass("main")) {
               $(this).removeClass('active');
               if (active == current) {
                  $(this).addClass('current');
               }
            }
         }); 
      }
      if (activeZoom != null && activeZoom == false) {
         $(activeZoom).hide();
         $("a.zoom").next().hide(); 
      }
   });
   
   $("a.zoom").mouseover(function(){
      $("a.zoom").next().hide(); 
      $(this).next().show();
      activeZoom = $(this).next();
      insideZoom = true;
   });
   
   $("div.view").mouseout(function(){
      $(this).hide();
      insideZoom = false;
   });
});
