if(!HOME)
	var HOME = "quienes";
var _toLoad = new Array();
var HTMLEXT = ".html";

function myOnload(f){
	_toLoad[_toLoad.length] = f;
}

$(document).ready(function(){
    Load(HOME);
})

function Load(file){
	loadPage.place(file);
}

var loadPage = {
	HTMLPREFIX: "",
	HTMLEXT: ".html",
	SWFPREFIX: "swf/blur_",
	SWFEXT: ".swf",
	BaseScripts:null,
	BaseStyles:null,
	LOADEDSTYLES:null,
	LOADEDSCRIPTS:null,
	stID:0,
	scID:0,

	init:function(){
		this.readScripts();
		this.readStyles();
	},
	readScripts:function(){
		var me = this;
		this.BaseScripts = new Array();
		$("head").children("script").each(function(){
			me.BaseScripts[me.BaseScripts.length] = $(this).attr("src");
		});
	},
	readStyles:function(){
		var me = this;
		this.BaseStyles = new Array();
		$("head").children("link[rel='stylesheet']").each(function(){
			me.BaseStyles[me.BaseStyles.length] = $(this).attr("src");
		});
	},
	place: function(file,params){
		this.unloadStyles();
		this.unloadScripts();
	
		this.LOADEDSTYLES = new Array();
		this.LOADEDSCRIPTS = new Array();
		var html = this.HTMLPREFIX + file + this.HTMLEXT;
		var title = this.SWFPREFIX + file + this.SWFEXT;

		if(!params)	 params = {};
		
		$("#LOADING").fadeIn(150);
		var me = this;
		//var p = $.get(html, params, function(d){me.__onComplete(d)}, "html");

		$.ajax({
				success: function(d){me.__onComplete(d, title)},
				dataType: "html",
				type: "GET",
				cache: false,
				url: html
			}
		);
	},
	__onComplete: function(xdoc, title){
		// Ejecutamos todos los noscripts
		var me=this;
		var xDocument = document.createElement("div");
		xdoc = this.myReplaceAll("<script", "<code rel='myScripts' style='display:none'", xdoc);
		xdoc = this.myReplaceAll("</script>", "</code>", xdoc);

		//alert(xdoc);
		
		xdoc = $(xDocument).append(xdoc);

		$("code[rel='myScripts']", xdoc).each(function(){
			var src = $(this).attr("src");
			if($(this).html().length > 0){
				var code = me.__parseScript($(this).html());
				eval(code);
			}else if(src && src.length > 0){
				me.loadScript(me.HTMLPREFIX + $(this).attr("src"));
			}
			$(this).remove();
		});

		$("link[rel='stylesheet']", xdoc).each(function(){
			if($(this).attr("href").length > 0){
				me.loadStyle(me.HTMLPREFIX + $(this).attr("href"));
			}
			$(this).remove();
		});

		$("#Body").html("");
		$("#Body").append(xdoc);
		
		for(var i=0;i<_toLoad.length;i++){
			_toLoad[i]();
		}

		_toLoad = new Array();
		loadTitle(title);
		$("#LOADING").fadeOut(150);
	},
	__parseScript: function(code){
		code = this.myReplaceAll("&gt;", ">", code);
		code = this.myReplaceAll("&lt;", "<", code);
		return code;
	},
	loadScript: function(src){
		this.scID++;
		var id = "SCRIPT_"+this.scID;
		$("HEAD").append("<script src='" + src +"' type='text/javascript' _id='"+id+"'></script>");
		this.LOADEDSCRIPTS[this.LOADEDSCRIPTS.length] = id;
	},
	loadStyle: function(src){
		this.stID++;
		var id = "STYLE_"+this.stID;
		$("HEAD").append('<link rel="stylesheet" type="text/css" href="' + src + '" _id="'+id+'"/>');
		//this.LOADEDSTYLES[this.LOADEDSTYLES.length] = src;
		this.LOADEDSTYLES[this.LOADEDSTYLES.length] = id;
	},
	unloadStyles: function(){
		if(this.LOADEDSTYLES && this.LOADEDSTYLES.length > 0){
			for(var i=0;i<this.LOADEDSTYLES.length;i++){
				var src = this.LOADEDSTYLES[i];
				var o = $("HEAD").children("link[rel='stylesheet'][_id='"+src+"']");
				o.remove();
			}
		}
	},
	unloadScripts: function(){
		if(this.LOADEDSCRIPTS && this.LOADEDSCRIPTS.length > 0){
			for(var i=0;i<this.LOADEDSCRIPTS.length;i++){
				var src = this.LOADEDSCRIPTS[i];
				var o = $("HEAD").children("script[_id='"+src+"']");
				o.remove();
			}
		}
	},
	myReplaceAll:function(pattern,str,where){
		while(where.indexOf(pattern) != -1){
			where = where.replace(pattern,str);
		}
		return where;
	}
}



function loadTitle(file){
	var title = new FlashObject(file, "title", "267", "47", "8", "");
    title.addParam("allowScriptAccess", "sameDomain");
    title.addParam("movie", file);
    title.addParam("quality", "high");
    title.addParam("scale", "noscale");
    title.addParam("wmode", "transparent");
title.write("TITLE");
}


var dN=0;
function debug(m){
	$("#DEBUG").show();
	dN++;
	var rdN = ((dN < 100) ? "0" : "") + ((dN < 10) ? "0" : "") + dN;
	$("#DEBUG").text(rdN + " : " + m + "\r\n" + $("#DEBUG").text())
}