function LesQuintanes(idContenedor) {

	/* =======================
	 ATRIBUTOS
	 ======================= */

	var parent = this;

	this._HTML_REGEX = /<br\/?>|<\/[a-zA-Z]+>|&#?\w*;/;

	this._contenedor = null;

	this._capaAplicacion = null;
	this._cabecera = null;
	this._titulo = null;
	this._textoTitulo = null;
	this._contenidoMedio = null;
	this._menu = null;
	this._piePagina = null;
	this._espacioPrincipal = null;
	this._catLnk = null;
	this._castLnk = null;
	this._engLnk = null;
	this._banderaIngreso = false;
	this._datosHome = null;

	this._secuenciaImagenesFondo = [];

	this._paginaActual = "home";

	this._pila = new Array();
	this._pila_titulos = new Array();

	/* =======================
	 METODOS Y FUNCIONES
	 ======================= */

	this.ajustarEstilosIngresar = function() {
		if(!parent._banderaIngreso) {
			$("ul#supersized").remove();

			$("td.pieDePagina").each(function() {
				$(this).removeClass("pieDePagina");
				$(this).addClass("pieDePagina2");
			});
			$("td.firma").each(function() {
				$(this).removeClass("firma");
				$(this).addClass("firma2");
			});
			$("td.bordeCabecera").each(function() {
				$(this).css("border-color", "black");
			});
			$("td.selectorIdioma").each(function() {
				$(this).css("color", "black");
			});
			$(".Titulo").css("color", "black");
			$("ul.Menu li.itemi").removeClass("home");
			$("#logo").attr("src", "img/logo2.png");
			$("td.facebookCell").css("display", "block");
			$("body").css("background-color", "white");
		}
	};

	this.reubicarPiePagina = function() {
		var posY = this._espacioPrincipal.offsetTop;
		var height = this._espacioPrincipal.clientHeight;
		if(height < 230) {
			height = 240;
		}
		posY += height + 30;
		$(this._piePagina).css("top", posY + "px");
	}

	this.asignarTitulo = function(nuevoTituloLI, apilar) {
		if(apilar != null && apilar) {
			parent._pila_titulos.push($(parent._cabecera).find("ul#listaTitulos").children(":first"));
			$(parent._cabecera).find("ul#listaTitulos").children(":first").detach();
		}
		$(parent._cabecera).find("ul#listaTitulos").empty();
		$(parent._cabecera).find("ul#listaTitulos").append(nuevoTituloLI);
	};

	this.crearTituloSimple = function(cat, cast, eng) {
		var li = document.createElement("li");
		$(li).addClass("etiqueta");
		$(li).addClass("Titulo");
		$(li).data("cat", cat);
		$(li).data("cast", cast);
		$(li).data("eng", eng);

		var idioma = $("div#aplicacion").data("idioma");
		$(li).html($(li).data(idioma));

		$(li).css("color", "black");

		return li;
	}

	this.loadEspaiArt = function() {
		if(parent._paginaActual != "espai_art") {
			parent.ajustarEstilosIngresar();
			parent._banderaIngreso = true;

			new PaginaEspaiArt(parent._espacioPrincipal);
			parent._paginaActual = "espai_art";

			parent.asignarTitulo(parent.crearTituloSimple(parent._datosHome.menu.espaidart.cat, parent._datosHome.menu.espaidart.cast, parent._datosHome.menu.espaidart.eng));
		}

	};

	this._popcallback = function(desapilar_titulo) {
		if(desapilar_titulo != null && desapilar_titulo) {
			parent.asignarTitulo(parent._pila_titulos[0]);
		}
		$(parent._espacioPrincipal).children(":first").remove();
		var child = parent._pila.pop();
		$(parent._espacioPrincipal).prepend(child);
	}

	this._artistaCallback = function(idArtista) {

		var child = $(parent._espacioPrincipal).children(":first");
		parent._pila.push(child);
		$(child).detach();

		new PaginaExposicion("artista", parent._espacioPrincipal, parent._cvcallback, idArtista, parent._popcallback);
		parent._paginaActual = "artista_" + idArtista;

	};

	this._botigaCallback = function(id_coleccio) {
		var child = $(parent._espacioPrincipal).children(":first");
		parent._pila.push(child);
		$(child).detach();

		new PaginaExposicion("botiga", parent._espacioPrincipal, null, id_coleccio, parent._popcallback);
		parent._paginaActual = "galeria_botiga_" + id_coleccio;
	};

	this._cvcallback = function() {
		var child = $(parent._espacioPrincipal).children(":first");
		parent._pila.push(child);
		$(child).detach();

		if(parent._paginaActual.indexOf("artista") != -1) {
			var idArtista = parseInt(parent._paginaActual.replace("artista_", ""));
			new PaginaCurriculum(parent._espacioPrincipal, parent._popcallback, null, idArtista);
		} else {
			new PaginaCurriculum(parent._espacioPrincipal, parent._popcallback, parent._paginaActual);
		}

	};

	this.loadPermanent = function() {
		if(parent._paginaActual != "permanent") {
			parent.ajustarEstilosIngresar();
			parent._banderaIngreso = true;

			new PaginaExposicion("permanent", parent._espacioPrincipal, parent._cvcallback);
			parent._paginaActual = "permanent";
		}
	};

	this.loadActual = function() {
		if(parent._paginaActual != "actual") {
			parent.ajustarEstilosIngresar();
			parent._banderaIngreso = true;

			new PaginaExposicion("actual", parent._espacioPrincipal, parent._cvcallback);
			parent._paginaActual = "actual";
		}
	};

	this.loadPropera = function() {
		if(parent._paginaActual != "propera") {
			parent.ajustarEstilosIngresar();
			parent._banderaIngreso = true;

			new PaginaExposicion("propera", parent._espacioPrincipal, parent._cvcallback);
			parent._paginaActual = "propera";
		}
	};

	this.loadAnterior = function() {
		if(parent._paginaActual != "propera") {
			parent.ajustarEstilosIngresar();
			parent._banderaIngreso = true;

			new PaginaExposicion("anterior", parent._espacioPrincipal, parent._cvcallback);
			parent._paginaActual = "anterior";
		}
	};

	this.loadArtistes = function() {
		if(parent._paginaActual != "artistes") {
			parent.ajustarEstilosIngresar();
			parent._banderaIngreso = true;

			new PaginaArtistes(parent._espacioPrincipal, parent._artistaCallback);
			parent._paginaActual = "artistes";

			parent.asignarTitulo(parent.crearTituloSimple(parent._datosHome.menu.artistes.cat, parent._datosHome.menu.artistes.cast, parent._datosHome.menu.artistes.eng));
		}

	};

	this.loadBotiga = function() {
		if(parent._paginaActual != "botiga") {
			parent.ajustarEstilosIngresar();
			parent._banderaIngreso = true;

			new PaginaBotiga(parent._espacioPrincipal, parent._botigaCallback);
			parent._paginaActual = "botiga";

		}
	};

	this.loadFesTeSoci = function() {
		if(parent._paginaActual != "festesoci") {
			parent.ajustarEstilosIngresar();
			parent._banderaIngreso = true;

			new PaginaFestesoci(parent._espacioPrincipal);
			parent._paginaActual = "festesoci";

			parent.asignarTitulo(parent.crearTituloSimple(parent._datosHome.menu.festesoci_titulo.cat, parent._datosHome.menu.festesoci_titulo.cast, parent._datosHome.menu.festesoci_titulo.eng));
		}
	};

	this.loadContactans = function() {
		if(parent._paginaActual != "contactans") {
			parent.ajustarEstilosIngresar();
			parent._banderaIngreso = true;

			new PaginaContactans(parent._espacioPrincipal);
			parent._paginaActual = "contactans";

			parent.asignarTitulo(parent.crearTituloSimple(parent._datosHome.menu.contactans.cat, parent._datosHome.menu.contactans.cast, parent._datosHome.menu.contactans.eng));
		}
	};

	this.secuenciar_fondos = function(idx) {
		if(idx < this._secuenciaImagenesFondo.length) {

			var img = new Image();
			img.src = "img/fondos/" + parent._secuenciaImagenesFondo[idx];
			//img.onload = function() {
				parent._secuenciaImagenesFondo[idx] = 'img/fondos/' + parent._secuenciaImagenesFondo[idx];
				parent.secuenciar_fondos(idx + 1);
			//};
		} else {
			this.configurar_fondos();
		}

	};

	this.configurar_fondos = function() {

		var imagenes = [];

		for(var i = 0; i < this._secuenciaImagenesFondo.length; i++) {
			imagenes[i] = {
				image : this._secuenciaImagenesFondo[i],
				title : '',
				url : ''
			};
		}

		jQuery(function($) {
			$.supersized({

				//Functionality
				slideshow : 1, //Slideshow on/off
				autoplay : 1, //Slideshow starts playing automatically
				start_slide : 1, //Start slide (0 is random)
				random : 0, //Randomize slide order (Ignores start slide)
				slide_interval : 5000, //Length between transitions
				transition : 1, //0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
				transition_speed : 500, //Speed of transition
				new_window : 0, //Image links open in new window/tab
				pause_hover : 0, //Pause slideshow on hover
				keyboard_nav : 0, //Keyboard navigation on/off
				performance : 2, //0-Normal, 1-Hybrid speed/quality, 2-Optimizes image quality, 3-Optimizes transition speed // (Only works for Firefox/IE, not Webkit)
				image_protect : 1, //Disables image dragging and right click with Javascript
				image_path : '', //Default image path

				//Size & Position
				min_width : 0, //Min width allowed (in pixels)
				min_height : 0, //Min height allowed (in pixels)
				vertical_center : 1, //Vertically center background
				horizontal_center : 0, //Horizontally center background
				fit_portrait : 0, //Portrait images will not exceed browser height
				fit_landscape : 0, //Landscape images will not exceed browser width

				//Components
				navigation : 0, //Slideshow controls on/off
				thumbnail_navigation : 0, //Thumbnail navigation
				slide_counter : 0, //Display slide numbers
				slide_captions : 0, //Slide caption (Pull from "title" in slides array)
				slides : imagenes
			});
		});

		$("#aplicacion").bind("esperarFondos", function(){

				parent.esperarFondos();

		});
		
		setTimeout("$('#aplicacion').trigger('esperarFondos')", 100);

	}

	this.esperarFondos = function() {
		
		if ($("div#supersized-loader").size() == 0) {
			this._contenedor = document.getElementById(idContenedor);
			$(this._contenedor).css({
				width : '100%',
				height : '100%'
			});
			$("div#cargando").remove();		
			this.inicializar();	
		}
		else {
			setTimeout("$('#aplicacion').trigger('esperarFondos')", 100);
		}

	};

	this.inicializar = function() {

		this._capaAplicacion = document.createElement("div");
		$(this._capaAplicacion).attr("id", "_capaAplicacion");
		$(this._capaAplicacion).css("position", "absolute");
		$(this._capaAplicacion).css("left", "0px");
		$(this._capaAplicacion).css("top", "0px");
		$(this._capaAplicacion).css("z-index", "1");
		$(this._capaAplicacion).css("padding-left", "50px");
		$(this._capaAplicacion).css("padding-top", "20px");

		$(this._contenedor).append(this._capaAplicacion);

		this.crearCabecera();

		this.crearContenidoMedio();

		$(this._capaAplicacion).css("width", "877px");
		$(this._capaAplicacion).css("height", "100%");

		this.crearPieDePagina();

		$(this._catLnk).click();

		this._menu.onLoadEspai = this.loadEspaiArt;
		this._menu.onLoadPermanent = this.loadPermanent;
		this._menu.onLoadActual = this.loadActual;
		this._menu.onLoadPropera = this.loadPropera;
		this._menu.onLoadAnterior = this.loadAnterior;
		this._menu.onLoadArtistes = this.loadArtistes;
		this._menu.onLoadBotiga = this.loadBotiga;
		this._menu.onLoadFesTeSoci = this.loadFesTeSoci;
		this._menu.onLoadContactans = this.loadContactans;

		$("div#aplicacion").data("asignarTitulo", parent.asignarTitulo);
	};

	this.crearCabecera = function() {
		this._cabecera = document.createElement("div");
		$(this._cabecera).attr("id", "Cabecera");
		$(this._cabecera).css("float", "top");
		$(this._cabecera).css("width", "100%");
		$(this._cabecera).css("padding-bottom", "10px");
		var table = document.createElement("table");
		$(this._cabecera).append(table);
		$(table).css({
			width : '100%',
			height : '100%'
		});
		var langRow = document.createElement("tr");
		$(table).append(langRow);
		this._catLnk = document.createElement("a");
		$(this._catLnk).attr("id", "cat");
		$(this._catLnk).text("Cat");
		$(this._catLnk).addClass("selectorIdioma");
		this._castLnk = document.createElement("a");
		$(this._castLnk).attr("id", "cast");
		$(this._castLnk).text("Cast");
		$(this._castLnk).addClass("selectorIdioma");
		this._engLnk = document.createElement("a");
		$(this._engLnk).attr("id", "eng");
		$(this._engLnk).text("Eng");
		$(this._engLnk).addClass("selectorIdioma");
		var langCell = document.createElement("td");
		$(langCell).attr("colspan", "2");
		$(langCell).css("text-align", "right");
		$(langCell).css("border-bottom", '1px solid');
		$(langCell).css("border-color", 'white');
		$(langCell).addClass("selectorIdioma");
		$(langCell).addClass("bordeCabecera");
		$(langCell).append(this._catLnk);
		$(langCell).append("|");
		$(langCell).append(this._castLnk);
		$(langCell).append("|");
		$(langCell).append(this._engLnk);
		$(langRow).append(langCell);
		$(this._capaAplicacion).append(this._cabecera);

		$(this._catLnk).click(function() {
			$("a.selectorIdioma").removeClass("actual");
			$(this).addClass("actual");
			$(".etiqueta").each(function() {
				var texto = $(this).data("cat");
				if(texto.indexOf("<br>") != -1 || texto.indexOf("</") != -1 || texto.indexOf("&#") != -1 || $(this).data("tipo") == "html" || texto.search(parent._HTML_REGEX) != -1) {
					$(this).html(texto);
				} else if($(this).data("tipo") == "link") {
					$(this).attr("href", $(this).data("cat"));
				} else {
					$(this).text(texto);
				}

				$("#aplicacion").data("idioma", "cat");
			});
		});

		$(this._castLnk).click(function() {
			$("a.selectorIdioma").removeClass("actual");
			$(this).addClass("actual");
			$(".etiqueta").each(function() {
				var texto = $(this).data("cast");
				if(texto.indexOf("<br>") != -1 || texto.indexOf("</") != -1 || $(this).data("tipo") == "html" || texto.search(parent._HTML_REGEX) != -1) {
					$(this).html(texto);
				} else if($(this).data("tipo") == "link") {
					$(this).attr("href", $(this).data("cast"));
				} else {
					$(this).text(texto);
				}
				$("#aplicacion").data("idioma", "cast");
			});
		});

		$(this._engLnk).click(function() {
			$("a.selectorIdioma").removeClass("actual");
			$(this).addClass("actual");
			$(".etiqueta").each(function() {
				var texto = $(this).data("eng");
				if(texto.indexOf("<br>") != -1 || texto.indexOf("</") != -1 || $(this).data("tipo") == "html" || texto.search(parent._HTML_REGEX) != -1) {
					$(this).html(texto);
				} else if($(this).data("tipo") == "link") {
					$(this).attr("href", $(this).data("eng"));
				} else {
					$(this).text(texto);
				}
				$("#aplicacion").data("idioma", "eng");
			});
		});
		// fila contenido
		var contenidoRow = document.createElement("tr");
		$(contenidoRow).append("<td><img id='logo' src='img/logo.png' style='width:100px; height:100px; padding-top: 10px; padding-bottom:8px'></td>");
		$(table).append(contenidoRow);

		// preload second logo
		var imgPreloadLogo2 = new Image();
		imgPreloadLogo2.src = "img/logo2.png";

		var lista = document.createElement("ul");
		$(lista).attr("id", "listaTitulos");
		$(lista).css("list-style-type", "none");
		$(lista).css("padding", "0px");
		var contenidoCell = document.createElement("td");
		$(contenidoCell).appendTo(contenidoRow);
		$(contenidoCell).css("vertical-align", "bottom");
		$(contenidoCell).css("width", "677px");
		$(contenidoCell).css("padding-left", "90px");
		$(contenidoCell).append(lista);

		this._titulo = document.createElement("li");
		$(this._titulo).addClass("etiqueta");
		$(this._titulo).addClass("Titulo");
		$(this._titulo).data("cat", this._datosHome.cabecera.titulo.cat);
		$(this._titulo).data("cast", this._datosHome.cabecera.titulo.cast);
		$(this._titulo).data("eng", this._datosHome.cabecera.titulo.eng);
		$(lista).append(this._titulo);

		this._textoTitulo = document.createElement("li");
		$(lista).append(this._textoTitulo);
		$(this._textoTitulo).addClass("etiqueta");
		$(this._textoTitulo).addClass("TextoTitulo");
		$(this._textoTitulo).css("margin-top", "30px");

		$(this._textoTitulo).data("cat", this._datosHome.cabecera.texto.cat);
		$(this._textoTitulo).data("cast", this._datosHome.cabecera.texto.cast);
		$(this._textoTitulo).data("eng", this._datosHome.cabecera.texto.eng);

		$(table).append("<tr><td colspan='2' class='bordeCabecera' style='border-top: 1px solid; border-color: white;'></td></tr>");

	};

	this.crearContenidoMedio = function() {

		this._contenidoMedio = document.createElement("div");
		$(this._contenidoMedio).attr("id", "ContenidoMedio");
		$(this._contenidoMedio).css("width", "100%");
		$(this._capaAplicacion).append(this._contenidoMedio);

		var contenedorMenu = document.createElement("div");
		$(contenedorMenu).attr("id", "contenedorMenu");
		$(contenedorMenu).css("padding-top", "10px");
		$(contenedorMenu).css("vertical-align", "top");
		$(contenedorMenu).css("float", "left");
		$(contenedorMenu).css("width", "200px");

		this._menu = new MenuLesQuintanes(contenedorMenu, this._datosHome);

		this._espacioPrincipal = document.createElement("div");
		$(this._espacioPrincipal).attr("id", "EspacioPrincipal");
		$(this._espacioPrincipal).css("float", "left");
		$(this._espacioPrincipal).css("position", "absolute");
		$(this._espacioPrincipal).css("left", "250px");
		$(this._espacioPrincipal).css("width", "677px");

		$(this._espacioPrincipal).watch("offsetTop", function(propertyName, oldValue, newValue) {
			parent.reubicarPiePagina();
		});

		$(this._espacioPrincipal).watch("clientHeight", function(propertyName, oldValue, newValue) {
			if(newValue > 0) {
				parent.reubicarPiePagina();
			}
		});
		var pusher = document.createElement("div");
		$(pusher).css("height", "300px");
		$(this._espacioPrincipal).append(pusher);

		$(this._contenidoMedio).append(contenedorMenu);
		$(this._contenidoMedio).append(this._espacioPrincipal);

		$("ul.Menu li.itemi").addClass("home");

	};

	this.crearPieDePagina = function() {
		this._piePagina = document.createElement("div");
		$(this._capaAplicacion).append(this._piePagina);
		$(this._piePagina).attr("id", "PieDePagina");
		$(this._piePagina).css("position", "absolute");
		$(this._piePagina).css("left", "50px");
		$(this._piePagina).css("top", "600px");
		$(this._piePagina).css("width", "877px");

		var table = document.createElement("table");
		$(table).attr("cellpadding", "0");
		$(table).attr("cellspacing", "0");
		$(table).css({
			width : '100%',
			height : '100%'
		});
		$(this._piePagina).append(table);

		// fila contenido
		var contenidoRow = document.createElement("tr");
		$(table).append(contenidoRow);

		var contenidoCell = document.createElement("td");
		$(contenidoCell).appendTo(contenidoRow);
		$(contenidoCell).addClass("pieDePagina");
		$(contenidoCell).css("width", "15%");

		var lista = document.createElement("ul");
		$(lista).css("list-style-type", "none");
		$(lista).css("padding", "0px");
		$(lista).css("margin", "0px");
		$(contenidoCell).append(lista);

		$(lista).append("<li>" + this._datosHome.piePagina.direccion + "</li>");
		$(lista).append("<li>" + this._datosHome.piePagina.codigoPostal + " " + this._datosHome.piePagina.localidad + "</li>");
		$(lista).append("<li>&nbsp;</li>");
		$(lista).append("<li>T " + this._datosHome.piePagina.telefonoFijo + "</li>");
		$(lista).append("<li>M " + this._datosHome.piePagina.telefonoMovil + "</li>");
		$(lista).append("<li>" + this._datosHome.piePagina.correo + "</li>");
		$(lista).append("<li>&reg;les quintanes, 2005</li>");

		var facebookLink = document.createElement("div");
		$(facebookLink).click(function() {
			window.open("http://www.facebook.com/pages/Espai-dart-les-Quintanes/189526144421665");
		});
		$(facebookLink).css("background-image", "url(img/icono_facebook.png)");
		$(facebookLink).css("background-repeat", "no-repeat");
		$(facebookLink).css("height", "25px");
		$(facebookLink).css("vertical-align", "middle");
		$(facebookLink).css("padding-left", "30px");
		$(facebookLink).css("padding-top", "7px");
		$(facebookLink).append("<span>Troba'ns al facebook</span>");
		$(facebookLink).css("cursor", "pointer");

		var facebookCell = document.createElement("td");
		$(facebookCell).addClass("pieDePagina");
		$(facebookCell).addClass("facebookCell");
		$(facebookCell).css("display", "none");
		$(facebookCell).append(facebookLink);
		$(contenidoRow).append(facebookCell);

		$(table).append("<tr><td colspan='2' class='pieDePagina'></td></tr>");

		$(table).append("<tr><td class='firma' colspan='2'>Disseny / Alba Vicente</td></tr>");

		$(table).find("td.pieDePagina:last").css("padding-bottom", "0px");
	};
	/* =======================
	 INICIALIZACION
	 ======================= */

	$("img#logo_cargando").load(function(){
		$("div#cargando").fadeIn("slow");
	});

	$.ajax({
		url : 'php/datosHome.php',
		dataType : "text",
		success : function(datos) {
			parent._datosHome = $.parseJSON(datos);
			parent._secuenciaImagenesFondo = parent._datosHome.fondos;
			parent.secuenciar_fondos(0);
		}
	});

}
