/**************************************/
/****** CMS Functions Essentials ******/
/**************************************/

this.loadCMS = function(){	
	
	$(".login-this").click(function(){
		var path = $(this).attr("href");
		loadLogin(path);
		return false;
	});
	
	if (($('#cms').length > 0)&&($('#menu-admin-header').length == 0)) {
		loadLogin();
	} 
	if ($('#cms').length == 0) {
		$("#menu-admin-header").remove();
		loadIn();
	} else {
		
		$(document.body).append("<div id=\"container-cms\"><div id=\"body-cms\" class=\"align-center\"></div></div><div id=\"footer-cms\"></div>");
		var target_body = $('#body-cms');
		var target_footer = $('#footer-cms');
		
		$("#container, #supersize, #tab-background,#tab-contact-me").remove();

		$("html,body").css({
			background:'#f3f1f1',
			color:'#676764',
			fontFamily:'Arial, Helvetica, sans-serif',
			fontSize: '12px',
			overflow: 'visible',
			height: '100%'
		});
		
		if($('#menu-admin-header').length > 0)
		{
			target_body.html('<div><p><img src="'+http_root+rp_image_global+img_loader+'"/> loading</p></div>');
			target_body.load( http_root+rp_cms+"page_summary.php", function(){
				target_footer.load( http_root+rp_cms+"menu_admin_mysql_footer.php", function(){
					resetMenuAdmin();
					loadDashboard();
					loadIn();
					guide();
					$(".form h2").click(function(){
						$(this).next().next().slideToggle("slow");
						$(this).toggleClass("active");
						return false;
					});

				});	
			});
			
			//$("#menu-admin-header").css({display:'block'});
		}
		
	}
}

/*****************/

/**
load the dashboard when you click on the home button.
**/

this.loadDashboard = function(){	
	var target_body = $('#body-cms');
	$('#menu-admin-header > ul > li > a:first,#menu-admin-footer > ul > li > a:first').click(function(){
		var path = $(this).attr('href');
		//alert(path);
		target_body.html('<div><p><img src="'+http_root+rp_image_global+img_loader+'"/> loading</p></div>');
		target_body.load(path, function(){
			
			/** 
			first, you need to unbind all the loadIn function that attached to all <a> with the class of load-in, 
			otherwise you will attach the loadIn function to each of this <a> 
			whenever you click on the button of Home which is a <a> too.
			**/
			$('.load-in').unbind('click');
			
			/** 
			then you attach the loadIn function again.
			**/
			loadIn();
			guide();
			
			$(".form h2").click(function(){
				$(this).next().next().slideToggle("slow");
				$(this).toggleClass("active");
				return false;
			});
		});
		return false;
	});
}

/*****************/

/**
using index numbers
**/

this.loadDashboard_bk = function(){	
	var target_body = $('#body-cms');
	$('.menu-admin > ul > li > a').eq(0).click(function(){
		var path = $(this).attr('href');
		target_body.html('<div><p><img src="'+http_root+rp_image_global+img_loader+'"/> loading</p></div>');
		target_body.load(path, function(){
			$(".form h2").click(function(){
				$(this).next().next().slideToggle("slow");
				$(this).toggleClass("active");
				return false;
			});
		});
		return false;
	});
}

/*****************/

this.resetMenuAdmin = function(){	
			
	/**
	do not return the drop-down:level 1 when you click on it, accept the last item.
	
	$('#menu-admin-header > ul > li:not(:last) > a,#menu-admin-footer > ul > li:not(:last) > a').click(function(){
		return false;
	});
	
	$('.menu-admin > ul > li > a').click(function(){
		return false;
	});**/
	
	$('.menu-admin a').each(function () {
		if ( $(this).siblings().size() > 0 ) 
		{
			$(this).click(function(){
				return false;
			});
		}
	});
	
	/**
	loop through each <a>, if it has a sibling, then append the class of 'indicator'.
	reset the style of which has a sibling.
	**/
	$("#menu-admin-header a").each(function () {
		if ( $(this).siblings().size() > 0 ) 
		{
			$(this).append("<span class='menu-admin-sub-indicator'></span>");
			
			//get the width of each current <a>
			var width = $(this).width();
			//alert(width);
			
			$(this).css({
				//if you set a width or height on current <a>, the z-index won't work in IE
				//so you have to take out the width below.
				//use padding instead.
				//width: width+8+'px'
				padding: '2px 16px 1px 8px'
			});
		}
	});
	
	/**
	reset the style of the drop-down:level 1 when you hover it.
	**/
	$("#menu-admin-header > ul > li").hover(function () {
		if ( $('a',this).siblings().size() > 0 ) 
		{
			$('a',this).css({
				zIndex: '100',
				padding: '2px 16px 2px 8px'
			});				
		}
	},
	function(){
		if ( $('a',this).siblings().size() > 0 ) 
		{
			$('a',this).css({
				zIndex: '',
				padding: '2px 16px 1px 8px'
			});
		}
	});
	
	/**
	reset the style of all drop-down:level 2 & level 3.
	**/
	$('#menu-admin-header > ul > li > ul > li:last-child > a, #menu-admin-header > ul > li > ul > li > ul > li:last-child > a').css({
		borderBottom: '0px solid #666'
	});
	
	/**
	reset the style of the last item with the class of admin-menu-singleton, which is the log out button.
	**/
	$('.admin-menu-singleton:last').css({
		padding: '2px 8px 1px 8px'
	});
	
	/**
	reset style of the menu-admin when you hover on the sub menus.
	**/	
	$("#menu-admin-header > ul > li > ul").hover(function () {
		$(this).parent().addClass("hover-grandparent");
	  },
	function(){
		$(this).parent().removeClass("hover-grandparent");
	});
	
	$("#menu-admin-header ul ul ul").hover(function () {
		$(this).parent().addClass("hover-parent");
		$(this).children().addClass("hover-children");
	  },
	function(){
		$(this).parent().removeClass("hover-parent");
		$(this).children().removeClass("hover-children");
	});
}

/*****************/

this.resetMenuAdmin_bk = function(){
	/**
	do not return the drop-down:level 1 when you click on it, accept the last item.
	**/
	$('#menu-admin-header > ul > li:not(:last) > a').click(function(){
		return false;
	});
	
	/*
	$('#menu-admin-header > ul > li > a').click(function(){
		return false;
	});
	
	$('#menu-admin-header > ul > li > a:last').bind('click', function() {
	  var path = $(this).attr('href');
	  document.location = path;
	  return true;
	});
	
	$('#menu-admin-header > ul > li > a').eq(2).click(function(){
		return false;
	});
	$('#menu-admin-header > ul > li > a').eq(3).click(function(){
		return false;
	});
	$('#menu-admin-header > ul > li > a').eq(4).click(function(){
		return false;
	});
	$('#menu-admin-header > ul > li > a').eq(5).click(function(){
		return false;
	});
	$('#menu-admin-header > ul > li > a').eq(6).click(function(){
		return false;
	});
	*/
	
	/**
	code below is to control the menu-admin when you hover on the sub menus.
	**/
	$("#menu-admin-header > ul > li > ul").hover(function () {
		$(this).parent().addClass("hover-grandparent");
	  },
	function(){
		$(this).parent().removeClass("hover-grandparent");
	});
	
	$("#menu-admin-header ul ul ul").hover(function () {
		$(this).parent().addClass("hover-parent");
		$(this).children().addClass("hover-children");
	  },
	function(){
		$(this).parent().removeClass("hover-parent");
		$(this).children().removeClass("hover-children");
	});
		
	/**
	loop through each <a>, if it has a sibling, then append the class of 'indicator'.
	**/
	$("#menu-admin-header a").each(function () {
		if ( $(this).siblings().size() > 0 ) 
		{
			$(this).append("<span class='menu-admin-sub-indicator'></span>");
			
			/*
			$(this).click(function (){
				//var $this = $(this).siblings(".selected").toggleClass("showme");
				var $this = $(this).siblings().toggleClass("showme");
				$("ul").not($this).removeClass("showme");
				return false;
			});
			
			$(this).toggle(
				function (){
					//$("#menu-admin-header ul ul").not(this).css({display: "none"});
					//$("#menu-admin-header li").removeClass("hover-grandparent");
					$(this).next().css({display: "block"});
					$(this).parent().addClass("hover-grandparent");
				},
				function (){
					$(this).next().css({display: "none"});
					$(this).parent().removeClass("hover-grandparent");
			});
			*/

			/*
			$(this).hover(function () {
				$(this).next().css({display: "block"});
				$(this).parent().addClass("hover-grandparent");
			  },
			function(){
				$(this).next().css({display: "none"});
				$(this).parent().removeClass("hover-grandparent");
			});
			*/
		}
	});
	
	/**
	control the style of all drop-down:level 2.
	**/
	$('#menu-admin-header > ul > li > ul > li:last-child > a').css({
		padding: '3px 8px 2px 8px',
		borderBottom: '1px solid #666'
	});
	
	/**
	control the style of the drop-down:level 1 when you hover it.
	**/
	$("#menu-admin-header > ul > li > a").hover(function () {
		if ( $(this).siblings().size() > 0 ) 
		{
			$(this).css({
				borderBottom: '1px solid #888'
			});
		}
	},
	function(){
		$(this).css({
			borderBottom: '1px solid #888'
		});
	});
}

/*****************/

this.popup_window = function(target, name, sizes){
//function popup_window(target, name, sizes) {
	newwindow = window.open(target, name, sizes);
	if (window.focus) {newwindow.focus()}
	return false;
}

this.guide = function(){	
$(".guide").click(function(){
	var path = $(this).attr("href");
	popup_window(path,'guide','width=400,height=600, scrollbars=yes'); 
	return false;
	});
}

this.closePopup = function(target){	
$(".close").click(function(){
	target.fadeOut('fast', function(){
		target.remove();
		});
	return false;
	});
}

this.locationBack = function(target){	
$(".back").click(function(){
	var path = $(this).attr("href");
	$(".popup").remove();
	document.location = path;
	return false;
	});
}

/*****************/

this.loadLogin = function(path){	

	$(".popup").remove();
	$(document.body).append("<div id=\"popup_login\" class=\"popup\"></div>");
	if(path) path = path;
	else path = http_root+rp_cms+'form_login.php?pg_url=cms';
	//alert(path);
	var target = $('#popup_login');
	var scrollTop = $(window).scrollTop();
	var scrollLeft = $(window).scrollLeft();
	var width = 380;
	var top = 200;
	var marginLeft = "-"+((scrollLeft + width)/2);
	target
		.css({
			top:(scrollTop + top) + "px", 
			left:"50%",
			marginLeft:marginLeft + "px",
			width: width + "px",
			zIndex:"10"
			});
	
	target.fadeIn('fast', function(){		
		target.html('<div class="ajaxloader"><img src="'+http_root+rp_image_global+img_loader+'"/> loading</div>');
		$('.ajaxloader')
			.css({
				padding:"20px", 
				textAlign:"center",
				backgroundColor:"#ffffff",
				color:"#000000"
				});
		target.load(path, {}, function(){
			target.hide();
			target.fadeIn('slow');
			closePopup(target);
			postLogin();
			});
		})			

}


this.postLogin = function(){
$("#form_data_login").submit(function(){	
	
	// get the values and store them.
	var path = $(this).attr('action');
	var pg_url = $('#pg_url').val();
	var ask_id = $('#ask_id').val();
	
	// if the ask id has a value.
	if(ask_id) ask_id = '/'+ask_id;
	else ask_id = '';
	
	// serialise the form values.
	var data_str = $(this).serialize();
	//alert(data_str);
	
	// processing.
	$("#msgbox").removeClass().addClass('messagebox').text('Validating...').fadeIn(1000);
	
	// post the form.
	$.post(path,$(this).serialize(),function(data){
		//alert(data);	
		
		// if the return data has 'granted'.
		if(data =='granted'){ //if correct login detail
			$("#msgbox").fadeTo(200,0.1,function(){ 
				
				// processing.
				$(this).html('Logging in...').addClass('messageboxok').fadeTo(900,1,function(){  
				
				//redirect to secure page
				document.location = http_root+pg_url+ask_id; 
				//document.location = 'index.php';
				});			  
			});
		}

		// if the return data has 'not granted'.
		else if (data =='not granted') {
			$("#msgbox").fadeTo(200,0.1,function(){ 
				$(this).html('You don\'t have the permission to edit this page.').addClass('messageboxerror').fadeTo(900,1); 
				});		
			}
			
		// if the return data has 'intruder'.
		else if (data =='intruder') {
			$("#msgbox").fadeTo(200,0.1,function(){ 
				$(this).html('Invalid login!').addClass('messageboxerror').fadeTo(900,1); 
				});		
			}
			
		// otherwise...
		else {
			$("#msgbox").fadeTo(200,0.1,function(){ 
				$(this).html('Your login details are incorrect!').addClass('messageboxerror').fadeTo(900,1);
				});	
			}
			
		});
	
	// do not post the form physically.
	return false; 
	});
}

/*****************/

function addTag() {
    $('#all-my-tags .items-tag a').click(function(){
        
		var target = $("#pg_tag");
		var current = target.val();
		current = $.trim(current);
		if (current =="TAGS") current = "";
		target.replaceWith("<input name=\"pg_tag\" type=\"text\" id=\"pg_tag\" value=\""+current+"\" />");
		var target = $("#pg_tag"); // must declare the target again after replaceWith()
		
		var tag = $(this).attr('href');
		var arrA = target.val().split(' ');

		if((idx = arrA.indexOf(tag)) >= 0) {
			arrA.splice(idx,1);
		} else {
			arrA.push(tag);
			}
	  
		target.val( arrA.join(' ').replace(/\s{2,}/,' ').replace(/^\s*/, ''));

		target.blur(function(){
			var currentValue = $("#pg_tag").val();
			if ( currentValue == '') {
				//alert(test);
				$("#pg_tag").replaceWith("<input name=\"pg_tag\" type=\"text\" id=\"pg_tag\" value=\"\" title=\"TAGS\"/>");
				$('form *[title]').inputHint();
				$('#all-my-tags .items-form a').removeClass('clicked');
				}
			});
			
        $(this).toggleClass('clicked');
        return false;
    });
}

function addTag_bk() {
    $('#all-my-tags .items-form a').click(function(){
        var currentValue = $("#pg_tag").val();
		if (currentValue =="TAGS") currentValue = "";
		$("#pg_tag").replaceWith("<input name=\"pg_tag\" type=\"text\" id=\"pg_tag\" value=\""+currentValue+"\" />");
        var newValue = null;
        $(this).toggleClass('clicked');
        var tag = $(this).attr('href');
        newValue = $(this).hasClass('clicked') ? currentValue + ' ' + tag : removeTag(currentValue, tag);
        $("#pg_tag").val(newValue).focus();
		
		$("#pg_tag").blur(function(){
			var currentValue = $("#pg_tag").val();
			if ( currentValue == '') {
				//alert(test);
				$("#pg_tag").replaceWith("<input name=\"pg_tag\" type=\"text\" id=\"pg_tag\" value=\"\" title=\"TAGS\"/>");
				$('form *[title]').inputHint();
				$('#all-my-tags .items-form a').removeClass('clicked');
				}
			});
        
        return false;
    });
}
 
function removeTag(str, tag) {
    tag = String(tag);
    str = String(str);
    var idx = str.indexOf(tag);
    if (idx === false) {
        return false;
    }
    var beforeTag = str.substring(0, idx);
    var afterTag = str.substring(idx + tag.length);
    return (beforeTag + afterTag).replace(/\s{2,}/,' ').replace(/^\s*/, '');
}

/*****************/

function addPriviledge() {
    $('#all-my-users .items-tag a').click(function(){
        
		var target = $("#pg_user");
		var current = target.val();
		
		current = $.trim(current);
		if (current =="USERS") current = "";
		target.replaceWith("<input name=\"pg_user\" type=\"hidden\" id=\"pg_user\" value=\""+current+"\" />");
		
		var target = $("#pg_user"); // must declare the target again after replaceWith()
		
		var tag = $(this).attr('href');
		var arrA = target.val().split(' ');

		if((idx = arrA.indexOf(tag)) >= 0) {
			arrA.splice(idx,1);
		} else {
			arrA.push(tag);
			}
	  
		target.val( arrA.join(' ').replace(/\s{2,}/,' ').replace(/^\s*/, ''));
			
        $(this).toggleClass('clicked');
        return false;
    });
}

/*****************/

this.ajaxUpload = function(index){
	//alert(index);
	index = String(index);
	if(index) {
		var index = ':eq('+index+')';
	}else{
		var index = '';
	}
	
	var total_items = ($('.items-uploaded'+index+' > li').length);
	var btn_upload = $('.btn-upload'+index+'');
	var path = btn_upload.attr("rel");
	var cat =  btn_upload.attr("name");
	var status = $('.status-upload'+index+'');
	
	if(total_items >= 1){
	$('.upload'+index+' > .set-form  > .item-form:first-child').css({
		borderBottom: '1px solid #999', 
		padding: '0px 0px 15px 0px'
		});
	}
	
	//alert(cat);
	//alert(path);
	//alert(total_items);
	
		new AjaxUpload(btn_upload, {
			action: path,
			name: cat,
			onSubmit: function(file, ext){
				if(cat == 'image')
				{
					if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){
						// extension is not allowed 
						status.text('Only JPG, PNG or GIF files are allowed');
						return false;
					}
				}
				else if(cat == 'document')
				{
					if (! (ext && /^(doc|pdf|zip)$/.test(ext))){
						// extension is not allowed 
						status.text('Only DOC, PDF or ZIP files are allowed');
						return false;
					}
				}
				else if(cat == 'video')
				{
					if (! (ext && /^(avi|mov|swf)$/.test(ext))){
						// extension is not allowed 
						status.text('Only AVI, MOV or SWF files are allowed');
						return false;
					}
				}
				status.html('<img src="'+http_root+rp_image_global+img_loader+'"/>');
			},
			onComplete: function(file, response){
				//On completion clear the status
				status.text('');
				//Add uploaded file to list
				if(response){
				
					$("error", response).each(function(){
						var message = $(this).attr('message');
						alert(message);
					});
					
					$("result", response).each(function(){
						var itemid = $(this).attr('itemid');
						var itemcat = $(this).attr('itemcat');
						var itemtitle = $(this).attr('itemtitle');
						var itempath = $(this).attr('itempath');
						var message = $(this).attr('message');
						$('.upload'+index+' > .set-form  > .item-form:first-child').css({
							borderBottom: '1px solid #999', 
							padding: '0px 0px 15px 0px'
						});
						//alert(itemcat);
						if(cat == 'image')
						{
							alert(message+' The id of this image is '+itemid+'.');
						$('<li id="item_'+itemid+'" class="item"></li>').appendTo('.items-uploaded-image'+index+'').html('<div><img src="'+itempath+'"/></div><div><span><a href="'+http_root+rp_cms+'form_image_edit.php?img_id='+itemid+'" class="edit">EDIT</a><div class="divider"></div><a href="'+http_root+rp_cms+'form_image_delete.php?img_id='+itemid+'" class="delete">DELETE</a></span><h4>'+itemtitle+'</h4><p></p></div>').addClass('success');
						}
						else if(cat == 'document')
						{
							alert(message+' The id of this document is '+itemid+'.');
							$('<li id="item_'+itemid+'" class="item"></li>').appendTo('.items-uploaded'+index+'').html('<div><img src="'+itempath+'"/></div><div><span><a href="'+http_root+rp_cms+'form_document_edit.php?doc_id='+itemid+'" class="edit">EDIT</a><div class="divider"></div><a href="'+http_root+rp_cms+'form_document_delete.php?doc_id='+itemid+'" class="delete">DELETE</a></span><h4>'+itemtitle+'</h4><p></p></div>').addClass('success');
						}
						else if(cat == 'video')
						{
							alert(message+' The id of this video is '+itemid+'.');
							$('<li id="item_'+itemid+'" class="item"></li>').appendTo('.items-uploaded'+index+'').html('<div><img src="'+itempath+'"/></div><div><span><a href="'+http_root+rp_cms+'form_video_edit.php?vid_id='+itemid+'" class="edit">EDIT</a><div class="divider"></div><a href="'+http_root+rp_cms+'form_video_delete.php?vid_id='+itemid+'" class="delete">DELETE</a></span><h4>'+itemtitle+'</h4><p></p></div>').addClass('success');
						}
						updateUpload();
						loadDelete();
						
					});

				}
			}
	});
}

/*****************/

this.updateUpload = function(){	
$(".items-uploaded .edit").click(function(){
	var path_edit = $(this).attr("href");
	var path_delete = $(this).next().next().attr("href");
	var target_loadIn = $(this).parent().parent();
	var target_html = $(this).parent().parent().html();
	var query_id = path_edit.split('?');
	var value_id = query_id[1].split('&');
	var item_id = value_id[0].split('=')[1]*1;
	
	//alert(path_delete);
	target_loadIn.html('<img src="'+http_root+rp_image_global+img_loader+'"/>');
	target_loadIn.load( path_edit, {}, function(){
		$('form *[title]').inputHint();
		$("#form-uploaded-update-"+item_id).submit(function(){
			var path_post = $(this).attr('action');
			var data_str = $(this).serialize();
			var query_size = path_post.split('?');
			var value_size = query_size[1].split('&');
			var w = value_size[0].split('=')[1]*1;
			var h = value_size[1].split('=')[1]*1;
				$.post(path_post, data_str, function(xml){
					$("label").removeClass('error');
					processUpdate_upload(xml,w,h,path_edit,path_delete);
					return false;
				});
			
			return false;
		});	
		$("input[name=cancel]").click(function(){
			target_loadIn.html(target_html);
			updateUpload();
			loadDelete();
			return false;
			});
		});	
	return false;
	});
}

this.processUpdate_upload = function(xml,w,h,path_edit,path_delete){
	$('#popup_result').remove();
	$(document.body).append("<div id=\"popup_result\" class=\"popup\"></div>");
	var popup = $('#popup_result');
	var scrollTop = $(window).scrollTop();
	var scrollLeft = $(window).scrollLeft();
	var width = w;
	var top = h;
	//alert(http_root);
	var marginLeft = "-"+ ((scrollLeft + width)/2);
	popup.css({
			top:(scrollTop + top) + "px", 
			left:"50%",
			marginLeft:marginLeft + "px",
			width:width + "px",
			zIndex:"100",
			display: "none"
			});
		
	popup.load( http_root+rp_cms+"result.php", {}, function(){
		$("error", xml).each(function(){
			var elementid = $(this).attr('elementid');
			var item_id = $(this).attr('itemid');
			var message = $(this).attr('message');
			$("#item_"+item_id+" #"+elementid+"_label").addClass('error');
			$(".result").append("<img src='"+http_root+rp_image_global+"attention.png' /> <b>" + message + "</b> <br />");
			$('form *[title]').inputHint();
			popup.fadeIn('slow', function(){
				closePopup(popup);
			});	
		});
		
		$("result", xml).each(function(){
		var message = $(this).attr('message');
		var item_id = $(this).attr('itemid');
		var item_title = $(this).attr('itemtitle');
		var item_description = $(this).attr('itemdescription');
		var item_href = $(this).attr('itemhref');
		var item_category = $(this).attr('itemcategory');
		//alert(item_category);
		var target = $(".upload-"+item_category+" .items-uploaded #item_"+item_id+" div:last-child");
		target.html('<img src="'+http_root+rp_image_global+img_loader+'"/>');
		$(".result").append("<img src='"+http_root+rp_image_global+"info.png' /> <b>" + message + "</b> <br />");
			
			popup.fadeIn('fast', function(){
				target.html('<span><a href="'+path_edit+'" class="edit" rel="'+item_id+'">EDIT</a><div class="divider"></div><a href="'+path_delete+'" class="delete">DELETE</a></span><h4>'+item_title+'</h4><p>'+item_description+'</p><p>'+item_href+'</p>');
				updateUpload();
				loadDelete();
				closePopup(popup);
				popup.fadeOut(function(){
					popup.remove();
				});	
			});
		});
	});
}

/*****************/

this.sortOrders = function(path){ //function sortOrders(){
	$(".items-uploaded-image,.items-uploaded-document,.items-uploaded-video,.sort-menu").sortable({
		opacity: 0.8, 
		cursor: 'move', 
		update: function(){
			//$("#items > .item").removeClass("last");
			//$("#items > .item:last").addClass("last");
			var path = $(this).attr('rel');
			var order = $(this).sortable("serialize"); 
			//alert(path);
			$.post(http_root+path, order, function(theResponse){
				//alert(order);
				$('#popup_result').remove();
				$(document.body).append("<div id=\"popup_result\" class=\"popup\"></div>");
				var popup = $('#popup_result');
				var scrollTop = $(window).scrollTop();
				var scrollLeft = $(window).scrollLeft();
				var width = 400;
				var top = 250;
				var marginLeft = "-"+ ((scrollLeft + width)/2);
				popup.css({
						top:(scrollTop + top) + "px", 
						left:"50%",
						marginLeft:marginLeft + "px",
						width:width + "px",
						zIndex:"100",
						display: "none"
						});
						
				popup.load( http_root+rp_cms+"result.php", {}, function(){
					$(".result").html(theResponse);
					popup.fadeIn('slow', function(){	
						setTimeout(function(){
							$("#popup_result").fadeOut("slow");
						},2000);
						closePopup(popup);
					});	
				})

				//$(".status-sort").html(theResponse);
				//$(".status-sort").slideDown('slow');
				}); 															 
			}								  
		});
	}

/*****************/

this.loadIn = function(){	
$(".load-in").click(function(){
	$(".popup").remove();
	var path = $(this).attr("href");
	var pg_cat_id = $(this).attr("id");
	
	var class_array = $(this).attr('class').split(' '); 
	var class_last = $(this).attr("class").split(' ').slice(-1); 
	var editor = $(this).attr("class").split(' ').slice(1,2);
	var target = String($(this).attr("class").split(' ').slice(2,3));
	
	//alert(target);
	if(target) { 
		target = $(target); 
		var target_html = target.html();
		}
	else { 
		target = $('#body-cms'); 
		}
	
	//alert(path);
	//alert(editor);
			
	target.html('<div class="ajaxloader"><img src="'+http_root+rp_image_global+img_loader+'"/> loading</div>');
	target.load( path + '&editor=' + editor , {}, function(){
		
		disable();
		restore();
		restoreAll();
		
		target.css({display: 'none'});
		target.fadeIn('slow', function(){
		
			$(".form h2").click(function(){
				$(this).next().next().slideToggle("slow");
				$(this).toggleClass("active");
				return false;
			});
			
			$(".upload h2").click(function(){
				$(this).next().next().next().slideToggle("slow");
				$(this).toggleClass("active");
				return false;
			});
			
			$(".form h4").click(function(){
				return false;
			});
			
			$(".form h5").click(function(){
				$(this).next().slideToggle("slow");
				$(this).toggleClass("active");
				return false;
			});
			
			$('form *[title]').inputHint();
			
			if(editor == 'mce-simple'){
				
				loadtinyMCE_simple();
				
				if($('.upload').length > 0) {
					
					/*
					if($('.upload-image').length>1){
					ajaxUpload('0');
					ajaxUpload('1');
					ajaxUpload('2');
					
					} else if($('.upload-image').length == 1) {
					ajaxUpload('0');
					ajaxUpload('1');
					}
					*/
					
					for( var i = 1; i <= $('.upload').length; i++){
						ajaxUpload(i-1);
						//alert(i-1);
					}
						
				//ajaxUpload_document();
				sortOrders();
				updateUpload();
				}
				loadDelete();
				postForm(editor);
				addTag();
				addPriviledge();
				
				loadOut();
			}else if(editor == 'basic'){
			
				if($('.upload').length > 0) {
					for( var i = 1; i <= $('.upload').length; i++){
						ajaxUpload(i-1);
						//alert(i-1);
					}
				
				//ajaxUpload_document();
				sortOrders();
				updateUpload();
				}
				loadDelete();
				postForm(editor);
				addTag();
				addPriviledge();
				
				loadOut();
			}else if(editor == 'slides'){
				//alert('1');
				if($('.upload').length > 0) {
					for( var i = 1; i <= $('.upload').length; i++){
						ajaxUpload(i-1);
					}
				loadDelete();
				sortOrders();
				updateUpload();
				}
			}else {
				loadOut();
				loadDelete();
				postForm();
				postForm_loadIn();
				sortOrders();
			}
			
			target.focus(function(){
				//alert('1');
				//this is to trigger the submit form automatically, without hitting the Update button.
				//$("#form_data").trigger("submit");
				//postForm(editor);
				target.html(target_html);
				loadIn();
				target.unbind('focus');
				target.unbind('click');
				});
					
			$('#header').click(function(){
				//user clicked anywhere on the designated element
				target.focus();
				});
				
			target.click(function(event) {
				//use the stopPropogation function to prevent the document (parent) click event from firing
				event.stopPropagation();
				//Returns whether event.stopPropagation() was ever called on this event object. 
				//alert( event.isPropagationStopped() );
				//or, user clicked on the target, make sure to return false, 
				//otherwise the document click event will be called as well.
				//return false;  
				});

			})
			
		});	
		
	return false;
	});
}

/*****************/

this.loadOut = function(relation){	
$(".edit").click(function(){	
	$(".popup").remove();
	$(document.body).prepend("<div id=\"popup_edit\" class=\"popup\"></div>");
	var target = $('#popup_edit');
	var path = $(this).attr("href");
	var editor = $(this).attr("class").split(' ').slice(1,2);
	var scrollTop = $(window).scrollTop();
	var scrollLeft = $(window).scrollLeft();
	var width = 1050;
	var top = 70;
	var marginLeft = "-"+((scrollLeft + width + 20)/2);
	
	//alert(editor);
	
	target.css({
			top:(scrollTop + top) + "px", 
			left:"50%",
			marginLeft:marginLeft + "px",
			width: width + "px",
			color:"#333333", 
			zIndex:"10"
			});
			
	target.fadeIn('fast', function(){		
		target.html('<div class="ajaxloader"><img src="'+http_root+rp_image_global+img_loader+'"/> loading</div>');
		$('.ajaxloader').css({
				padding:"20px", 
				textAlign:"center",
				backgroundColor:"#ffffff"
				});
		
		target.load( path, {}, function(){						
			$('#form-edit').prepend("<div class=\"close\"><a href=\"#\" class=\"close\"> X Close </a></div>");			
			$('#form-edit').css({
				padding:"20px", 
				backgroundColor:"#ffffff"
				});

			$('form *[title]').inputHint();
			$(".upload h2").click(function(){
				$(this).next().next().next().slideToggle("slow");
				$(this).toggleClass("active");
				return false;
			});
			
			$(".form h4").click(function(){
				return false;
			});
			
			$(".form h5").click(function(){
				$(this).next().slideToggle("slow");
				$(this).toggleClass("active");
				return false;
			});
			
			
			$("#pg_tag").blur(function(){
			var currentValue = $("#pg_tag").val();
			if (currentValue =="TAGS") currentValue = "";
			if ( currentValue == '') {
				//alert(test);
				$("#pg_tag").replaceWith("<input name=\"pg_tag\" type=\"text\" id=\"pg_tag\" value=\"\" title=\"TAGS\"/>");
				$('form *[title]').inputHint();
				$('#all-my-tags .items-form a').removeClass('clicked');
				}
			});
			
			if(editor == 'mce-simple') { 
				loadtinyMCE_simple(); 
				
				if($('.upload').length>0) {
					for( var i = 1; i <= $('.upload').length; i++){
						ajaxUpload(i-1);
						//alert(i-1);
					}
				
				//ajaxUpload_document();
				sortOrders();
				updateUpload();
				}
				postForm(editor);
				addTag();
				addPriviledge();
			}else if(editor == 'basic'){
				
				if($('.upload').length>0) {
					for( var i = 1; i <= $('.upload').length; i++){
						ajaxUpload(i-1);
						//alert(i-1);
					}
				
				//ajaxUpload_document();
				sortOrders();
				updateUpload();
				}
				postForm();
				addTag();
				addPriviledge();
			}else{
				postForm();
				}
			loadDelete();
			closePopup(target);
			});	
		})
	return false;
	});
}

/*****************/

this.postForm = function(editor){
$("#form_data").submit(function(){
	$("#popup_result").remove();
	$(document.body).append("<div id=\"popup_process\" class=\"popup\"></div>");
	var path = $(this).attr('action');
	var popupparent = $('#popup_process');
	var scrollTop = $(window).scrollTop();
	var scrollLeft = $(window).scrollLeft();
	var query= path.split('?');
    var value= query[1].split('&');
    var w= value[0].split('=')[1]*1;
    var h= value[1].split('=')[1]*1;	
	var width = w;
	var top = h;
	
	var str = $(this).serialize();
	//alert(str);
	//alert(editor);
	
	var marginLeft = "-"+ ((scrollLeft + width)/2);
	
	popupparent
		.css({
			top:(scrollTop + top) + "px", 
			left:"50%",
			marginLeft:marginLeft + "px",
			width:width + "px",
			zIndex:"11"
			//display:"none"
			});
	popupparent.append("<div id=\"process\" class=\"popup_content\"></div>");	
	var popupchild = $('#process');

	if(editor == 'mce-simple'){ tinyMCE.triggerSave(true,true); }
	popupchild.html('<div class="ajaxloader"><img src="'+http_root+rp_image_global+img_loader+'"/> loading</div>');
	$('.ajaxloader').css({
				padding:"10px", 
				textAlign:"center",
				backgroundColor:"#ffffff"
				});
	$.post(path,
		$(this).serialize()
		,function(xml){
			$("label").removeClass('error');
			popupparent.remove();
			processForm(xml,w,h);
		});
	return false;
	});
}

this.processForm = function(xml,w,h){ //  ==  function addMessages(xml) {
$(document.body).append("<div id=\"popup_result\" class=\"popup\"></div>");
var popup = $('#popup_result');
var scrollTop = $(window).scrollTop();
var scrollLeft = $(window).scrollLeft();
var width = w;
var top = h;
var marginLeft = "-"+ ((scrollLeft + width)/2);
popup
	.css({
		top:(scrollTop + top) + "px", 
		left:"50%",
		marginLeft:marginLeft + "px",
		width:width + "px",
		zIndex:"11",
		display:"none"
		});
popup.load(http_root+rp_cms+"result.php", {}, function(){
	$("error", xml).each(function(){
		$('form *[title]').inputHint();
		var elementid = $(this).attr('elementid');
		var message = $(this).attr('message');
		$("#"+elementid+"_label").addClass('error');
		$(".result").append("<img src='"+http_root+rp_image_global+"attention.png' /> <b>" + message + "</b> <br />");
		popup.fadeIn('slow', function(){	
			closePopup(popup);
		});
	});
	
	$("result", xml).each(function(){
	var message = $(this).attr('message');
	var path = $(this).attr('path');
	var action = $(this).attr('action');
	var itemid = $(this).attr('itemid');
	var itemtitle = $(this).attr('itemtitle');
	var itemhide = $(this).attr('itemhide');
	var itemcategory = $(this).attr('itemcategory');
	var itemcleanurl = $(this).attr('itemcleanurl');
	var basename = $(this).attr('basename');
	
	//alert(path);
	//alert(itemcategory);
	//alert(itemtitle);
	//alert(itemcleanurl);
	//alert(itemhide);
	//alert(itemid);
	
	$(".result").append("<img src='"+http_root+rp_image_global+"info.png' /> <b>" + message + "</b> <br />");
	
	popup.fadeIn('fast', function(){
	
		if((action=='add')||(action=='send')){
			setTimeout(function(){
				popup.fadeOut("slow", function(){
				popup.remove();
				});	
			},2000);
			$("#body-cms").load(http_root+path, {}, function(){
				loadOut();
				loadDelete();
				postForm_loadIn();
				sortOrders();
				
				$(".form h2").click(function(){
					$(this).next().next().slideToggle("slow");
					$(this).toggleClass("active");
					return false;
				});
			});	
		}else if($("#body-cms").length == 0){
			setTimeout(function(){
				popup.fadeOut("slow", function(){
					$('#popup_edit').fadeOut("slow");
				});	
			},2000);
			
			/*
			$('<div>').load(http_root+'inc-core/core.php'+'?pg_url='+itemcleanurl, function() {
				$(this).appendTo('#main');
				$('<div>').load(http_root+rp_template+'page.portfolio.item.php'+'?pg_url='+itemcleanurl, function() {
					$(this).appendTo('#main');
				});
			});
			*/		
			var target = $(".form").parent();
			target.load(http_root+rp_template+basename+'?pg_url='+itemcleanurl+'&edit_as_you_go=true', {}, function(event){
				loadIn();
				target.unbind('blur');
				target.unbind('click');
			});
				
		}else{
			setTimeout(function(){
				popup.fadeOut("slow", function(){
					$('#popup_edit').fadeOut("slow");
					$(".items-form #item_"+itemid+" h1:first").text(itemtitle);
					
					if(itemcategory){
						$(".items-form #item_"+itemid+" span:first").text(itemcategory);
					}
					if(itemhide){
						if (itemhide == '1') 
						{
							//var target = $(".items-form #item_"+itemid+" > div:last").css({background: 'red'});
							var target = $(".items-form #item_"+itemid+" > div:last");
							$('.disable', target).text('ENABLE');
						}
						
						else if (itemhide == '0') 
						{
							var target = $(".items-form #item_"+itemid+" > div:last");
							$('.disable', target).text('DISABLE');
							
						}
						
						else if (itemhide == 'on') 
						{
							itemhide = 'Private';
							$(".items-form #item_"+itemid+" span:first").text(itemhide);
						} 
						else 
						{
							itemhide = 'Published';
							$(".items-form #item_"+itemid+" span:first").text(itemhide);
						}
						
					}					
				});	
			},2000);
		}
			
		$('form *[title]').inputHint();
		closePopup(popup);
		
		});
    });
	
});
	
}

this.postForm_loadIn = function(){
$("#form-contact").submit(function(){
		var path = $(this).attr('action');
		var cat_id = $('#cat_id_browse').val();
		var target = $(".items-form");
		var str = $(this).serialize();
		//alert(str);
		target.html('<img src="'+http_root+rp_image_global+img_loader+'"/> loading');
		target.load( path+'?cat_id_browse='+cat_id, {}, function(){
			loadOut();
			loadDelete();
			});
		return false;
	});
}

/*****************/

this.loadDelete = function(){	
$(".delete").click(function(){
	
	// remove the popup.
	$('#popup_result').remove();
	
	// get the second value of the class in delete class and store it in a variable called catagory.
	var catagory = $(this).attr("class").split(' ').slice(1,2);
	//alert(catagory);
	
	// set the conditions.
	if($(catagory == 'menu').length > 0) var target_delete = $(this).parent().parent().parent().parent();
	else if (catagory == 'ask') var target_delete = $(this).parent().parent().parent().parent().parent();
	else if (catagory == 'answer') var target_delete = $(this).parent().parent().parent().parent();
	else var target_delete = $(this).parent().parent().parent();
	
	var target_loadIn = $(this).parent();
	var target_html = $(this).parent().html();
	var path_load = $(this).attr('href');
	
	var query_id = path_load.split('?');
	var value_id = query_id[1].split('&');
	var item_id = value_id[0].split('=')[1]*1;

	if(value_id.length > 1)
	var parent_id = value_id[1].split('=')[1]*1;
	//alert(parent_id);
	
	// make a gif loader.
	target_loadIn.html('<img src="'+http_root+rp_image_global+img_loader+'"/> loading');
	
	// load the delete form.
	target_loadIn.load( path_load, function(){
		
		// submit the form.
		$("#form-delete-"+item_id).submit(function(){
			
			// remove popup.
			$('#popup_result').remove();
			
			// get the path from attribute of action in the form.
			var path_post = $(this).attr('action');
			
			// make a gif loader.
			target_loadIn.html('<div class="ajaxloader"><img src="'+http_root+rp_image_global+img_loader+'"/> loading</div>');
			
			// post the form.
			$.post(path_post, $(this).serialize(), function(xml){
				
				// load the callback fucntion.
				processDelete(xml);
				
				// slide up the deleted target.
				target_delete.slideUp('fast', function() {
				
				// remove its divs completely.
				target_delete.remove();
				
				// condition for uploads.
				var total_items_c1 = ($('.items-uploaded:eq(0) > li').length);
				var total_items_c2 = ($('.items-uploaded:eq(1) > li').length);
				var total_items_c3 = ($('.items-uploaded:eq(2) > li').length);
				var total_items_c4 = ($('.items-uploaded:eq(3) > li').length);
				var total_items_c5 = ($('.items-uploaded:eq(4) > li').length);
				if(total_items_c1 == 0){
					$('.upload:eq(0)  > .set-form  > .item-form:first-child').css({
						borderBottom: '0px solid #999', 
						padding: '0px 0px 0px 0px'
						});
					}
				if(total_items_c2 == 0){
					$('.upload:eq(1) > .set-form  > .item-form:first-child').css({
						borderBottom: '0px solid #999', 
						padding: '0px 0px 0px 0px'
						});
					}
				if(total_items_c3 == 0){
					$('.upload:eq(2)  > .set-form  > .item-form:first-child').css({
						borderBottom: '0px solid #999', 
						padding: '0px 0px 0px 0px'
						});
					}
				if(total_items_c4 == 0){
					$('.upload:eq(3)  > .set-form  > .item-form:first-child').css({
						borderBottom: '0px solid #999', 
						padding: '0px 0px 0px 0px'
						});
					}
				if(total_items_c5 == 0){
					$('.upload:eq(4)  > .set-form  > .item-form:first-child').css({
						borderBottom: '0px solid #999', 
						padding: '0px 0px 0px 0px'
						});
					}
					
				// condition for: manage mains, manage subs, manage posts, manage newsletters, manage contacts, manage categories, etc. 
				var total_item_form = $('.items-form .item-form').length;
				if(total_item_form == 0) $('.items-form').html('<br/>&nbsp;&nbsp; '+total_item_form+' item left.');
				
				// condition for: blog comments only.
				var total_comment = $('.item-comment').length;
				if(value_id.length > 1) $('#item-blog-'+parent_id+' .comments').html(total_comment+' COMMENTS &raquo;');
				
				$(".foot-comment").each(function () {
				$(this).each(function () {
					var total_reply = $(".item-reply",this).length;
					//alert(total_reply);
					
					if(total_reply == 0) {
						$(this).remove();
						}
						});
				
					});	
					
				});
			});
			return false;
		});
		
		// when the no/cancel button is triggered.
		$("input[name=no]").click(function(){
			target_loadIn.html(target_html);
			updateUpload();
			loadDelete();
			loadOut();
			loadReply();
			return false;
		});
	
	});
	
	return false;
	});
}

// callback function for deleting items.
this.processDelete = function(xml){

	// append a popup div.
	$(document.body).append("<div id=\"popup_result\" class=\"popup\"></div>");
	var popup = $('#popup_result');
	var scrollTop = $(window).scrollTop();
	var scrollLeft = $(window).scrollLeft();
	var width = 400;
	var top = 220;
	var marginLeft = "-"+ ((scrollLeft + width)/2);
	popup.css({
			top:(scrollTop + top) + "px", 
			left:"50%",
			marginLeft:marginLeft + "px",
			width:width + "px",
			zIndex:"11",
			display:"none"
			});
		
	// proccess the result and load the result page and display the result messages on the result page.
	popup.load(http_root+rp_cms+"result.php", {}, function(){
		
		// loop for any error messages.
		$("error", xml).each(function(){
			var elementid = $(this).attr('elementid');
			var message = $(this).attr('message');
			$("#"+elementid+"_label").addClass('error');
			$("#"+elementid+"_img").css({visibility:'visible'});
			$(".result").append("<img src='"+http_root+rp_image_global+"attention.png' /> <b>" + message + "</b> <br />");
			popup.fadeIn('slow', function(){	
				closePopup(popup);
			});	
		});
		
		// loop for any positive results.
		$("result", xml).each(function(){
		var message = $(this).attr('message');
		//alert(message);
		
		// append the positive messages in the result class.
		$(".result").append("<img src='"+http_root+rp_image_global+"info.png' /> <b>" + message + "</b> <br />");
		
		// display the messages by fading them in.
		popup.fadeIn('fast', function(){
			setTimeout(function(){
				popup.fadeOut("slow",function(){
					popup.remove();
				});	
			},1000);	
			
			// attach closePopup function.
			closePopup(popup);		
			});
		});
	});
}

/*****************/

this.disable = function(){
	$(".disable").click(function(){
		var path = $(this).attr('href');
		var original = $(this).text();
		//alert(original);
		
		if(original == 'DISABLE')
		{
			$.post(path+'1',function(data){
				//alert(data);
			});
			$(this).text('ENABLE');
			$(this).parent().append('<span class="message-setting">&nbsp; Disabled successfully.</span>');
			$('.message-setting').fadeOut(2000);
		}
		else
		{
			$.post(path+'0',function(data){
				//alert(data);
			});
			$(this).text('DISABLE');
			$(this).parent().append('<span class="message-setting">&nbsp; Enabled successfully.</span>');
			$('.message-setting').fadeOut(2000);
		}
		
		return false;
	});
	
	/**
	loop through each <li>, if it has a children of <ul>, then append the class of 'indicator'.
	reset the style of which has a children.
	**/
	$(".form li").each(function () {
		if ( $(this).children('ul').size() > 0 ) 
		{
			$('h1:first', this).append("<span class='sub-indicator'></span>");
			$('h1:first', this).css({cursor:'pointer'});
			$(this).children('ul').css({display:'none'});
			$(this).addClass('toggle-my-children');
		}
	});
	
	/**
	toggle the subs and the subsubs
	**/
	$('.toggle-my-children').toggle(
		function (){
			$(this).children('ul').slideDown();
		},
		function (){
			$(this).children('ul').slideUp();
	});	
}

this.restore = function(){
	$(".restore").click(function(){
		var original = $(this).attr('rel');
		var parent = $(this).parent().parent().parent();
		var target = $('input', parent).val();
		//var original = $(this).text();
		//alert(original);
		//alert(target);
		
		if(original == target)
		{
			$(this).parent().parent().append('<span class="message-setting">&nbsp; Nothing was changed.</span>');
			$('.message-setting').fadeOut(2000);
		}
		else
		{
			$(this).css({color: ''});
			$("input", parent).val(original);
			$("input", parent).focus();
		}
		return false;
	});
	
	/**
	loop each of the input field
	change the color of its parent's restore button's colour to blue, when the keyup accurs on that input field.
	**/
	$("input").each(function () {
		$(this).keyup(function () {
			var parent = $(this).parent();
			$(".restore", parent).css({color:'#3374d0'});
		});
	});
}

this.restoreAll = function(target){	
$(".restore-all").click(function(){
	/**
	loop each of the input field accept the submit inputs which are 'update' and 'cancel'
	**/
	$("input:not(:submit)").each(function () {
		var parent = $(this).parent();
		var target = $(this).val();
		var original = parent.find('.restore').attr('rel');
		
		if(original == target)
		{
			parent.find('.left').append('<span class="message-setting">&nbsp; Nothing was changed.</span>');
			$('.message-setting').fadeOut(2000);
			$('form *[title]').inputHint();
		}
		else
		{
			parent.find('.restore').css({color: ''});
			$(this).val(original);
		}
	});
	return false;
	});
}

/*****************/

this.loadtinyMCE_simple = function(){
	tinyMCE.init({
		// General options
		mode : "exact",
		theme : "advanced",
		elements : "content_mce", //id
		plugins : "safari,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",

		// Theme options
		theme_advanced_buttons1 : "newdocument,pastetext,|,bold,italic,underline,strikethrough,|,undo,redo,|,link,unlink,image,media,|,help,code,|,fullscreen",
		theme_advanced_buttons2 : "",
		
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,
		
		// Specifying an Absolute Image Path
		//document_base_url : "http://localhost/art_on_your_doorstep_2009/", 
		document_base_url : http_root,
    	relative_urls : false,
        remove_script_host : false,
		
		
		// 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 : http_root+rp_cms+"mce_template_list.js",
		external_link_list_url : http_root+rp_cms+"mce_link_list.php",
		external_image_list_url : http_root+rp_cms+"mce_image_list.php",
		media_external_list_url : http_root+rp_cms+"mce_media_list.php",

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
	
}


this.loadtinyMCE_full = function(){
	tinyMCE.init({
		// General options
		mode : "exact",
		theme : "advanced",
		elements : "content_mce", //id
		plugins : "safari,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",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,|,forecolor,backcolor",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,
		
		// Specifying an Absolute Image Path
		//document_base_url : "http://localhost/art_on_your_doorstep_2009/", 
		document_base_url : http_root,
    	relative_urls : false,
        remove_script_host : false,
		
		
		// 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 : http_root+rp_cms+"mce_template_list.js",
		external_link_list_url : http_root+rp_cms+"mce_link_list.php",
		external_image_list_url : http_root+rp_cms+"mce_image_list.php",
		media_external_list_url : http_root+rp_cms+"mce_media_list.php",

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
}
