var ROOT_OFFSET = "../";

$(window).bind("load", function()
{
	var jxTables = $("TABLE").filter(function(){return /^tblEx/.test(this.id);});
	jxTables.addClass("example").set("cellSpacing", 5).execute(function()
	{
		var jxImg = $(".imgRunScript", this);
		var jxTextArea = $("TEXTAREA", this);
		if(jxImg.length == 1 && jxTextArea.length == 1)
		{
			jxImg.set("codeArea", jxTextArea[0]);
			jxImg.bind("click", function(){eval(this.codeArea.value);});
		}
		jxImg = $(".imgSelectAll", this);
		if(jxImg.length == 1 && jxTextArea.length == 1)
		{
			jxImg.set("codeArea", jxTextArea[0]);
			jxImg.bind("click", function(){this.codeArea.select();});
		}
	});
	
	$("TABLE TEXTAREA").set("cols", 80).execute(function()
	{
		var matches = this.value.match(/\r?\n/g);
		$(this).set("rows", Math.min(matches == undefined ? 1 : matches.length + 1,
			10));
	});
	
	$("TEXTAREA").bindHover(function(){$(this).addClass("over");},
		function(){$(this).removeClass("over");}, null, true).setClass("out");

	$(".imgRunScript, .imgSelectAll").bindHover(function(){
		this.src = ROOT_OFFSET + "images/" + this.className.replace("img", "")
			+ "-red.gif";
		$(this).setCSS("cursor", "pointer");
	},
	function(){
		this.src = ROOT_OFFSET + "images/" + this.className.replace("img", "")
			+ "-blue.gif";
	}, true);

	$("#tblParams").set("cellSpacing", 10);
});
