var fadeSpeed = 1500;

/* Ajax methods */
function ajaxReplace(href, containerId, isAjaxParamName){
	isAjaxParamName = isAjaxParamName ? isAjaxParamName : "isajaxrequest";
	$j.ajax({
		url: href + "&" + isAjaxParamName + "=true",
		dataType: "html",
		success: function(response){
			$j(containerId).html(response);
		}
	});
}


// Fire off page specific init method
$j(document).ready(function() {
	
	var isAdmin = false;
	if (location.href.indexOf("admin/") > -1){
		isAdmin = true;
	}
	
	// Replace Nav
	$j("#NavigationPrimaryLeft > ul > li > a").each(function(){
		var jElm = $j(this);
		var liClass = new String(jElm.parent().attr("class"));
		var current = "";
		if (liClass != "undefined" && liClass != "" && liClass != "first")
			current = "-current";
		var text = jElm.text();
		var imageName = new String(jElm.text() + current + ".gif");
		imageName = imageName.toLowerCase();
		imageName = imageName.replace(" ", "-");
		var imageUrl = appPath + "_client/images/global/nav-options/" + imageName;
		jElm.html("<img src=\"" + imageUrl + "\" alt=\"" + text + "\" />");
	});
	
	$j("#NavigationPrimaryLeft > ul > li > a > img").each(function(){
		var jElm = $j(this);
		var src = this.src;
		jElm.mouseover(function(){
			var jElm = $j(this);
			var rolloverImageSrc = new String(src);
			if (rolloverImageSrc.indexOf("-current") < 0){
				rolloverImageSrc = rolloverImageSrc.replace(".gif", "-current.gif");
				this.src = rolloverImageSrc;
			}
		});
		jElm.mouseout(function(){
			this.src = src;
		});
	});
	
	// Replace H1s
	$j("h1").each(function(){
		var jElm = $j(this);
		if (jElm.children().length > 0)
			jElm = $j(jElm.children()[0]); // Replace the child element rather than the header.
		
		var elementType = "h1";
		if (isAdmin)
			elementType = "h1-admin";
		var text = jElm.text();
		var imageUrl = appPath + "_Handlers/ImageTextWriterHandler.ashx?elementtype=" + elementType + "&text=" + escape(text) + "&color=" + escape(header1Color);
		jElm.html("<img src=\"" + imageUrl + "\" alt=\"" + text + "\" />");
	});
	
	// Replace H2s
	$j("h2").each(function(){
		var jElm = $j(this);
		if (jElm.children().length > 0)
			jElm = $j(jElm.children()[0]); // Replace the child element rather than the header.
			
		var text = jElm.text();
		var color = new String(jElm.attr("class"));
		if (color == "undefined") color = "";
		var imageUrl = appPath + "_Handlers/ImageTextWriterHandler.ashx?elementtype=h2&text=" + escape(text) + "&color=" + escape(color);
		jElm.html("<img src=\"" + imageUrl + "\" alt=\"" + text + "\" />");
	});
	
	// Replace "Do" links
	$j("p.doaction").each(function(){
		var jElm = $j(this);
		if (jElm.children().length > 0)
			jElm = $j(jElm.children()[0]); // Replace the child element rather than the header.
			
		var text = jElm.text();
		var imageUrl = appPath + "_Handlers/ImageTextWriterHandler.ashx?elementtype=doaction&text=" + escape(text);
		jElm.html("<img src=\"" + imageUrl + "\" alt=\"" + text + "\" />");
	});

	if (typeof initPage == "function"){
		initPage();
	}
});

function documentLoaded(){
	if (typeof documentOnLoad == "function"){
		documentOnLoad();
	}
}