var tortugo_selector =  
{
		//propiedades
		globalNumLink: 0,
		construido: 0,
		variables: new Array(),
		
		//metodos
		selectorMover: function(numLink)
		{
			if(this.globalNumLink!=numLink)
			{

				var oldActivo=$("#selectorIzquierdo .selectorActivo");
				var newActivo=$("#selectorLink"+numLink);
				oldActivo.removeClass("selectorActivo");
				oldActivo.addClass("selectorInactivo");
				newActivo.removeClass("selectorInactivo");
				newActivo.addClass("selectorActivo");
				this.globalNumLink=parseInt(numLink);
			}
		},
		selectorClick: function(numLink)
		{
			$('#selectorMedio').cycle(parseInt(numLink));
			return false;
		},
		selectorAbrir: function(numLink)
		{
			var data = this.variables[numLink];
			$("#contenedorNoticiasAJAX").html("<div class='ui-widget'><div class='ui-widget-header'><p>"+data.page.title+"<span style='float: right;'><a href='#cerrar' onclick='$(\"#contenedorNoticiasAJAX\").html(\"\"); return false;'><img src='publico/css/temas/iconos/cancel.png' border='0'/></a></span></p></div><div class='ui-widget-content' style='height: 200px; padding: 10px; text-align: left;'><img src='"+data.page.files.file[0].contents["@href"]+"?size=webview' align='left' style='height: 200px'/>"+data.page.summary.replace(/(<([^>]+)>)/ig,"")+"</div></div>");
		},
		selectorConstruir: function(numLink)
		{
			if(this.construido<5&&numLink<5)
			{
				//alert(tortugo_selectorConstruido+" | "+numLink);
				var hrefAPI=$("#selectorLink"+numLink+" p").attr("title")+"?dream.out.format=jsonp&dream.out.pre=?";
				//alert(hrefAPI);
				 $.getJSON(hrefAPI,
						 function(data)
						 {
					 		//PATH: data.page.path.removeAccents()
					 		//SUMARIO http://$API/pages/$ID/properties/urn%253acustom.mindtouch.com%2523sumario
					 		var img = (data.page.files.file.length) ? data.page.files.file[0] : data.page.files.file ;

							/*******************************/
					 		var nodoSelectorContenidoImagen = $("<div></div>").attr("class","selectorContenidoImagen")
										.append($("<img/>").attr("src",img["contents.preview"][1]["@href"])
											.attr("style","margin-top: 10px; width: 280px; heigth: 210px;")
											);
							/*******************************/

					 		var sumario = data.page.summary.replace(/(<([^>]+)>)/ig,"");
					 		for(var propiedad in data.page.properties.property)
					 		{
					 			//alert(propiedad);
					 			if(data.page.properties.property[propiedad]["@name"]=="urn:custom.mindtouch.com#sumario")
					 			{
					 				sumario = data.page.properties.property[propiedad].contents["#text"];
					 			}
					 		}

							/*******************************/
					 		var nodoSelectorContenidoTexto = $("<div></div>").attr("class","selectorContenidoTexto")
										.append($("<h2></h2>").attr("class","tituloNoticia")
											.append($("<a></a>").attr("href","Noticias/"+data.page["@id"])
												.html(data.page.title.replace(/(<([^>]+)>)/ig,""))
												)
											)
										.append("<hr/>")
										.append($("<p></p>").attr("class","cuerpoNoticia").html(sumario))
										.append("<hr/>");
							/*******************************/
					 		var nodoSelectorContenidoMeta = $("<div></div>").attr("class","selectorMeta")
										//.append($("<span></span>").html(debug_str))
										.append($("<button></button>")
											.attr("class","selectorAnterior ui-corner-left colorSecundario"))
										/*.append($("<button></button>")
											.attr("onclick","tortugo_selector.selectorAbrir("+numLink+");")
											.attr("class","selectorLeerMas colorPrincipal"))*/
										.append($("<button></button>")
											.attr("class","selectorSiguiente ui-corner-right colorSecundario"));

							/*******************************/
							var nodoPrincipal = $("<div></div>").attr("id","selectorContenido-"+numLink)
												.attr("class","selectorContenido")
												.append($(nodoSelectorContenidoImagen))
												.append($(nodoSelectorContenidoTexto))
												.append($(nodoSelectorContenidoMeta))
												;

							var selMedT = document.getElementById("selectorMedio");
							var selActT = "<div id='selectorContenido-"+numLink+"' class='selectorContenido' style='background-color: transparent;'>"+$(nodoPrincipal).html()+"</div>";
							selMedT.innerHTML+=selActT;
							/*******************************/

					 		tortugo_selector.variables.push(data);
					 		$("#selectorLink-"+numLink).attr("onclick","tortugo_selector.selectorClick("+numLink+")");
					 		tortugo_selector.selectorConstruir(++tortugo_selector.construido);
						});
			}
			else
			{
				$("#selectorMedio").cycle({ 
				    fx: 'fade',
				    //easeIn: 'easeInQuint',
				    //easeOut: 'easeOutQuint',
				    //speedIn: "fast",
				    timeout: 15000,
				    delay: -6000,
				    pause: 1,
				    prev: $(".selectorAnterior"),
				    next: $(".selectorSiguiente"),
				    before: function(){tortugo_selector.selectorMover(this.id.split("-")[1])}
				});
			}
		},
		start: function() 
		{
/*******************************/

/*
	if($.browser.msie)
	{
		alert("Usted usa un navegador no soportado por el Decreto 3390 para el uso prioritario del Software Libre.\nActualizate: ¡¡Usa Software Libre, usa Firefox!!");
		window.location="http://getfirefox.com/";
	}
*/
	var nodoSelector = $("<div></div>").attr("id","selector").attr("class","colorSecundario ui-corner-all");
	var nodoContenedor = $("<div></div>").attr("id","contenedorSelector");
	var nodoIzquierdo = $("<div></div>").attr("id","selectorIzquierdo");
//MODIFICAR AQUI//
	var nodoMedio = $("<div></div>").attr("id","selectorMedio").attr("class","ui-corner-all").attr("style","float: right; width: 660px; background-color: transparent;");

	var contenidoHTML = $("#selector2").html();

	$(nodoIzquierdo).append(contenidoHTML);
	$(nodoContenedor).append(nodoIzquierdo);
	$(nodoContenedor).append(nodoMedio);
	$(nodoSelector).append(nodoContenedor);
	$("#selector2").html(nodoSelector);
	$("#selector2css").remove();

/*******************************/

			var nuevoHTMLselectorIzquierdo="";
			var nuevoHTMLselectorIzquierdo=$("<div></div>");
			$("#selectorIzquierdo li").each(
				function(i,dom)
				{
					var imagen = $("img",this);
					var enlace = $("a",this);
					var className = (i!=0) ? "selectorLink" : "selectorLink selectorActivo";


					/**********C*O*N*S*T*R*U*Y*O***E*N*L*A*C*E*S**********/
					var nodoElemento = $("<div></div>")
								.attr("id","selectorLink"+i)
								.attr("style","height: 60px;")
								.attr("class",className)
								.click(function(obj){
										var tmp_idStr = new String(this.id);
										tortugo_selector.selectorClick(tmp_idStr.charAt(tmp_idStr.length-1));
									});
					var nodoElementoImg = $("<img/>")
								.attr("src",imagen.attr("src"))
								.attr("style","margin-top: 5px; width: 70px; height: 50px;")
								.attr("class","selectorFotico ui-corner-all");

					var nodoElementoP = $("<p></p>")
								.attr("class","selectorFoticoTitulo")
								.attr("title",enlace.attr("rel"))
								//.append($("<a></a>").attr("href",enlace.attr("id")))
								.text(enlace.text());
					//alert($(nodoElementoP).html());
					//alert($(nodoElementoP).attr("title"));

					nodoElemento.append(nodoElementoImg);
					nodoElemento.append(nodoElementoP);

					nuevoHTMLselectorIzquierdo.append(nodoElemento);
				}
			);
			$("#selectorIzquierdo ul").after(nuevoHTMLselectorIzquierdo).remove();
			this.selectorConstruir(0);
		}
}

