/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Varien
 * @package     js
 * @copyright   Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

// Menu drop down handler
		
		
		jQuery.noConflict() ;
		
		if (jQuery.browser.msie && jQuery.browser.version.substr(0,1)<7) {
			// Doesn't work for IE < 7!
		} else {
			
			
			jQuery(document).ready(function() {
				function menuvar(){
					this.timerRef = [] ; 
					this.current  ;
					this.timers = [] ;
					this.refs = [] ;
					this.isFaded = [] ;
					this.temp = "" ;
				}
				
				
				var menu = new menuvar ;
				
				jQuery("#nav li.level0").mouseenter(function(){
				
					menu.current = '' ;
					
					var currentCatClasses = jQuery(this).attr('class').split(" ") ;
					
					jQuery.each(currentCatClasses, function(index, item){ 
					
						if(item.indexOf("nav") != -1){
							x = item.split("-") ;
							x = x[0] + x[1] ;
							menu.current += x ;
						}
						
						if(item.indexOf("level") != -1){
							
							x = item.split("-") ;
							x = x[0] ;
							menu.current += x ;
							
						}
						
						
					}) ;
					
					var currentIndex = "";
					
					if(menu.timerRef.lastIndexOf(menu.current) != -1){ 
					
						currentIndex = menu.timerRef.lastIndexOf(menu.current) ;
					} else {
						menu.timerRef.push(menu.current);
						menu.timers.push("");
						menu.refs.push("");
						menu.isFaded.push("0");
						currentIndex = menu.timerRef.lastIndexOf(menu.current) ;
					}
					
					clearInterval(menu.timers[currentIndex]);
					
					if(menu.isFaded[currentIndex] == 0){
						menu.refs[currentIndex] = jQuery(this) ;
						menu.timers[currentIndex] = setTimeout(function(){
							//jQuery(menu.refs[currentIndex]).find("ul.level0").fadeIn("fast", function(){menu.isFaded[currentIndex] = 1 ;});
							jQuery(menu.refs[currentIndex]).find("ul.level0 li.level1").css('height', jQuery(menu.refs[currentIndex]).find("ul.level0").height() + 'px');
							jQuery(menu.refs[currentIndex]).find("ul.level0").fadeTo("fast", 0.9, function(){menu.isFaded[currentIndex] = 1 ;});
						}, 400) ;
					}
					
				});
				
				jQuery("#nav li.level0").mouseleave(function(){
					
					menu.current = '' ;
					
					var currentCatClasses = jQuery(this).attr('class').split(" ") ;
					
					jQuery.each(currentCatClasses, function(index, item){ 
					
						if(item.indexOf("nav") != -1){
							x = item.split("-") ;
							x = x[0] + x[1] ;
							menu.current += x ;
						}
						
						if(item.indexOf("level") != -1){
							
							x = item.split("-") ;
							x = x[0] ;
							menu.current += x ;
							
						}
						
						
					}) ;
					
					var currentIndex = "";
					
					if(menu.timerRef.lastIndexOf(menu.current) != -1){ 
					
						currentIndex = menu.timerRef.lastIndexOf(menu.current) ;
					} else {
					
						menu.timerRef.push(menu.current);
						menu.timers.push("");
						menu.refs.push("");
						menu.isFaded.push(0);
						currentIndex = menu.timerRef.lastIndexOf(menu.current) ;
					}
	
					clearInterval(menu.timers[currentIndex]);
					
					if(menu.isFaded[currentIndex] == 1){
						menu.refs[currentIndex] = jQuery(this) ;
						menu.timers[currentIndex] = setTimeout(function(){
							jQuery(menu.refs[currentIndex]).find("ul.level0").fadeOut("fast", function(){menu.isFaded[currentIndex] = 0 ;});
							//jQuery(menu.refs[currentIndex]).find("ul.level0").fadeTo("fast", 0, function(){menu.isFaded[currentIndex] = 0 ;});
						}, 400);
					}
				});
				
				});
			}
