(function($){

$.fn.setAnimateMenuOn = function(name, obj){
	$.fn.animateMenuOn = $.fn[name];
}

$.fn.setAnimateMenuOff = function(name, obj){
	$.fn.animateMenuOff = $.fn[name];
}

$.fn.animateMenuOn = function(){
}

$.fn.animateMenuOff = function(){
}

})(jQuery);

(function($){
$.fn.MenuBottom = function(options)
{
	 var defaults = {
	 	 actionClass: '',
	 	 top: '0px',
	 	 delay: 30,
	 	 animationLength:400,
	 	 eventStart: 'mouseover',
	 	 eventEnd: 'mouseout',
	 	 innerBlock: 'ul',
	 	 innerElem: 'li',
	 	 setWidth: 'auto',
	 	 animateFunctionOn:'slideDown',
	 	 animateFunctionOff:'slideUp'
         };
         var functions = {
         	delay: function(th, nmbr)
		{
			th.timeout = setTimeout(function(){
					if($(th).children(options.innerBlock).size() == 0)
					{
						$(th).children(options.innerBlock).css("display", "none");
						$(th).removeClass(options.actionClass);
					}
					else
					{
						$(th).children(options.innerBlock).stop(1, 1);
						$(th).children(options.innerBlock).animateMenuOff(options.animationLength, function(){
								$(th).removeClass(options.actionClass);
						});
					}
			}, nmbr);
		},
		start: function(th, obj)
		{
			var setWidth = options.setWidth;
			if(options.setWidth == 'auto')
			{
				setWidth = $(th).outerWidth()+"px";
			}
			clearTimeout(th.timeout);
			$(th).clearQueue();
			$(th).addClass(options.actionClass);
			$(th).children(options.innerBlock).css("top", options.top).stop(1, 1).animateMenuOn(options.animationLength).children(options.innerElem).css("width", setWidth);
		}
         };
        var options = $.extend(defaults, options); 
	return this.each(function() {
		var qobj = $(this);
		var obj = this;
		qobj.setAnimateMenuOn(options.animateFunctionOn);
		qobj.setAnimateMenuOff(options.animateFunctionOff);
		qobj.bind(options.eventStart, function(){
			functions.start(obj, obj);
		});
		qobj.bind(options.eventEnd, function(){
			functions.delay(this, options.delay);
		});
	});  
};  
})(jQuery);

(function($){

$.fn.MenuSide = function(options) 
{
	 var defaults = {
	 	  actionClass: '',
	 	  delay: 30,
	 	 animationLength:400,
	 	 eventStart: 'mouseover',
	 	 eventEnd: 'mouseout',
	 	 innerBlock: 'ul',
	 	 innerElem: 'li',
	 	 setWidth: 'auto',
	 	 setChildOffset: 'parent',//pozicija is kaires
	 	 animateFunctionOn:'slideDown',
	 	 animateFunctionOff:'slideUp'
         }; 
         var functions = {
         	delay: function(th, nmbr)
		{
			th.timeout = setTimeout(function(){
				if($(th).children(options.innerBlock).size() == 0)
					{
						$(th).children(options.innerBlock).css("display", "none");
						$(th).removeClass(options.actionClass);
					}
					else
					{
						$(th).children(options.innerBlock).stop(1, 1);
						$(th).children(options.innerBlock).animateMenuOff(options.animationLength, function(){
								$(th).removeClass(options.actionClass);
						});
					}
			}, nmbr);
		},
		start: function(th, obj)
		{
			var setWidth = options.setWidth;
			if(options.setWidth == 'auto')
			{
				setWidth = $(th).css("width");
			}
			clearTimeout(th.timeout);
			$(th).clearQueue();
			$(th).addClass(options.actionClass);
			$(th).children(options.innerBlock).css("display", "block").children(options.innerElem).css("width", setWidth);
			if(options.setChildOffset == 'parent')
			{
				var left = parseInt($(th).css("margin-right").replace("px", ""))+parseInt($(th).css("margin-left").replace("px", ""))+parseInt(setWidth.replace("px", ""))+"px";
			}
			else
			{
				var left = $(th).children(options.setChildOffset).innerWidth()+$(th).children(options.setChildOffset).position().left;
				var top = $(th).children(options.setChildOffset).position().top;
			}
			
			$(th).children(options.innerBlock).css("left", left).css("top", top+"px").stop(1, 1).animateMenuOn(options.animationLength);
		}
         };
        var options = $.extend(defaults, options);
	return this.each(function() {
		var qobj = $(this);
		var obj = this;
		qobj.setAnimateMenuOn(options.animateFunctionOn);
		qobj.setAnimateMenuOff(options.animateFunctionOff);
		qobj.bind(options.eventStart, function(){
			functions.start(obj, obj);
		});
		qobj.bind(options.eventEnd, function(){
			functions.delay(this, options.delay);
		});
	});
};  
})(jQuery);

(function($){  
$.fn.MenuShow = function(options) 
{
	 var defaults = {
	 	 actionClass: '',
	 	 delay: 30,
	 	 animationLength:400,
	 	 eventStart: 'mouseover',
	 	 eventEnd: 'mouseout',
	 	 innerBlock: 'ul',
	 	 elementSelect: 'children',
	 	 animateFunctionOn:'slideDown',
	 	 animateFunctionOff:'slideUp'
         };
         var functions = {
         	delay: function(th, nmbr)
		{
			if(th.menuOn == true)
			{
				th.timeout = setTimeout(function(){
					if($(th).children(options.innerBlock).size() == 0)
					{
						$(th).children(options.innerBlock).css("display", "none");
						$(th).removeClass(options.actionClass);
						th.menuOn = false;
					}
					else
					{
						$(th).children(options.innerBlock).stop(1, 1);
						$(th).children(options.innerBlock).animateMenuOff(options.animationLength, function(){
								$(th).removeClass(options.actionClass);
								th.menuOn = false;
						});
					}
				}, nmbr);
			}
		},
		start: function(th, obj)
		{
			clearTimeout(th.timeout);
			$(th).clearQueue();
			$(th).addClass(options.actionClass);
			$(th).children(options.innerBlock).stop(1, 1).animateMenuOn(options.animationLength, function(){
				obj.menuOn = true;
			});
		}
         };
        var options = $.extend(defaults, options); 
	return this.each(function() {
		var qobj = $(this);
		var obj = this;
		this.menuOn = false;
		elem = qobj;
		
		if(options.elementSelect != 'children')
		{
			var elem = qobj.children(options.elementSelect);
		}
		qobj.setAnimateMenuOn(options.animateFunctionOn);
		qobj.setAnimateMenuOff(options.animateFunctionOff);
		elem.bind(options.eventStart, function()
		{
			functions.start(obj, obj, qobj);
			elem.blur();
		});
		elem.bind(options.eventEnd, function(){
			functions.delay(obj, options.delay, qobj);
			elem.blur();
		});
	});  
};  
})(jQuery);

