// JavaScript Document

$().ready(function() {
		
		// hide all cancel buttons (edit button is shown)
		$(".cancel").hide();
		
		// load tinymce	 -------------------
		$(".edit").click(function () { 
								   
			if ($(this).parent().parent().parent().attr("id") == 'homemid') {
			
				$(this).hide();
				$(this).next().show();
				var contents = $(this).parent().next("div").html();
				var url = $(location).attr('href');
				var field = $(this).parent().next("div").attr("id");
				var height = $(this).parent().next("div").attr("name")
				
				contents = "<form action='php/updatetext.php' method='post'><textarea class='tinymce' name='text' rows='" + height + "'>" + contents + "</textarea><input type='hidden' name='field' value='" + field + "' /><input type='hidden' name='url' value='" + url + "' /><input type='submit' /></form>";
				$(this).parent().next("div").html(contents);
									   
									   
				$(this).parent().next("div").find("textarea:first").tinymce({
				// Location of TinyMCE script
				script_url : 'js/tiny_mce/tiny_mce.js',
	
				// General options
				mode: "none",
				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 : "cut,copy,paste,|,bullist,numlist,|,undo,redo,|,link,unlink,image,media",
				theme_advanced_buttons2 : "hr,charmap,|,code,|,bold,italic,underline,strikethrough,|,forecolor,|,justifyleft,justifycenter,justifyright,justifyfull",
				theme_advanced_buttons3 : "styleselect,formatselect,fontsizeselect",
				theme_advanced_buttons4 : "tablecontrols",
				theme_advanced_toolbar_location : "top",
				theme_advanced_toolbar_align : "left",
				theme_advanced_statusbar_location : "top",
				theme_advanced_resizing : true,
	
	
				// Example content CSS (should be your site CSS)
				content_css : "http://www.gcknights.com.au/new/css/mcestyles.css", // ------------------- CHANGE WHEN UPLOADED
	
				// Drop lists for link/image/media/template dialogs
				external_link_list_url : "http://www.gcknights.com.au/new/js/linkslist.js",
				});
			}
			else {
				if ($(this).parent().parent().parent().attr("id") == 'contentleft') {
				
					$(this).hide();
					$(this).next().show();
					var contents = $(this).parent().next("div").html();
					var url = $(location).attr('href');
					var field = $(this).parent().next("div").attr("id");
					var height = $(this).parent().next("div").attr("name")
					
					contents = "<form action='php/updatetext.php' method='post'><textarea class='tinymce' name='text' rows='" + height + "'>" + contents + "</textarea><input type='hidden' name='field' value='" + field + "' /><input type='hidden' name='url' value='" + url + "' /><input type='submit' /></form>";
					$(this).parent().next("div").html(contents);
										   
										   
					$(this).parent().next("div").find("textarea:first").tinymce({
					// Location of TinyMCE script
					script_url : 'js/tiny_mce/tiny_mce.js',
		
					// General options
					mode: "none",
					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 : "cut,copy,paste,|,bullist,numlist,|,undo,redo,|,link,unlink,image,media,|,hr,charmap,|,code,",
					theme_advanced_buttons2 : "bold,italic,underline,strikethrough,|,forecolor,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontsizeselect",
					theme_advanced_buttons3 : "tablecontrols",
					theme_advanced_toolbar_location : "top",
					theme_advanced_toolbar_align : "left",
					theme_advanced_statusbar_location : "top",
					theme_advanced_resizing : true,
		
		
					// Example content CSS (should be your site CSS)
					content_css : "http://localhost:8888/css/mcestyles.css", // ------------------- CHANGE WHEN UPLOADED
		
					// Drop lists for link/image/media/template dialogs
					external_link_list_url : "http://localhost:8888/js/linkslist.js",
					});
				}
				else {
					if ($(this).parent().parent().parent().attr("id") == 'homeright' || $(this).parent().parent().parent().attr("id") == 'contentright' || $(this).parent().parent().parent().attr("id") == 'homeleft') {
			
						$(this).hide();
						$(this).next().show();
						var contents = $(this).parent().next("div").html();
						var url = $(location).attr('href');
						var field = $(this).parent().next("div").attr("id");
						var height = $(this).parent().next("div").attr("name")
						
						contents = "<form action='php/updatetext.php' method='post'><textarea class='tinymce' name='text' rows='" + height + "'>" + contents + "</textarea><input type='hidden' name='field' value='" + field + "' /><input type='hidden' name='url' value='" + url + "' /><input type='submit' /></form>";
						$(this).parent().next("div").html(contents);
											   
											   
						$(this).parent().next("div").find("textarea:first").tinymce({
						// Location of TinyMCE script
						script_url : 'js/tiny_mce/tiny_mce.js',
			
						// General options
						mode: "none",
						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 : "cut,copy,paste,|,bullist,numlist",
						theme_advanced_buttons2 : "link,unlink,image,media,|,hr,charmap,|,code",
						theme_advanced_buttons3 : "bold,italic,underline,strikethrough,|,forecolor,|,justifyleft,justifyfull",
						theme_advanced_buttons4 : "styleselect,formatselect",
						theme_advanced_buttons5 : "fontsizeselect",
						theme_advanced_toolbar_location : "top",
						theme_advanced_toolbar_align : "left",
						theme_advanced_statusbar_location : "top",
						theme_advanced_resizing : true,
			
			
						// Example content CSS (should be your site CSS)
						content_css : "http://localhost:8888/css/mcestyles.css", // ------------------- CHANGE WHEN UPLOADED
			
						// Drop lists for link/image/media/template dialogs
						external_link_list_url : "http://localhost:8888/js/linkslist.js",
						});
					}	
					else {
					
					if ($(this).parent().parent().parent().attr("id") == 'contentmid') {
				
					$(this).hide();
					$(this).next().show();
					var contents = $(this).parent().next("div").html();
					var url = $(location).attr('href');
					var field = $(this).parent().next("div").attr("id");
					var height = $(this).parent().next("div").attr("name")
					
					contents = "<form action='php/updatetext.php' method='post'><textarea class='tinymce' name='text' rows='" + height + "'>" + contents + "</textarea><input type='hidden' name='field' value='" + field + "' /><input type='hidden' name='url' value='" + url + "' /><input type='submit' /></form>";
					$(this).parent().next("div").html(contents);
										   
										   
					$(this).parent().next("div").find("textarea:first").tinymce({
					// Location of TinyMCE script
					script_url : 'js/tiny_mce/tiny_mce.js',
		
					// General options
					mode: "none",
					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 : "cut,copy,paste,|,bullist,numlist,|,undo,redo,|,link,unlink,image,media,|,hr,charmap,|,code,|,bold,italic,underline,strikethrough,|,forecolor,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontsizeselect",
					theme_advanced_buttons2 : "tablecontrols",
					theme_advanced_toolbar_location : "top",
					theme_advanced_toolbar_align : "left",
					theme_advanced_statusbar_location : "top",
					theme_advanced_resizing : true,
		
		
					// Example content CSS (should be your site CSS)
					content_css : "http://localhost:8888/css/mcestyles.css", // ------------------- CHANGE WHEN UPLOADED
		
					// Drop lists for link/image/media/template dialogs
					external_link_list_url : "http://localhost:8888/js/linkslist.js",
					});
					}
					}
				}
			}
		});
		
		// cancel tinymce -----------------------
		
		$(".cancel").click(function () { 
		  // remove tinymce, remove textarea (put contents in div)
		  $(this).prev().show();
		  $(this).hide();
		  $(this).parent().next("div").find("textarea:first").tinymce().hide();
		   var contents = $(this).parent().next("div").find("textarea:first").html();
		   $(this).parent().next("div").html(contents);
		});
		
		$('#slideshow').cycle({
			fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		});

});
