/*
$(document).ready(function(){
 $("ul.dropdown li").hover(function(){
   $(this).addClass("hover");
   $('> .dir',this).addClass("open");
   $('ul:first',this).css('visibility', 'visible');
 },function(){
     //$(this).animate({opacity: 1}, 3000, function() {
	    $(this).removeClass("hover");
        $('.open',this).removeClass("open");
        $('ul:first',this).css('visibility', 'hidden');
	//  });
 });
});
*/
$(document).ready(function(){
	var config = {    
		sensitivity: 6,
		interval: 100,
		over: showSubMenu,
		timeout: 500,
		out: hideSubMenu
	};
	$("ul.dropdown li").hoverIntent(config);	
	$("ul.dropdown li").each(hideSubMenu);
	
	/*
	var config2 = {    
		sensitivity: 6,
		interval: 100,
		over: showTT,
		timeout: 500,
		out: hideTT
	};
	$(".toolTip").hoverIntent(config2);	
	$(".toolTip").each(hideTT);
	//$(".toolTip").click(function(){ showTT(); });
	*/
	
	var tmptip = '';
	
	$('.toolTip').hover(
			function(e) {
				this.tip = this.title;
				tmptip = this.title;
				this.title = '';
				$('#toolTipWrapper').html('<div class="toolTipTop"></div><div class="toolTipMid">'+this.tip+'</div><div class="toolTipBtm"></div>');
				var tmph = $('#toolTipWrapper').height();
				//alert(tmph);
				//$('#toolTipWrapper').css('top',e.pageY-(tmph+22)).css('left',e.pageX).css('visibility','visible'); 
				$('#toolTipWrapper').css('top',e.pageY-(tmph+22)).css('left',e.pageX);
				$('#toolTipWrapper').fadeIn(200);
				$(this).css('borderBottom','1px solid #000000');
			},
			function()
			{
				//alert('mouse out');
				this.title = tmptip;
				//$('#toolTipWrapper').css('visibility','hidden'); 
				$('#toolTipWrapper').css('display','none');
				$(this).css('borderBottom', '1px dotted #195900');
			}
	);
		

	function showTT()
	{
		//$(".toolTip").each(sendToBack).function(){ alert('done'); };
		this.tip = this.title;
		$('#toolTipWrapper').html('<div class="toolTipTop"></div><div class="toolTipMid">'+this.tip+'</div><div class="toolTipBtm"></div>');
		/*
		$(this).append(
			'<div class="toolTipWrapper">'
				+'<div class="toolTipTop"></div>'
				+'<div class="toolTipMid">'
					+this.tip
				+'</div>'
				+'<div class="toolTipBtm"></div>'
			+'</div>'
		);
		*/
		this.title = "";
		$(this).css('zIndex', '2');
		//$('.toolTipWrapper').css('display', 'block');
		//$('.toolTipWrapper').css('visibility', 'visible');
	}

	function hideTT()
	{
		$(".toolTip").each(sendToBack);
		//$('.toolTipWrapper').css('visibility', 'hidden');
		$(this).children().remove();
		this.title = this.tip;
	}

	$('.toolTip2').hover(
			function() {
			this.tip = this.title;
			var randomnumber1 = Math.floor(Math.random()*9999);
			var randomnumber2 = Math.floor(Math.random()*9999);
			var randid = 'tt'+randomnumber1+'-'+randomnumber2;
			
			//var cur = parseInt($(this).css('z-index'));
			//var nextz = cur + 1;
			//alert(nextz);
			
			$(this).append(
				'<div class="toolTipWrapper" id="'+randid+'">'
					+'<div class="toolTipTop"></div>'
					+'<div class="toolTipMid">'
						+this.tip
					+'</div>'
					+'<div class="toolTipBtm"></div>'
				+'</div>'
			);
			this.title = "";
			this.width = $(this).width();
			//$('.toolTip').css({zIndex:'-1'});
			//$('#'+randid); //.css({zIndex:nextz,color:'yellow'});
			$('#'+randid).fadeIn(300);
		},
		function() {
			//$(this).css({zIndex:'0'});
			//$('.toolTipWrapper').css({zIndex:'-1'});
			$('.toolTipWrapper').fadeOut(200);
			$(this).children().remove();
			this.title = this.tip;
			}
		);

}); // close document.ready

function showSubMenu(){
	$("ul.dropdown li").each(sendToBack);
	//$('ul:first',this).animate({opacity: 1}, 300, function() {
		//$('ul:first',this).css('opacity', '1');
		$(this).css('zIndex', '2');
		$(this).addClass("hover");
		$('> .dir',this).addClass("open");
		$('ul:first',this).css('visibility', 'visible');
	//});
}
function hideSubMenu(){
	//$('ul:first',this).animate({opacity:0}, 300, function() {
		$(this).removeClass("hover");
		$('.open',this).removeClass("open");
		$('ul:first',this).css('visibility', 'hidden');
	//});
	//$('ul:first',this).animate({opacity:0}, 300, function(){
	//	$(this).css('visibility', 'hidden');
	//});
}
function sendToBack(){
	$(this).css('zIndex', '1');
}

