function widget() {
	var ident = "#blank";
	var _SHOW = true;
	var _HIDE = false;
	var isRunning = true;
	this.type = "default";
	var currentDoc = "";
	this.object = $(ident);
	this.header = $(ident + " .widgetHeader");
	this.footer = $(ident + " .widgetFooter");
	this.content = $(ident + " .widgetContent");
	this.closeBut = $(ident + " .widgetHeader .minimizar");
	this.__status = _HIDE;
	this.__construct = function () {
		this.object.hide();
		var objt = this;
		this.closeBut.click(function () {
			objt.Close();
		});
		this._setType(this.type);
	}
	this.init = function (id) {
		ident = (id) ? "#" + id : this.ident;
		currentDoc = "";
		this.object = $(ident);
		this.header = $(ident + " .widgetHeader");
		this.footer = $(ident + " .widgetFooter");
		this.content = $(ident + " .widgetContent");
		this.closeBut = $(ident + " .widgetHeader .minimizar");
		this.__status = _HIDE;
	}
	this._setType = function (_type) {
		this.object.data("_type", _type);
	}
	this.Open = function () {
		var dlg = $("#ie_experience");
		if (dlg.length>0)
		{
			if (dlg.dialog('isOpen'))
			{
				dlg.dialog(
					{
						close:function(){
								oW.Open();
						}
					});
				return;
			}
		}
		this.content.hide();
		var $this = this;
		this.object.slideDown(800, function () {
			$this = $this;
			$(this).find(".widgetContent").slideDown(800, function () {
				if (isRunning) {
					//isRunning = false;
					$($this).trigger("opened");
				}
			});
		});
		this.__status = _SHOW;
		this.currentDoc = document.location.hash;//pathname.replace("/", "");
	}
	this.Close = function (fichero) {
		var Obj = this;
		$this = $(this);
		this.content.slideUp(800, "swing", function () {
			$($this).trigger("closed");
			$($this).queue(function () {
				Obj.Loading("/");
				$($this).dequeue();
			});
		});
	}
	this.CloseAndLoading = function (fichero) {
		if (this.isChangedFichero(fichero)) {
			var Obt = this;
			var $this = $(this);
			$($this).trigger("closedBefore");
			this.content.slideUp(800, "swing", function () {
				$($this).trigger("closed");
				$($this).queue(function () {
					Obt.Loading(fichero);
					$($this).dequeue();
				});
			});
		} else {
			this.fxNoChange(fichero);
			return false;
		}
	}
	this.Loading = function (fichero) {
		$(".widget-loading").show();
		this.loadData(fichero+".php",{});
		//document.location = fichero;
	}
	this.changeContent = function (fichero) {
		var Obt = this;
		if (this.currentDoc != encodeURI(fichero)) {
			this.content.slideUp(800, "swing", function () {
				Obt.Destroy(fichero)
			});
		} else {
			this.object.effect("shake");
		}
	}
	this.isChangedFichero = function (fichero) {
		return (encodeURI(fichero) != this.currentDoc);
	}
	this.fxNoChange = function (fichero) {
		this.changeContent(fichero);
		this.content.promise().done(function () {
			$(this).parents("div.widget").effect("fold");
		});
	}
	this.Destroy = function (fichero) {
		this.content.empty();
		this.__status = _HIDE;
		if (fichero) {
			this.loadData(fichero, {});
		}
	}
	this.check = function (newWidget) {
		var type = this.type;
		$(".widget").each(function () {
			if ($(this).data("_type") == type) {
				if (newWidget === $(this).attr("id")) {
					return true;
				} else {
					$(this).attr("id", newWidget);
					return false;
				}
			}
		});
	}
	this.loadData = function (fichero, params) {
		var obt = this;
		$.post("docs/en/" + fichero, params, function (data) {
			obt.content.html(data);
			obt.Open();
			obt.currentDoc = fichero;
			commonLoadPage(fichero);
		}, "html");
	}
	
	this.position = function(){
		return this.object.position();	
	}
	this.positionAbsolute = function(){
		var posContent = $("#lyContent").position();
		var posWidget = this.object.position();
		posWidget.top += posContent.top;
		posWidget.left += posContent.left;
		return posWidget;
		
		//var h = this.position();
//		//Cogemos el offset height de top y ptos.
//		var offsetTop = $("#lyLiquidTop").height() + $("#lyLiquidPtos").height() + h;
		
	}
	this.__construct();
}
var oW;
$(document).ready(function () {
	oW = new widget();
	if (document.location.hash == "") oW.loadData("home.php",{});
	else oW.loadData(document.location.hash.replace("#","")+".php", {});
	oW.Open();
});
String.prototype.toUpper = function (init, long) {
	var x = this.substr(init, long).toUpperCase();
	var ret = this.substr(0, init) + x + this.substr(init + long, this.length);
	return ret;
}

