/*
 * jquery-gallery 0.2 (25-11-2007)
 *
 * Copyright (c) 2007 Queli Coto (http://www.noth.es)
 * Lincencia bajo CC
 * Built upon jQuery 1.2 (http://jquery.com)
 */
$(document).ready(function test(){
								
	crearGaleria();							
//alert( document.getElementById("fadeimg").height);
    var ht = document.getElementById("fadeimg").height;
		  var wd = document.getElementById("fadeimg").width;
		    var contheight=document.getElementById("fadeimg").height;
		  var contwidth =document.getElementById("fadeimg").width;
		  
		  
		    document.getElementById("itemloading").style.height=contheight+'px' ;
			// alert(  document.getElementById("itemloading").style.height);
		document.getElementById("itemloading").style.width=contwidth+'px'  ;
		
		    document.getElementById("sdImg2").style.height=(ht)-13;
		  document.getElementById("sdImg1").style.width=(wd)-11;
});

$(document).ready(crearGaleria);

function crearGaleria ()
{
	//cargamos el title y la descripcion de la primera imagen
	//var title = $(".slideShowGallery dt img").attr('title');
	//conseguimos el ancho y la altura de nuestra galer?ia
	//var height = $(".slideShowGallery dt img").height();
	//var width = $(".slideShowGallery dt img").width();
	//$(".slideShowGallery dt").css({ width: width-10, height: height });
	//var descripcion = $(".slideShowGallery dt img").attr('alt');
	
  	$(".slideShowGallery dt p").hide();
  	$(".slideShowGallery dt p").fadeIn('fast');
  	
	//inicializamos los click en las imagenes
	$(".slideShowGallery ul li td a img").click( function() { 
		var urlImagen =$(this).parent().attr('href');
		ocultarFoto(urlImagen);
		return false; //cancelamos el click en el a 
	} );
}

function ocultarFoto(url)
{
      
	if($(".slideShowGallery dt img").attr('src') != url )
	{
	   $(".slideShowGallery dt p").fadeOut();
	   
	 
	//alert(itemheight);
	

       $(".slideShowGallery dt img").animate({ 
										 
		  left: 50, opacity: 'hide' 
		}, 500, function() {
			     //  var itemheight=$(".slideShowGallery dt img").attr('height')+'px';
			  //	
			  var i = new Image();				
	       
			// alert( document.getElementById("fadeimg").height);
		
			  i.onload =  function() { 
			
			   $(".slideShowGallery dt img").attr('src',url);    
	   //alert(url);

		document.getElementById("sdImg2").style.height=(i.height)-13+'px';
		document.getElementById("sdImg1").style.width=(i.width)-11+'px';

		document.getElementById("itemloading").style.height=i.height+'px';
		document.getElementById("itemloading").style.width=i.width+'px';
    	      $(".slideShowGallery dt img").animate({ 
				  left: 50, opacity: 'show' , src : url
	 		  }, 500,function() {
		
		  	$(".slideShowGallery dt p").hide();
		
			//document.getElementById("itemloading").style.height="auto" ;
			//document.getElementById("itemloading").style.height="auto" ;
		  	$(".slideShowGallery dt p").fadeIn('fast');
		  	$(".slideShowGallery dt p").css('opacity',0.6);
			 
			 });
		  };
		
		 i.src = url;	
		 //alert(url);
		 
      }); 
	}
}

$.fn.image = function(src, f){
    return this.each(function(){
        var i = new Image();
        i.src = src;
        i.onload = f;
		
        this.appendChild(i);
    });
 }

