// JavaScript Document

function login_show(){
	//$("#adminBar").slideUp(200);
	setTimeout("$(\"#loginContainer\").slideDown(300);",200);
}
function login_hide(){
	$("#loginContainer").slideUp(200);
	//setTimeout("$(\"#adminBar\").slideDown(300);",200);
}




function initiatePageEdit(){
	
var pageEditable = false;

		if ( $(".editable") != null){
		


		// Put in an edit bar around each editable DIV
		$(".editable").each(function(){
			
			// Grab the attributes we need
			var divName = $(this).attr("id");
			var editFileName = "edit_" + divName + ".txt";
			var editTheme = $(this).attr("et");
			var editRows = $(this).attr("er");
			
			// Initial editBar is a edit Icon
			var editBarHTML = "<div id=\"" + divName + "EditBar\" class=\"editBar\">\n";
			editBarHTML += "<a href=\"javascript:edit('" + divName + "','" + editTheme + "','" + editRows + "');\">";
			editBarHTML += "<img src=\"media/images/editing/editpencil.png\" width=\"32\" height=\"32\" alt=\"edit\" border=\"0\"/>";
			editBarHTML += "</a>";
			editBarHTML += "</div>";
			
			$(this).before(editBarHTML);
	
			
		})
		} else {
			alert("There are no areas to edit on this page!");	
		}
}

var notCurrentingEditing = true;
function cancelEdit(editarea){
	
	var backupContents = $("#editingStorageDIV").html();
	var editAreaDIV = eval("$(\"#" + editarea + "\")");
	
	var editorBar = eval("$(\"#" + editarea + "EditBar\")");
	var editBarHTMLBackup = $("#editingEditBarStorageDIV").html();
	
	$(editorBar).html(editBarHTMLBackup);
	$(editAreaDIV).html(backupContents);
	
	notCurrentingEditing = true;
	
}
function saveEdit(editarea){

	// force tinyMCE to save content:
	tinyMCE.triggerSave();
	var a = "document." + editarea + "Form.submit();";
	eval(a);
	
}
function edit(editarea, theme, editRows){
//<a href="javascript:edit('guitarList');">
//<img src="media/images/editing/editpencil.png" width="32" height="32" alt="edit" border="0" id="guitarListEditIcon" name="guitarListEditIcon"/></a>
//<img src="media/images/headings/Guitars.gif" alt="" width="110" height="32" />      
//<div id="guitarList" class="editable" editFile="edit_guitarList.txt">    
// edit_guitarList.txt");

if (notCurrentingEditing){
	
	if (editRows == "" || editRows == null){ editRows = 10;}

	// Grab the current Contents of the DIV
	var currentContents = eval("$(\"#" + editarea + "\").html()"); 
	// Store the contents for undo capabiltiites.
	$("#editingStorageDIV").html(currentContents);

	var formContent = "<form action=\"processEdit.php\" method=\"post\" name=\"" + editarea + "Form\">";
	formContent += "<input type=\"hidden\" name=\"editareaname\" value=\"" + editarea + "\">";
	formContent += "<textarea id=\"content\" rows=\"" + editRows + "\" style=\"width:95%\" name=\"content\" class=\"mceEditor\" >";
	formContent += currentContents;
	formContent += "</textarea></form>";

	// dump the new contents into the editing DIV
	eval("$(\"#" + editarea + "\").html(formContent)"); 
	
	
	// Update the edit area to show 'SAVE' and 'CANCEL' icons
	var saveCancelHTML = "<a href=\"javascript:cancelEdit('" + editarea + "')\">";
	saveCancelHTML += "<img src=\"media/images/editing/editcancel.png\" width=\"32\" height=\"32\" alt=\"edit\" border=\"0\"/>";
	saveCancelHTML += "</a>&nbsp;&nbsp;&nbsp;";
	saveCancelHTML += "<a href=\"javascript:saveEdit('" + editarea + "')\">";
	saveCancelHTML += "<img src=\"media/images/editing/editsave.png\" width=\"32\" height=\"32\" alt=\"edit\" border=\"0\"/>";
	saveCancelHTML +="</a>";
	var editorBar = eval("$(\"#" + editarea + "EditBar\")");
	var editorBarHTMLBackup = $(editorBar).html();
	$("#editingEditBarStorageDIV").html(editorBarHTMLBackup);
	$(editorBar).html(saveCancelHTML);
	
	
	// Set the global variable so we know if we're already editing another area or not?
	notCurrentingEditing = false;

	// Invoke TinyMCE Editor, either simple or advanced theme
	
	if (theme =="" || theme == "simple"){
		tinyMCE.init({
			mode : "specific_textareas",
			editor_selector : "mceEditor",
			theme : "simple"
		});
	} 
	
	if (theme == "advanced"){
		tinyMCE.init({
			mode : "specific_textareas",
			editor_selector : "mceEditor",
			theme : "advanced",
			theme_advanced_toolbar_location : "top"
		});	
	}
	
	if (theme == "bulletinboard"){
		tinyMCE.init({
			mode : "specific_textareas",
			editor_selector : "mceEditor",
			theme : "bulletinboard"

		});	
	}
	

} else {
	alert("You can only edit one area at a time.");
}
	
}

