//Global events are events which may take place in an area generated by an ajax callback
function setGlobalEvents() {
	
	$(".commentSpamMenu").click(function(event) {
		event.preventDefault();
		$(this).next(".efMenu").toggle("slow");
	});
	
	//alert($(".commentSpamMenu").click());
	
	$(".commentSpamMenu").next(".efMenu").children("ul").children("li").children("a").click(function(event) {
			event.preventDefault();
			//$("#comments").slideUp("slow");
			var block = $(this).attr("title");
			var commentId = $(this).parent().parent().siblings(".idf_commentId").attr("value");

			//$("#commentTypeFilter").attr("value", type);
			$.ajax({
				method: "get",url: "app/spam.php",data: "block="+block+"&commentId=" + commentId, 
				beforeSend: function(){
					$("#loading").show("fast");
				},
				complete: function(){
					$("#loading").hide("fast");
				},
				success: function(html){
					$(this).next(".spamStatus").show("slow");
					alert(html);
				}
			});
	});
}

$(document).ready(function(){
	$("div").filter(".navLvl").hide();
	
	$("button")
	.filter(".cancelConfirmBox")
		.click(function(){
			$(this).parents(".confirmBox").hide();
		})
   .end();
   
	$("a")
	.filter(".more")
		.click(function(event){
			event.preventDefault();
			var nextMenu = $(this).parents(".sideLink").next();
			if(nextMenu.is(':hidden')) {
				nextMenu.show("fast");
			} else {
				nextMenu.hide("fast");
			}
			$(this).toggleClass("active");
		})
	.end();	

	$("#comStats").click(function(event) {
		event.preventDefault();
		$("#commentNumbers").dialog({
			resizable: false,
			width: 400,
			height: 200,
			buttons:{ "Close": function() { $(this).dialog("destroy"); }},
			close: function(ev, ui) { $(this).dialog("destroy"); }
		});
	});
	
	$(".infoMenu a").hoverIntent(function() {
	  $(this).next("span").animate({opacity: "show", top: "-100"}, "slow");
	}, function() {
	  $(this).next("span").animate({opacity: "hide", top: "-120"}, "fast");
	});
	
	$("input.hexColor").focus(function() {
		$(this).parent(".formElement").siblings(".formElement").children(".colorPicker").remove();
		if ( $(this).siblings(".colorPicker").length == 0 ) {
			var cp = new colorPicker($(this).attr("id")+"cp", $(this).attr("id"), $(this).attr("value"),5);
			cp.draw();
			$(this).siblings(".colorPicker").hide();
			$(this).siblings(".colorPicker").show("fast");
		}
	});
	
	$(".formElement").children().focus(function() {
		$(this).parent(".formElement").addClass("active");
	});
	
	$(".formElement").children().blur(function() {
		$(this).parent(".formElement").removeClass("active");
	});
	setGlobalEvents();
});

