(function($) {

/*
 * clickMe - Click menu with a list to move also content
 *
 * Copyright (c) 2008 Alejadro Barrero Plazas (xoyaz.com)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * $Date: 05-10-2008 09:40:17 -0400 (Sun, 05 Oct 2008) $
 * $Rev: 1 $
 */

	$.fn.clickMe = function(op_user) {
		
		var menuName = this,				
			op = $.extend( cm.op_default , op_user);
			
		$(menuName).find("li:has(ul)").addClass("arrow");
		// move content to inicial margin
		$(op.moveIt).css({ marginTop: op.moveItMargin });
		
		//  anchor inside menu active the code
		$(menuName).find("a").click(function() {
		
			var ulsVisible = $(menuName).find("ul").is(":visible");
			var testUl = $(this).next("ul").is(":visible");
			
			// hide and remove op.activeMenu class from visible list inside the menu 
			if (ulsVisible) {
				// know if the anchor that active the function is visible
				if(testUl) {					
					$(menuName).find("li").removeClass(op.activeMenu);
					$(this).next("ul").animate(op.aniHide, op.speed, moveContent() );			
				} else {
					$(menuName).find("li").removeClass(op.activeMenu);						
					$(menuName).find("ul").animate(op.aniHide, op.speed);
					$(this).parent("li").addClass(op.activeMenu);
					$(this).next("ul").animate(op.aniShow, op.speed , moveContent() );
				}
			} else {
				$(this).parent("li").addClass(op.activeMenu);
				$(this).next("ul").animate( op.aniShow, op.speed, moveContent() );			
			}
		});
			
		// Move content 
		function moveContent() {
				
			var ulHeight = $("."+op.activeMenu +" ul").height() ;
			var moveMargin = parseFloat($(op.moveIt).css("margin-top"));
			var dif = ulHeight + op.moveItMargin - moveMargin;					
						
			if (ulHeight == moveMargin) {

			} else if (ulHeight < moveMargin) {			
				$(op.moveIt).animate({marginTop: "+=" + dif}, op.speed);

			} else if (ulHeight > moveMargin){
				$(op.moveIt).animate({marginTop: "+=" + dif}, op.speed);			
				
			}				 							
		}
		
	};

	var cm = $.fn.clickMe;
	cm.op = {};
	cm.op_default = {
		activeMenu: "current",
		moveIt: ".content",
		moveItMargin : 0,
		aniShow: { opacity: "show", height: "show"},
		aniHide: { opacity: "hide", height: "hide"},
		speed: "slow"
	};

})(jQuery);



