(function($) {
	this.offx = 30;
	this.offy = 30;

	$.fn.vtip = function() {
		return this.each(function() {
			$(this).hover(
		        function(e) {
		            this.t = this.title;
		            this.title = ''; 
		            this.top = (e.pageY + offy); this.left = (e.pageX + offx);
            
		            $('body').append( '<p id="vtip" style="border:1px solid red">' + this.t + '</p>' );
                    $('p#vtip').css("top", this.top+"px").css("left", this.left+"px").fadeIn("slow");
            
		        },
		        function() {
		            $(this).attr('title', this.t);
		            $("p#vtip").fadeOut("slow").remove();
		        }
		    ).mousemove(function(e) {
	            this.top = (e.pageY + offy);
	            this.left = (e.pageX + offx);
                     
	            $("p#vtip").css("top", this.top+"px").css("left", this.left+"px");
	        });
		});
	};
})(jQuery);

////////////////
// Pearl Izumi Navigation for top menu
// ----------------------
////////////////

jQuery(function($) {
	var tdelay = 50;
	var timeout = -1;

	$('#nav .showDropdown').each(function() {
		var drop = $(this).next().appendTo($('#nav').parent());
		$(this).attr('href', '#' + drop.attr('id'));
	});
	
	$('#nav').delegate('a', 'mouseenter', function(e) {
		hideDropdowns();
		var link = $(this);

		$(link.attr('href')).each(function() {
			if (!$(this).data('moved')) {
				$(this).data('moved', true)
				.position({
					my: 'left top',
					at: 'left bottom',
					of: link});
			}

			$('.gender:first', this).addClass('first');
		}).fadeIn('fast', function() {
			$(this).addClass('visible').css('display', '');
			$(this).trigger('navopen');
		});
	});

	$('#nav').delegate('a', 'mouseleave', function(e) {
		timeout = setTimeout(hideDropdowns, tdelay);
	});
	
	$('.dropdownBox, .dropdownPrd').mouseleave(function(e) {
		timeout = setTimeout(hideDropdowns, tdelay);
		//$(this).removeClass('visible');
	}).mouseenter(stopTimeout);
	
	$('.gender').hover(function() {
		$(this).toggleClass('hover');
	}, function(e) {
		$(this).toggleClass('hover');
	});

	function hideDropdowns() {
		stopTimeout();
		$('.dropdownBox, .dropdownPrd').stop(true, true).fadeOut('fast', function() {
			$(this).removeClass('visible').css('display', '');
			$(this).trigger('navclose');
		});
	}

	function stopTimeout() {
		if (timeout >= 0) {
			clearTimeout(timeout);
			timeout = -1;
		}
	}
});
