/* Commonly used function among pages */

/* prevent conflict with scriptaculous, prototype */
jQuery.noConflict();





/* run this config at start */
jQuery(document).ready(function()
{
	repaint();
	eventSetting();
});





function eventSetting()
{
	jQuery(".menucat").bind("click", function()
	{
		var src	= jQuery(this).find("img:eq(1)").attr("src");
		
		src = (src.lastIndexOf("-.png") > -1) ? src.replace("-.png", ".png") : src.replace(".png", "-.png");
		
		jQuery(this).find("img:eq(1)").attr("src", src);
		jQuery(this).next().stop(false, true).slideToggle(500);
	});
	
	jQuery(".menu").find("a").bind("click", function()
	{
		var action = jQuery(this).attr("href");
		
		jQuery(".menu").each(function()
		{
			var alt = jQuery(this).prev(".menucat").find("img:eq(1)").attr("alt");
			
			if (jQuery(this).is(":visible"))
				jQuery("input[name="+ alt +"]").val("true");
			else
				jQuery("input[name="+ alt +"]").val("false");
		});
		
		jQuery("form[name=menu-management]").attr("action", action).submit();
	});
}





function repaint()
{
	var w = 0;
	var h = 0;
	
	jQuery(".main-content td").each(function()
	{
		w = jQuery(this).width();
		h = jQuery(this).height();
		
		jQuery(this).find(".panelbg:eq(0)").css({ "width":w +"px", "height":h +"px" });
	});
	
	jQuery(".content").each(function()
	{
		w = jQuery(this).width();
		h = jQuery(this).height();
		
		jQuery(this).prev(".panelbg").css({ "width":w +"px", "height":h +"px" });
	});
}





/* support xml for IE */
function processXML(data)
{
	var xml = data;
	
	if(typeof data == "string") // IE uses "text" as content type, firefox uses "text/xml"
	{
		xml = new ActiveXObject("Microsoft.XMLDOM");
		xml.async = false;
		xml.loadXML(data);
	}
	return xml;
}