(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) {
				if($(this).attr("href")=="#"){ //make sure that that it's a menu dropdown link
				// know if the anchor that active the function is visible
				if(testUl) {					
					$(menuName).find("li").removeClass(op.activeMenu);
					moveContent(testUl); 
					$(this).next("ul").animate(op.aniHide, op.speed);		
				 $(this).children("img").attr("src","/images/expand-icon.png");
				} else {
					$(menuName).find("li").removeClass(op.activeMenu);						
					$(menuName).find("ul").animate(op.aniHide, op.speed);
					$(this).parent("li").addClass(op.activeMenu);
					moveContent(testUl);
					$(this).next("ul").animate(op.aniShow, op.speed );
				 $('.plinkimg').replaceWith( "<img src='/images/expand-icon.png' class='plinkimg' />" );
				 $(this).children("img").attr("src","/images/colapse-icon.png");
				}
				}
			} else {
				 $(this).children("img").attr("src","/images/colapse-icon.png");
				$(this).parent("li").addClass(op.activeMenu);
				moveContent();
				$(this).next("ul").animate( op.aniShow, op.speed);	

				
			}
		});
			
		// Move content 
		function moveContent(testUl) {
							
			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) {			
			if(testUl){
				$(op.moveIt).animate({marginTop: "+=" + dif}, op.speed);
			}
			} else if (ulHeight > moveMargin){
				$(op.moveIt).animate({marginTop: "+=" + dif}, op.speed);			
				
			}				 							
		}
		
		
$(".current ul").animate( { opacity: "show", speed:"slow"});	
				$(op.moveIt).css("margin-top", $("."+op.activeMenu +" ul").height() + op.moveItMargin);	
				 $(".current").children().children("img").attr("src","/images/colapse-icon.png");
	};
 
	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);



