// python4js

python4js = {"translate":
    function (p) {
    	p = p.replace(/<!--/g, "");
    	p = p.replace(/\/\/-->/g, "");
    	p = p.replace(/\n/g, ";\n");
    	p = p.replace(/def (\w+)\(([\w, ]+)\):;/g, "function $1($2) {");

    	p = p.replace(/^(\s*)for (\w+) in (\w+):;/gm, "$1for(var $2 in $3){\n$1    $2 = $3[$2];");
    	p = p.replace(/if (.*?):;/g, "if($1){");
    	p = p.replace(/\.append/g, ".push");
    	p = p.replace(/elif/g, "else if");
    	p = p.replace(/while (.*?):;/g, "while($1){");
    	p = p.replace(/list\((".*?")\)/g, "$1.split(\"\")");
    	p = p.replace(/^#!.*/m, "");

    	p = p.replace(/#/g, "//");
    	p = p.replace(/^;/gm, "");

    	lines = p.split("\n");
    	prev_indent = 0;
    	for(i in lines){
    		line = lines[i]
    		m = line.match("( *)(.*)");
    		indent = m[1].length;
    		var close = "";
    		while(indent < prev_indent){
    			prev_indent -= 4;
    			close += "}";
    		}
    		lines[i] = m[1] + close + m[2];
    		prev_indent = indent; 
    	}
    	p = lines.join("\n");
    	p = p.replace(/};/g, "}");

    	return p.replace(/^\s+/, "");
    }
}
function len(n){
    return n.length;
}

function chr(n){
    return String.fromCharCode(n);
}

function ord(s) {
	return s.charCodeAt(0);
}

{
	var s = document.getElementsByTagName("script");
	for(var i = 0; i < s.length; i++) {
		if(s[i].type && s[i].type == "text/python4js") {
			result = python4js.translate(s[i].text);
			eval(result);
		}
	}

}

