﻿jQuery.noConflict();
jQuery("html").addClass("js");
/*
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>

(function($) { $.fn.hoverIntent = function(f, g) { var cfg = { sensitivity: 7, interval: 100, timeout: 0 }; cfg = $.extend(cfg, g ? { over: f, out: g} : f); var cX, cY, pX, pY; var track = function(ev) { cX = ev.pageX; cY = ev.pageY; }; var compare = function(ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); if ((Math.abs(pX - cX) + Math.abs(pY - cY)) < cfg.sensitivity) { $(ob).unbind("mousemove", track); ob.hoverIntent_s = 1; return cfg.over.apply(ob, [ev]); } else { pX = cX; pY = cY; ob.hoverIntent_t = setTimeout(function() { compare(ev, ob); }, cfg.interval); } }; var delay = function(ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); ob.hoverIntent_s = 0; return cfg.out.apply(ob, [ev]); }; var handleHover = function(e) { var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget; while (p && p != this) { try { p = p.parentNode; } catch (e) { p = this; } } if (p == this) { return false; } var ev = jQuery.extend({}, e); var ob = this; if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); } if (e.type == "mouseover") { pX = ev.pageX; pY = ev.pageY; $(ob).bind("mousemove", track); if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout(function() { compare(ev, ob); }, cfg.interval); } } else { $(ob).unbind("mousemove", track); if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout(function() { delay(ev, ob); }, cfg.timeout); } } }; return this.mouseover(handleHover).mouseout(handleHover); }; })(jQuery);
*/

/*
* jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
*/
jQuery.easing['jswing'] = jQuery.easing['swing'];
jQuery.extend(jQuery.easing,
{
    def: 'easeOutQuad',
    swing: function(x, t, b, c, d) {
        //alert(jQuery.easing.default);
        return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
    },
    easeOutQuad: function(x, t, b, c, d) {
        return -c * (t /= d) * (t - 2) + b;
    },
    // t: current time, b: begInnIng value, c: change In value, d: duration
    easeOutExpo: function(x, t, b, c, d) {
        return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
    }
});

(function($) {
	hideNav = function(nav) {
		nav = $(nav);
		var pos = nav.data("pos");
		
		nav.animate({"top": pos.hidden +"px"}, 300);
	};
	
	showNav = function(nav) {
		nav = $(nav);
		var pos = nav.data("pos");
		
		nav.siblings(".subnav").each(function(){ hideNav(this) });
		nav.animate({"top": pos.shown +"px"}, 300);
	};

	initMenu = function() {
		$("#topnav").each(function(){
			var $nav = $(this);
			
			if($.browser.msie)
				$nav.append('<div class="shadow"></div>');
			
			var maxSubnavH = 0;
			var navH = $(" > ul:first", $nav).outerHeight();
			
			$(" > ul ul", $nav).each(function() {
				var $lvl2_nav = $(this);
				// Save reference to the sub nav (lvl 2) on the parent LI
				var li = $lvl2_nav.parent().data("nav", $lvl2_nav);
				
				var navPos = {shown: navH, hidden: (navH - $lvl2_nav.outerHeight())};
				
				// Give the sub nav a classname and Move it to the nav container
				$lvl2_nav
					.data("parentLI", li)
					.data("pos", navPos)
					.addClass("subnav")
					.css({"top": navPos.hidden +"px"})
					.appendTo($nav);
				
				maxSubnavH = Math.max(maxSubnavH, $lvl2_nav.outerHeight());
				
				// Activate hover events on the LI and on sub nav
				li
				.mouseenter(function(e) {
					var cLI = $(this);
					
					clearTimeout(cLI.data("closeTO"));
					
					cLI.data("openTO",
						setTimeout(function() {
							var cNav = $(cLI.data("nav"));
							showNav(cNav);
						}, 200)
					);
				})
				.mouseleave(function(e) {
					var cLI = $(this);
					clearTimeout(cLI.data("openTO"));
					
					cLI.data("closeTO",
						setTimeout(function() {
							hideNav($(cLI.data("nav")));
						}, 500)
					);
				});
				
				$lvl2_nav
				.mouseenter(function(e) {
					clearTimeout($($(this).data("parentLI")).data("closeTO"));
				})
				.mouseleave(function(e) {
					var nav = $(this);
					$(nav.data("parentLI")).data("closeTO", setTimeout(function() { hideNav(nav); }, 400));
				});
			});
			
			$nav.css({"padding-bottom": maxSubnavH +"px", "margin-bottom": -maxSubnavH +"px", "overflow": "hidden"});
		});
	};
})(jQuery);

jQuery(function() {
	initMenu();
});

/*jQuery(function($) {
    Engine = {
        ui: {
            menu: function() {
                $("#topnav > ul ul").slideUp(0);
                $("#topnav > ul > li").hoverIntent(
					function() {
					    $(this).addClass("selected").find("ul").slideDown("normal", "easeOutExpo");
					},
					function() {
					    $(this).removeClass("selected").find("ul").slideUp("fast");
					}
				);
            }
        }
    }
});

jQuery(document).ready(function($) {
    Engine.ui.menu();
});*/
    

