/**
 * Apply TopMenuItemHover functionality
 */

var costerShowMenuTimeout;
function topMenuItemHover(){
  var childrens = $('#menu_mainMenu').children();
  for( var i = 0; i < childrens.length; i++ ){
    $(childrens[i]).hover(
      function(){
    	  costerShowMenuTimeout = setTimeout("showSubMenu()", 300);
      },
      function(){
    	  clearTimeout(costerShowMenuTimeout);
      }
  	);
  }
}


/**
 * Show SubMenu
 */
function showSubMenu(){
  var childrens = $('#menu_mainMenu').children();
  var subMenuAll = '';

  
  /* Generate subMenu */
  for( var i = 0; i < childrens.length; i++ ){
    subMenuAll += '<div id="column_numb_' + i + '" class="column">';
    
    if( $(childrens[i]).find('ul').html() != null )
      subMenuAll += '<ul>' + $(childrens[i]).find('ul').html() + '</ul>';
    else
      subMenuAll += '&nbsp;';
    
    subMenuAll += '</div>';
  }
  subMenuAll += '<div class="column_last"><div id="column_numb_last">&nbsp;</div></div>';
  subMenuAll += '<div class="clearAll"></div>';
  $('#mainMenu_subContainer').html( subMenuAll );
  
  
  /* Replace ID with CLASS for selected element */
  $('#mainMenu_subContainer').find('li.active').removeAttr('class').removeAttr('id').addClass('current');
 
  
  /* Set height */
  var height = $('#mainMenu_subContainer').height() + 30;
//alert( height );
  for( var k = 0; k < i; k++ )
  	$('#column_numb_' + k).height( height );
  $('#column_numb_last').height( height );
  
  /* Show subMenu */
  $('#mainMenu_subContainer').fadeIn( 500, function(){ $(this).css({ 'display': 'block' }); } );
  

  
  /* Hide subMenu */
  $('#wrapper').hover(
  	function(){
    },
    function(){
      $('#mainMenu_subContainer').fadeOut( 500, function(){ $(this).css({ 'display': 'none' }); } );
    }
  );
  $('#whitebox').hover(
	function(){
      $('#mainMenu_subContainer').fadeOut( 500, function(){ $(this).css({ 'display': 'none' }); } );
    },
    function(){
    }
  );
  $('#tabslider_list').hover(
	function(){
      $('#mainMenu_subContainer').fadeOut( 500, function(){ $(this).css({ 'display': 'none' }); } );
    },
    function(){
    }
  );
  $('#header').hover(
	function(){
      $('#mainMenu_subContainer').fadeOut( 500, function(){ $(this).css({ 'display': 'none' }); } );
    },
    function(){
    }
  );
 /*$('#tabmenu').hover(
    function(){
    },
    function(){
      $('#mainMenu_subContainer').fadeOut( 500, function(){ $(this).css({ 'display': 'none' }); } );
    }
  );*/
}
