// JavaScript Document
		jQuery(document).ready(function(){
			
		   //MOVER THUMBS
			$(".contenedor").mousemove(function(e){
				var divWidth = $(this).width();
				var divHeight = $(this).height();
				var igW = $(".moveCont").width();
				var igH = $(".moveCont").height()+180;
				var dOs = $(this).offset();
				
				/*!
				 * Dual licensed under the MIT and GPL licenses:
				 *
				 * Agradesco a Gian Carlo Mingati por la formula para el paneo
				 * 
				 */
				
				var leftPan = (e.pageX - dOs.left) * (divWidth - igW) / (divWidth);
				var topPan = (e.pageY - (dOs.top+60)) * (divHeight - igH) / (divHeight);
				$(".moveCont").animate({ top: topPan}, {duration:200,queue:false});
			})    
			.mouseout(function(){$(".moveCont").stop();});
			
			RotationIMG();
		})
		
		
		// READ XML
		//$.get("gallery.xml", function (xml) {
		$.get("../../ambientesPortada.xml.php", function (xml) {
			
			$(xml).find("album").each(function () {
			   var lgPath = $(this).attr('lgPath');
			   var tnPath = $(this).attr('tnPath');
			   var id = $(this).attr('id');
			   //$('<div id="'+id+'"></div>').appendTo('#page-wrap');
			   var compara ="";
			   var numid=1;
			   $(xml).find("img").each(function () {
					
					var src = $(this).attr('src');
					var tn = $(this).attr('tn');
					var title = $(this).attr('title');
					var linkk = $(this).attr('link');
					var caption = $(this).attr('caption');
					
					if(compara != id){
						compara = id;
						$('<a href="'+linkk+'"><img id="Ilg" src="'+lgPath+src+'" alt="'+title+'" width="360" height="240"/></a>').appendTo(".imgLg");
						$("<strong class='formMensaje'>"+title+"</strong><br/><p style='color:#fff; font-size:12px;'>"+caption+"</p>").appendTo(".mensage");
						$(".mensage").attr('href',linkk);
						$(".mensage").animate({"top":"0"},{duration:700, queue:false});
						$(".bgMensaje").animate({"top":"0"},{duration:700, queue:false});
					}
					$('<li><a href="javascript:loadimg(\''+lgPath+src+'\',\''+title+'\',\''+caption+'\',\''+numid+'\')" id="id_'+numid+'"><img src="'+lgPath+tn+'" alt="'+title+'" /></a></li>').appendTo(".thumb");
					numid++;
			   });
			   
			});


			//OVER EN LOS THUMBS
			//Fancy Thumbnail Hover Effect
			//http://www.sohtanaka.com/web-design/fancy-thumbnail-hover-effect-w-jquery/
			
			$("ul.thumb li").hover(function() {
				$(this).css({'z-index' : '10'}); /*Add a higher z-index value so this image stays on top*/ 
					$(this).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
						.animate({
							marginTop: '-110px', /* The next 4 lines will vertically align this image */ 
							marginLeft: '-110px',
							top: '80%',
							left: '55%',
							width: '200px', /* Set new width */
							height: '150px'/*,  Set new height */
							/*padding: '5px'*/
					}, 200); /* this value of "200" is the speed of how fast/slow this hover animates */
			
				} , function() {
				$(this).css({'z-index' : '0'}); /* Set z-index back to 0 */
				$(this).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
					.animate({
						marginTop: '0px', /* Set alignment back to default */
						marginLeft: '0px',
						top: '0%',
						left: '0%',
						width: '171px', /* Set width back to default */
						height: '115px'/*,  Set height back to default */
						/*padding: '5px'*/
				}, 400);
			});
		});
		
		
		//REMPLAZAR IMAGENES	
		function loadimg(ruta,titulo,mensage,id){
			
			$(".mensage").animate({"top":"-40"},{
				duration:200,
				queue:false, 
				complete:function(){
					
					$("#Ilg").fadeOut("slow",function(){
						$(this).removeAttr('src').attr('src', ruta).fadeIn("slow",function(){
							$(".mensage").animate({"top":"0"},{duration:700, queue:false});
							$(".bgMensaje").animate({"top":"0"},{duration:700, queue:false});
						});
					});
					$(".mensage strong").html(titulo);
					$(".mensage p").html(mensage);
				}
			});
			$(".bgMensaje").animate({"top":"-40"},{duration:200, queue:false});
			
			if(id){
				//alert("true");
				clearInterval(valor);
				ID_S=id;
				RotationIMG();
			}
		}

		//ROTACION
		var ID_S=1;
		var valor;
		function RotationIMG(){
			
			var cadena = "";
			var cad1 = "";
			var variables;
			valor = setInterval(function() {
				
				if(ID_S == $('ul.thumb > li').length) {
					//clearInterval(valor);
					ID_S=1;
				}else{
					ID_S++;
				}
				
				cadena = $("#id_"+ID_S).attr("href");
				cad1 = cadena.replace("javascript:loadimg(", "");// "hxllx"
				cadena = cad1.replace(")","");
				cad1 = cadena.replace(/'/gi,"");
				variables = cad1.split(",");
				//alert(variables[0]+' : '+variables[1]+' : '+variables[2]);
				loadimg(variables[0],variables[1],variables[2]);
				
			}, 5000);
		}
		

