/*******************************************************************************************/	
// jquery.event.hover.js - rev 5 
// Copyright (c) 2008, Three Dub Media (http://threedubmedia.com)
// Liscensed under the MIT License (MIT-LICENSE.txt)
// http://www.opensource.org/licenses/mit-license.php
// Created: 2008-06-02 | Updated: 2008-07-30
/*******************************************************************************************/

(function($){$.fn._hover=$.fn.hover;$.fn.hover=function(fn1,fn2,fn3){if(fn3)this.bind('hoverstart',fn1);if(fn2)this.bind('hoverend',fn3?fn3:fn2);return!fn1?this.trigger('hover'):this.bind('hover',fn3?fn2:fn1);};var hover=$.event.special.hover={delay:100,speed:100,setup:function(data){data=$.extend({speed:hover.speed,delay:hover.delay,hovered:0},data||{});$.event.add(this,"mouseenter mouseleave",hoverHandler,data);},teardown:function(){$.event.remove(this,"mouseenter mouseleave",hoverHandler);}};function hoverHandler(event){var data=event.data||event;switch(event.type){case'mouseenter':data.dist2=0;data.event=event;event.type="hoverstart";if($.event.handle.call(this,event)!==false){data.elem=this;$.event.add(this,"mousemove",hoverHandler,data);data.timer=setTimeout(compare,data.delay);}
break;case'mousemove':data.dist2+=Math.pow(event.pageX-data.event.pageX,2)
+Math.pow(event.pageY-data.event.pageY,2);data.event=event;break;case'mouseleave':clearTimeout(data.timer);if(data.hovered){event.type="hoverend";$.event.handle.call(this,event);data.hovered--;}
else $.event.remove(data.elem,"mousemove",hoverHandler);break;default:if(data.dist2<=Math.pow(data.speed*(data.delay/1e3),2)){$.event.remove(data.elem,"mousemove",hoverHandler);data.event.type="hover";if($.event.handle.call(data.elem,data.event)!==false)
data.hovered++;}
else data.timer=setTimeout(compare,data.delay);data.dist2=0;break;}
function compare(){hoverHandler(data);};};})(jQuery);

(function($) {
	/*
		jquery.dropSlideMenu.js v1.0
		Last updated: 24 July 2009

		Created by Damien du Toit
		http://coda.co.za/blog/2009/07/24/dropslidemenu

		Licensed under a Creative Commons Attribution-Non-Commercial 3.0 Unported License
		http://creativecommons.org/licenses/by-nc/3.0/
	*/

	$.fn.dropSlideMenu = function(options) {

		$.fn.dropSlideMenu.defaults = {
			indicators: true, // adds a div to the list items for attaching indicators (arrows)
			openEasing: "easeOutQuad", // open animation effect
			closeEasing: "easeInQuad", // close animation effect
			duration: 600, // speed of drop down animation (in milliseconds)
			delay: 800, // delay before the drop down closes (in milliseconds)
			hideSelects: true // hide all select elements on the page when the menu is active (IE6 only)
		};

		var o = $.extend({}, $.fn.dropSlideMenu.defaults, options);

		return this.each(function() {
			window.container = $(this).children("ul:first");
			window.lists = container.find("ul");
			window.listItems = lists.parent();
			window.timer = null;
			window.count = 1;

			// add class to container
			//container.addClass("ds");
			
			// inject float clearer
			//var clear = "<div class=\"dsClear\">&nbsp;</div>";
			//container.append(clear);

			lists.each(function() {
				// assign unique id, hide list
				$(this).attr("id", "dsList-" + count).css({ display: "none", visibility: "visible" });

				count++;
			});

			count = 1;

			listItems.each(function() {
				var listItem = $(this);
				var list = listItem.children("ul:first");
				var link = listItem.children("a:first");

				// wrap indicator markup
				if (o.indicators) {
					link.wrap("<div class=\"indicator\"></div>");
				}

				// assign unique id
				//listItem.attr("id", "dsListItem-" + count);
				
				$.event.special.hover.delay = 80;

				listItem.hover(function() {
					if ($(this).hasClass("open")) {
						if (timer) {
							// reset timer
							window.clearTimeout(timer);
							timer = null;
						}
					}
					else {
						// hide all menus
						lists.hide();

						// reset all list item styles
						listItems.removeClass("open").removeClass("active");

						// reset timer
						window.clearTimeout(timer);
						timer = null;

						// open menu
						openList($(this));
					}
				}, 
				function() { 
					timer = setTimeout(function() {
						// close menu
						closeList(list.parent());
					}, o.delay);
		        });

				function openList(li) {
					// hide select elements in IE6
					if (o.hideSelects && $.browser.msie && parseInt($.browser.version) < 7) {
						$("select").css("visibility", "hidden");
					}

					// add style
					li.addClass("open");

					// open menu
					list.show("slide", {duration: o.duration, direction: "up", easing: o.openEasing}, function() {
					});
				}

				function closeList(li) {
					// reset timer
					timer = null;

					// close menu
					list.hide("slide", {duration: o.duration, direction: "up", easing: o.closeEasing}, function() {
						// remove style
						li.removeClass("open");

						// show select elements in IE6
						if (o.hideSelects && $.browser.msie && parseInt($.browser.version) < 7) {
							$("select").css("visibility", "visible");
						}
					});	
				}

				count++;
			});

			// Internet Explorer fix
			if ($.browser.msie) {
				container.find("li ul li a").css({ zoom: 1, verticalAlign: "top" });
			}

			// behaviour for links with empty href's
			$("a[href$='#']", container).css({cursor: "default"}).click(function() { return false; });

			//container.show();
		});
	};
})(jQuery);
