

(function() {

    function HoverMenu(jqObj, settings) {
	var $this 	= this;
	$this.jqObj 	= jqObj;
	$this.settings 	= settings;
	$this.HoverEls 	= new Array();
	this.mouseOutTimer = null;
	
	$($this.settings.root).each(function() {
	    $this.HoverEls.push(new HoverMenuItem($(this), $this));
	});

	return $this;
    }

    HoverMenu.prototype.hideAll = function() {
	var i;

	for (i = 0; i < this.HoverEls.length; i++) {
	    this.HoverEls[i].hide();
	}

	return this;
    }

    HoverMenu.prototype.hide = function(index) {
	return this.HoverEls[index].hide();
    }

    HoverMenu.prototype.show = function(index) {
	return this.HoverEls[index].show();
    }


    function HoverMenuItem(jqObj, pObj) {
	this.jqObj  = jqObj;
	this.pObj   = pObj;

	var $this   	= this;
	var position 	= this.jqObj.position();
	
	
	if (typeof(this.pObj.settings.offset) == "function") {
	    this.jqObj.children(this.pObj.settings.children).css("top", position.top + this.pObj.settings.offset(this.jqObj));
	} else {
	    this.jqObj.children(this.pObj.settings.children).css("top", position.top + this.pObj.settings.offset);
	}
		    

	if ((this.pObj.settings.timeout != null) && (this.pObj.settings.timeout > 0)) {

	    this.jqObj.hoverIntent({ 
		over 	: function() {
	    	clearTimeout(this.mouseOutTimer);
		    $this.pObj.hideAll();
		    $this.show();
		   // console.log("over 1");
		},
		out 	: function() {
			//console.log("out 1");
		},
		timeout	: $this.pObj.settings.timeout,
	        sensitivity	: $this.pObj.settings.sensitivity,
	        interval	: $this.pObj.settings.interval
	    });
	    
	    this.jqObj.children(this.pObj.settings.children).hoverIntent({
		over	: function() {
	    	clearTimeout(this.mouseOutTimer);
		    $this.pObj.hideAll();
		    $this.show();
		   // console.log("over 2");
	    }, 
		out	: function() {
	    	/*console.log("out 2");
			clearTimeout(this.mouseOutTimer);
			this.mouseOutTimer = setTimeout(function(){
				$this.hide();
			},1000);*/
		},
		timeout	: $this.pObj.settings.timeout,
	        sensitivity	: $this.pObj.settings.sensitivity,
	        interval	: $this.pObj.settings.interval
	    });
	    $(".myMenu").mouseleave(function(e) {
	    	//console.log("out 3");
	    	clearTimeout(this.mouseOutTimer);
	    	this.mouseOutTimer = setTimeout(function(){	
	    			$this.pObj.hideAll();
	    	},1000);
	    	
	    });		
	    $(".myMenu").mouseover(function(e) {
	    	//console.log("over 3");
	    	clearTimeout(this.mouseOutTimer);
	    	
	    });		
	    $(".myMenu li").mouseover(function(e) {
	    	//console.log("over 4");
	    	clearTimeout(this.mouseOutTimer);
	    });		    
	} else {
	    this.jqObj.mouseenter(function() { 
	    	$this.pObj.hideAll();
	    	$this.show();
	    });
	/*    this.jqObj.mouseleave(function() { 
	    	$this.pObj.hideAll();
	    });	    
	/*    this.jqObj.children(this.pObj.settings.children).mouseenter(function() { 
	    	$this.pObj.hideAll();
	    	$this.show();
	    });
	    */	    
	    this.jqObj.children(this.pObj.settings.children).mouseleave(function() {
		$this.hide();
	    });
	}

	return this;
    }

    HoverMenuItem.prototype.hide = function() {
	return this.jqObj.children(this.pObj.settings.children).hide();
    }

    HoverMenuItem.prototype.show = function() {
	return this.jqObj.children(this.pObj.settings.children).show();
    }

    

    $.hoverMe = { 
	HoverMees: new Array(),

	settings: {
	    children: ".hoverItem",
	    root    : ".root",
	    offset  : function(obj) {
		return $(obj).innerHeight();
	    },
	    timeout : null,
	    sensitivity	: 7,
	    interval	: 100
	},

	init: function(jqObj, params) {
	    var settings = $.extend($.hoverMe.settings, params || {});

	    $.hoverMe.HoverMees.push(new HoverMenu(jqObj, settings));
        }
    }

    $.fn.hoverMe = function(params) {
	return this.each(function() {
	    	$.hoverMe.init(this, params); 
		});
    }   
   
    
})(jQuery);


function showMenuItems(){
 	$(this).find('.mbmenu').css('display','block');
}
function hideMenuItems(){

}
$(document).ready(function() {

    $(".myMenu").hoverMe({
        root: ".rootVoice",
        children: ".mbmenu",
        timeout: 100,
        sensitivity: 5,
        interval: 100


      });
      
    //	mouseout menu fix
	/*
   $('.myMenu').mouseout(function() {
		$('.myMenu li div').hide();
	});
    
	$('.myMenu a').click(function() {
		$('.myMenu li div').hide();
	});
	/*
	$(".main-nav li").bind("mouseover",function(){
		$("#"+this.id+" div").css("display","block");
	});
	
	$(".main-nav li").bind("mouseout",function(){
		$("#"+this.id+" div").css("display","none");	
	});
		*/
});
/*
$(document).ready(function() {

	var config = {    
	     over: showMenuItems, // function = onMouseOver callback (REQUIRED)    
	     timeout: 500, // number = milliseconds delay before onMouseOut    
	     out: hideMenuItems // function = onMouseOut callback (REQUIRED)    
	};
	
	
	$("#menuBarItem").hoverIntent( config );

});
/*
$(document).ready(function() {

    $(".myMenu").hoverMe({
        root: ".rootVoice",
        children: ".mbmenu",
        timeout: 500,
        sensitivity: 20,
        interval: 100
      });
//mouseout menu fix
$('.myMenu').mouseout(function() {
       $('.myMenu li div').delay(500).fadeOut(400);
});

$('.myMenu a').click(function() {
       $('.myMenu li div').delay(300).fadeOut(200);
});
});*/

/*


*/
