$(document).ready(function() {

	$(".visorimag").bind("mouseenter", function(){
   	
			if (!$(this).data("py")) {
	   			var py = ($("#visormarco").height() + 50 - $("#visorgrande").height()) / $(".visorimag").size();
	   			py = $("#visormarco").position().top + (py * $(".visorimag").index($(this)));          
	   			$(this).data("py", py)
			}
			if (!$("#visorgrande").data("px")) {
   			    var px = $(this).css('position','relative').position().left;
   			    var pxini = px - 471;
				$("#visorgrande").css('position','absolute').css("left", px);   
			    $("#visorgrande").data("pxini", pxini);
			    $("#visorgrande").data("px", px);
			}
			$("#visorgrande").stop();            
  		    $("#visorgrande #im2").attr("src", $(this).children("img").attr("src"));
			$("#visorgrande #im2:hidden").show().parent().css("top", $(this).data("py"));
			var indice  = $(".visorimag").index($(this));
			$("#visorgrande #im3 #visortit").text(v_t[indice][0]);
			$("#visorgrande #im3 #visortxt").html(v_t[indice][1]);
			$("#visorgrande #im3 #visoraref").data("url", v_t[indice][2]);
			$("#visorgrande #im3:hidden").show();
			$("#visorgrande").animate({left: $("#visorgrande").data("pxini"), width:441, top:$(this).data("py")}, 'medium');
            
			$("#" + $(this).attr("id").substr(3)).css('position','relative')
			.animate({left:-30,	width: 0},'fast',function() {
				$(".visorim:hidden:not([id='" + $(this).attr("id") + "'])").each(function() {
					$(this).show();
					$(this).css('position','relative').animate({left:  0,width: 134},'fast');}); 
				$(this).hide();
			});
		});
		
   $(window).resize(function() {
   			$("#visorgrande").removeData("px")
   			$("#visorgrande").removeData("pxini")
   		});
   
   $("#visormarco").bind("mouseleave", function(){
   	        $(this).data("tiempo",setTimeout("ocultacion()", 200));
   	  });

   $("#visormarco").bind("mouseenter", function(){
   			if ($(this).data("tiempo")) {
   	        	clearTimeout($(this).data("tiempo"));
	   	        $(this).removeData("tiempo");
   			}
		});
		
   $("#visorgrande").bind("mouseenter", function(){
   	        clearTimeout($("#visormarco").data("tiempo"));
   	        $("#visormarco").removeData("tiempo");
   	        $(this).stop();
			$(this).children("#im2").show();
			
			$(this).animate({left:$(this).data("pxini"), width:441}, 'medium', function() {
				$(this).children("#im3").show();
			});
		});

   $("#visoramas").bind("click",
   			function(){
	   			if ($(this).parent().height() < 100) {	
					$(this).parent().animate({top:-160,height:160}, 'medium', function() {
	   			    	    	$(this).children("#visoramas").text(cerrar)
						        $(this).children("#visortxt").show();
						        $(this).children("#visoraref").show();
	   			    	    	;})
				} else {
					$(this).parent().animate({top:-28,height:28}, 'medium', function() {
						        $(this).children("#visortxt").hide();
						        $(this).children("#visoraref").hide();
	  				        	$(this).children("#visoramas").text(mas);})
	   	    	}
	   		}
		);
		
   $("#visorgrande").bind("mouseleave", function(event){
   	        $("#visormarco").data("tiempo",setTimeout("ocultacion()", 200));
		});
		
   $("#visoraref").bind("click", function() {
   		window.location.replace($(this).data("url"));
   });
		
		
});


function ocultacion( ) {
	
    $("#visormarco").removeData("tiempo");
    $("#visorgrande").children("#im3").animate({top:-28,height:28}, 'medium', function() {
  			        	$(this).children("#visoramas").text(mas);
					});
	$("#visorgrande").animate({left:$("#visorgrande").data("px"), width:0}, 'medium', function() {$("#visorgrande #im2").hide();$("#visorgrande #im3").hide();});
	$(".visorim:hidden").add($(".visorim:animated"))
		.each(function() {
			$(this).show();
			$(this).css('position','relative').animate({left:  0,width: 134},'fast'
		  )
			;});
}