$(function() {

	
});

$(document).ready(function() {

	$('textarea.TextArea').tinymce({
		// Location of TinyMCE script
		script_url : '../js/tiny_mce.js',
		
		// General options
		theme : "advanced",
		plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",
		
		// Theme options
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,fontselect,fontsizeselect,bullist,numlist,undo,redo,link,unlink,image,forecolor,backcolor,emotions",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_buttons4 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,
		
		// Example content CSS (should be your site CSS)
		//content_css : "css/content.css",
		
		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",
		
		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});	
		
	$(".Hover LI").mouseover(function() {
		$(this).css("background-color", "#5da2e5");
	});
		
	$(".Hover LI").mouseout(function() {
		$(this).css("background-color", "#83bcf1");
	});
	
	$("A.DelUserGuestbook").click (function() {
		$("." + $(this).attr("id")).fadeOut(500);
		$.ajax({
			type: 	"POST",
			url: 		"includes/DelUserGuestbook.php",
			data: 	"id=" + $(this).attr("id")
		});
	});

	$("A.DelGuestbook").click (function() {
		$("." + $(this).attr("id")).fadeOut(500);
		$.ajax({
			type: 	"POST",
			url: 		"includes/DelGuestbook.php",
			data: 	"id=" + $(this).attr("id")
		});
	});
								
	$('#codes').tabs({ fxSlide: true });									
								
	$(".Browser").click ( function() {
		$('html, body').animate({scrollTop:0}, 'slow');
		$("#BackgroundCover").css("display", "block");
		$("#UploadBrowser").fadeIn(1000);
	});
			
	$("#BackgroundCover").click ( function() {
		$('#JUploader li').each ( function() {
			var swfu = $.swfupload.getInstance('#JUploader');
			swfu.cancelUpload($(this).attr('id'));
			$(this).slideUp('fast');				
		  });
		$("#BackgroundCover").css("display", "none");
		$("#UploadBrowser").css("display", "none");
		$("#TagWindow").css("display", "none");
	});
	
	$("#UploadBrowser A.close").click ( function() {
		$('#JUploader li').each ( function() {
			var swfu = $.swfupload.getInstance('#JUploader');
			swfu.cancelUpload($(this).attr('id'));
			$(this).slideUp('fast');				
		  });	
		$("#BackgroundCover").css("display", "none");
		$("#UploadBrowser").css("display", "none");
		$("#TagWindow").css("display", "none");
	});
	
	$("A.AddCat").click ( function() {
		$('#CatChar').html($(this).attr('rel'));
		$('html, body').animate({scrollTop:0}, 'slow');
		$("#BackgroundCover").css("display", "block");
		$("#UploadBrowser").css("min-height", "200px");
		$("#UploadBrowser").fadeIn(1000);
		GroupID = $(this).attr("id");
		$("#CatID").val(GroupID);
	});		
	
	SpanHeight	= $("#DetailBlok SPAN.Image").height();
	ImgHeight 	= $("#DetailBlok SPAN.Image IMG").height();
	
	MarginTop 	= Math.floor((SpanHeight - ImgHeight) / 2);
	$("#DetailBlok SPAN.Image IMG").css("margin-top", MarginTop);
	
	$("#TagDisplay").click ( function() {
		//$("#BackgroundCover").css("display", "block");
		$("#TagWindow").css("display", "block");
	});
	
	$("#AddTag").click (function() {
		$.ajax({
			type: 	"POST",
			url: 		"includes/AddTag.php",
			data: 	"id=" + $("#ImageID").val() + "&value=" + $("#TagValue").val() + "&t=" + $("#T").val() + "&userid=" + $("#UserID").val()
		});
		$("#BackgroundCover").fadeOut(500);
		$("#TagWindow").fadeOut(500);
	});	
	
	$(".DelImage").click( function() {
		id = $(this).attr("rel");
		$("#ImageOverview LI." + id).fadeOut(1000); 
		$.ajax({
			type: 	"POST",
			url: 		"includes/DeleteImage.php",
			data: 	"id=" + $(this).attr("id")
		});		
	});
	
	$(".AddFriend").click( function() {
		Check = confirm("Vrienden worden met deze gebruiker?");
		if(Check == true) {
			$.ajax({
				type: 	"POST",
				url: 		"includes/AddFriend.php",
				data: 	"id=" + $(this).attr('id')
			});		
			alert("Je uitnodiging is verstuurd, wacht op goedkeuring van de gebruiker.");
		}
	});
	
	$(".DelFriend").click( function() {
		Check = confirm("Weet je zeker dat je de vriendschap wil verwijderen.");
		if(Check == true) {
			$.ajax({
				type: 	"POST",
				url: 		"includes/DelFriend.php",
				data: 	"id=" + $(this).attr('id')
			});		
		}
	});	
	
	$(".ImageZoom").hover(function() {
		id 			= $(this).attr("rel");
		height 		= $("#" + id).height();
		width 		= $("#" + id).width();
		NewHeight = height * 3;
		NewWidth	= width * 3;
		
		$("." + id).css('z-index', '100');
		
		$("#" + id).addClass("hover").stop()
			.animate({
				height: '' + NewHeight +'',
				width: '' + NewWidth + ''
			}, 200);
		
		} , function() {
		$("." + id).css('z-index', '0');
		$("#" + id).removeClass("hover").stop()
			.animate({
				width: '' + width + '', 
				height: '' + height + ''
			}, 200);
	});	
	
	$("#AddCat").click ( function() {
		if($("#CatName").val() == "") {
			alert("Vul een categorie naam in.");
		} else {
			$.ajax({
				type: 	"POST",
				url: 		"includes/AddCategorie.php",
				data: 	"id=" + $("#CatID").val() + "&name=" + $("#CatName").val()
			});
		}
		var textarea = $('#CatName');
		var txt = textarea.val();
		setTimeout("window.location.href = '/" + $('#Cat').val() + "/" + textarea.val().replace(' ', '-') + "/';", 500);
	});		
	
	$('#Upload').click ( function() {
		$('#JUploader').swfupload('startUpload');
	});
		
	$('#Cancel').click ( function() {			
		$('#JUploader li').each ( function() {
			var swfu = $.swfupload.getInstance('#JUploader');
			swfu.cancelUpload($(this).attr('id'));
			$(this).slideUp('fast');				
		  });
	});		
	
});
