		// Menu Initialization begins here. This can be moved elsewhere
		$(function(){
			$('ul.jd_menu').jdMenu({	onShow: loadMenu
										//onHideCheck: onHideCheckMenu,
										//onHide: onHideMenu, 
										//onClick: onClickMenu, 
										//onAnimate: onAnimate
										});
			$('ul.jd_menu_vertical').jdMenu({onShow: loadMenu, onHide: unloadMenu, offset: 1, onAnimate: onAnimate});
		});

		function onAnimate(show) {
			//$(this).fadeIn('slow').show();
			if (show) {
				$(this)
					.css('visibility', 'hidden').show()
						.css('width', $(this).innerWidth())
					.hide().css('visibility', 'visible')
				.fadeIn('normal');
			} else {
				$(this).fadeOut('fast');
			}
		}

		var MENU_COUNTER = 1;
		function loadMenu() {
			if (this.id == 'dynamicMenu') {
				$('> ul > li', this).remove();
		
				var ul = $('<ul></ul>');
				var t = MENU_COUNTER + 10;
				for (; MENU_COUNTER < t; MENU_COUNTER++) {
					$('> ul', this).append('<li>Item ' + MENU_COUNTER + '</li>');
				}
			}
		}

		function unloadMenu() {
			if (MENU_COUNTER >= 30) {
				MENU_COUNTER = 1;
			}
		}

		// We're passed a UL
		function onHideCheckMenu() {
			return !$(this).parent().is('.LOCKED');
		}

		// We're passed a LI
		function onClickMenu() {
			$(this).toggleClass('LOCKED');
			return true;
		}
		// Menu Initialization ends here. This can be moved elsewhere


$(document).ready(function() {
						   
						   
	$("#progress").css("visibility","hidden");

    // Load the homepage even though nothing has been clicked yet..
	// *** The following line needs updating whenever we change the structure of what is sent to the server ***
	if (initialPage != "") {loadExternalContent("#content","replace",{ objAction: 'view', objData: initialPage, objTDiv: '#content', objTMethod: 'replace', objSessionKey: Piranha_SessionKey, objClientIP: Piranha_ClientIP})};

// On click, load external content into specified div..
	$('div').livequery('click', function(event) { 
		if ($(this).attr("id") == "Piranha_Click") {
			// Okay, its one of our buttons or links, what are we going to do with it? (view,edit,minimize,maximize)
			
			// Minimize:
			if ($(this).attr("Piranha_RequestAction") == "minimize") {
				var resizeWhat = $(this).attr("Piranha_RequestData");
				$("div[Piranha_SizeableId='" + resizeWhat + "']").slideUp(300);
				// *** The following line needs updating whenever we change the structure of what is sent to the server ***
				sendNotificationOnlyToServer($(this).attr("Piranha_ResponseTargetDiv"),$(this).attr("Piranha_ResponseUpdateMethod"),{objAction: $(this).attr("Piranha_RequestAction"), objData: $(this).attr("Piranha_RequestData") , objTDiv: $(this).attr("Piranha_ResponseTargetDiv"), objTMethod: $(this).attr("Piranha_ResponseUpdateMethod"), objSessionKey: Piranha_SessionKey, objClientIP: Piranha_ClientIP});
				}
			
			// Maximize:
			else if ($(this).attr("Piranha_RequestAction") == "maximize") {
				var resizeWhat = $(this).attr("Piranha_RequestData");
				$("div[Piranha_SizeableId='" + resizeWhat + "']").slideDown(300);
				// *** The following line needs updating whenever we change the structure of what is sent to the server ***
				sendNotificationOnlyToServer($(this).attr("Piranha_ResponseTargetDiv"),$(this).attr("Piranha_ResponseUpdateMethod"),{objAction: $(this).attr("Piranha_RequestAction"), objData: $(this).attr("Piranha_RequestData") , objTDiv: $(this).attr("Piranha_ResponseTargetDiv"), objTMethod: $(this).attr("Piranha_ResponseUpdateMethod"), objSessionKey: Piranha_SessionKey, objClientIP: Piranha_ClientIP});
				}

			// Save a plain form - without any fck editor: (via a form post, as a query string could be too long + encoding issues could result)
			else if ($(this).attr("Piranha_RequestAction") == "edit_saveplainform") {
				// Okay this is tricky. First lets grab some control parameters of the article being edited:
				var thisArticleID = $(this).attr("Piranha_RequestData");
				var targetDiv = $(this).attr("Piranha_ResponseTargetDiv");
				var displayMethod = $(this).attr("Piranha_ResponseUpdateMethod");				
				// Fill in any hidden form data to send (simulating our normal AJAX querystring method). Other data was prefilled by the responder when originally sent to us.
				$("input[id='Piranha_FormField_" + thisArticleID + "_objSessionKey']").attr("value",Piranha_SessionKey);
				$("input[id='Piranha_FormField_" + thisArticleID + "_objClientIP']").attr("value",Piranha_ClientIP);
				// Bind the form to the Ajax form library:
				$("#Piranha_FormPost_" + thisArticleID).ajaxForm(function(html) {
					// What follows is a duplication of the code which exists in our normal loadExternalContent routine below: (we need to unify this routine)													
					if (displayMethod == "append") {
						$(targetDiv).append(html);
						}
					else {
						// For ie we just switch the data due to flickering and clear type issues..
						if ($.browser.msie) { 
							$(targetDiv).html(html);
							// Any other action to perform after the data has been switched..
							}
						// For other browsers we can do nice fade transitions..
						else {
							$(targetDiv).fadeOut("slow",function(){
								$(targetDiv).html(html).fadeIn("slow", function(){
									// Any other action to perform after the fade in has completed..
									});
								}); 
							};
						};
					});				
				// Trigger the bound method against the form, to submit the data:
				$("#Piranha_FormPost_" + thisArticleID).submit();
				}

			// Save a form which contains an fck editor: (via a form post, as a query string could be too long + encoding issues could result)
			else if ($(this).attr("Piranha_RequestAction") == "edit_savewithfck") {
				// Okay this is tricky. First lets grab some control parameters of the article being edited:
				var thisArticleID = $(this).attr("Piranha_RequestData");
				var targetDiv = $(this).attr("Piranha_ResponseTargetDiv");
				var displayMethod = $(this).attr("Piranha_ResponseUpdateMethod");				
				// Next grab a handle to this instance of the fck editor:
				var oEditor = FCKeditorAPI.GetInstance('editor_' + thisArticleID);
				// Extract the html from the editor:
				var thisEditorText = oEditor.GetHTML();
				// Fill in any form data to send (simulating our normal AJAX querystring method). Other data was prefilled by the responder when originally sent to us.
				$("input[id='Piranha_FormField_" + thisArticleID + "_objHTML']").attr("value",thisEditorText);
				$("input[id='Piranha_FormField_" + thisArticleID + "_objSessionKey']").attr("value",Piranha_SessionKey);
				$("input[id='Piranha_FormField_" + thisArticleID + "_objClientIP']").attr("value",Piranha_ClientIP);
				// Bind the form to the Ajax form library:
				$("#Piranha_EditorPost_" + thisArticleID).ajaxForm(function(html) {
					// Once we replace the div, we're still going to be left with a residual editor script, so remove it:
					$("script[id='fckeditorscript_" + thisArticleID + "']").remove();
					// What follows is a duplication of the code which exists in our normal loadExternalContent routine below: (we need to unify this routine)													
					if (displayMethod == "append") {
						$(targetDiv).append(html);
						}
					else {
						// For ie we just switch the data due to flickering and clear type issues..
						if ($.browser.msie) { 
							$(targetDiv).html(html);
							// Any other action to perform after the data has been switched..
							}
						// For other browsers we can do nice fade transitions..
						else {
							$(targetDiv).fadeOut("slow",function(){
								$(targetDiv).html(html).fadeIn("slow", function(){
									// Any other action to perform after the fade in has completed..
									});
								}); 
							};
						};
					});				
				// Trigger the bound method against the form, to submit the data:
				$("#Piranha_EditorPost_" + thisArticleID).submit();
				}

			// Cancel fck editing:
			else if ($(this).attr("Piranha_RequestAction") == "edit_cancel") {
				// *** The following line needs updating whenever we change the structure of what is sent to the server ***
				loadExternalContent($(this).attr("Piranha_ResponseTargetDiv"),$(this).attr("Piranha_ResponseUpdateMethod"),{objAction: $(this).attr("Piranha_RequestAction"), objData: $(this).attr("Piranha_RequestData") , objTDiv: $(this).attr("Piranha_ResponseTargetDiv"), objTMethod: $(this).attr("Piranha_ResponseUpdateMethod"), objSessionKey: Piranha_SessionKey, objClientIP: Piranha_ClientIP});
				}
			
			// Otherwise (view,edit) send a content request to the server:
			else {
				// *** The following line needs updating whenever we change the structure of what is sent to the server ***
				loadExternalContent($(this).attr("Piranha_ResponseTargetDiv"),$(this).attr("Piranha_ResponseUpdateMethod"),{objAction: $(this).attr("Piranha_RequestAction"), objData: $(this).attr("Piranha_RequestData") , objTDiv: $(this).attr("Piranha_ResponseTargetDiv"), objTMethod: $(this).attr("Piranha_ResponseUpdateMethod"), objSessionKey: Piranha_SessionKey, objClientIP: Piranha_ClientIP});
				}

			// Nullify the result of this routine for menu nodes which have no children:
			if ($(this).attr("Piranha_RequestData") == 'page_home') {return false};
			}
		}); 

	// Whenever new content is added to the dom, use live query to add CSS to Piranha Click devices (Don't do it if AjaxOptionNoChangeClass = True)..
	$('div').livequery(function(){ 
		if ($(this).attr("id") == "Piranha_Click") {
			if ($(this).attr("Piranha_OptionNoChangeClass") == "true") {
				$(this).addClass('divlinkboundlatesetcursoronly');
				}
			else {
				$(this).removeClass();
				$(this).addClass('divlinkboundlate');
				$(this).append('&nbsp;&raquo;');
				// $(this).prepend('<img src="layoutimages/babyarrow.gif">'); *** This line adds a small arrow in front of links ***
				}
			}
		}); 


	// Basic routine for sending a notification to the server, does not expect any reply..
	function sendNotificationOnlyToServer(targetDiv, displayMethod, queryParams) {	
		$.get("default_responder.asp", queryParams, function(html){
			// Do nothing..
			});
		};


	// Basic routine for fetching external content and appending or replacing the existing with it..
	function loadExternalContent(targetDiv, displayMethod, queryParams) {	
		$("#progress").css("visibility","visible");
		$.get("default_responder.asp", queryParams, function(html){
			if (displayMethod == "append") {
				$(targetDiv).append(html);
				}
			else {
				// For ie we just switch the data due to flickering and clear type issues..
				if ($.browser.msie) { 
					$(targetDiv).html(html);
					// Any other action to perform after the data has been switched..
					$("#progress").css("visibility","hidden");
					}
				// For other browsers we can do nice fade transitions..
				else {
					$(targetDiv).fadeOut("slow",function(){
						$(targetDiv).html(html).fadeIn("slow", function(){
							// Any other action to perform after the fade in has completed..
							$("#progress").css("visibility","hidden");
							});
						}); 
					};
				};
			});
		};
	});
