// JavaScript Document
jQuery(function($){ 
 
  var settings = { 
    thumbListId: "thumbsap", 
    imgViewerId: "viewerap", 
    activeClass: "active", 
    activeTitle: "Photo en cours de visualisation", 
    loaderTitle: "Chargement en cours", 
    loaderImage: "img/loader.gif" ,
	sizeHeight: "425px",
	sizeWidth: "566px",
	sizeW: 566
  }; 
 
  var thumbLinks = $("#"+settings.thumbListId).find("a"), 
    firstThumbLink = thumbLinks.eq(0), 
    highlight = function(elt){ 
      thumbLinks.removeClass(settings.activeClass).removeAttr("title"); 
      elt.addClass(settings.activeClass).attr("title",settings.activeTitle); 
    }, 
    loader = $(document.createElement("img")).attr({ 
      alt: settings.loaderTitle, 
      title: settings.loaderTitle, 
	  width: 566,
		height: 425,
		src: settings.loaderImage
    }); 
 
  highlight(firstThumbLink); 
 
  $("#"+settings.thumbListId).after( 
    $(document.createElement("p")) 
      .attr("id",settings.imgViewerId) 
      .append( 
        $(document.createElement("img")).attr({ 
          alt: "x", 
          src: firstThumbLink.attr("href"),
		 width: settings.sizeW
		  ,
		  height: 425
        }) 
      ) 
  ); 
 
  var imgViewer = $("#"+settings.imgViewerId), 
    bigPic = imgViewer.children("img"); 
 
  thumbLinks 
    .click(function(e){ 
      e.preventDefault(); 
      var $this = $(this), 
        target = $this.attr("href"); 
      if (bigPic.attr("src") == target) return; 
      highlight($this); 
      imgViewer.html(loader); 
      bigPic 
        .load(function(){ 
         //imgViewer.html($(this).attr({width:566,height:425}).fadeIn(250)); 
		   imgViewer.html($(this).attr({width:566}).fadeIn(250)); 
        //imgViewer.html($(this).fadeIn(250)); 
		if(bigPic.height()>bigPic.width())var formeimg = "Vert";
		if(bigPic.height()<bigPic.width())var formeimg = "Hori";
		//$("#viewerap").resizable();
		//alert(formeimg);

		//alert(($(document.createElement("img")).attr({ src: bigPic.attr('src')})).width);
		 //alert(firstThumbLink.attr("href").width +" "+ bigPic.height());
		}) 
       .attr("src",target);
	   //.after(bigPic.attr({src:target,width:566,height:425}));
	   
	   //bigPic.attr({src:target,width:566,height:425});
	   //.attr({src:target,alt:"Y",width:"120px"});
    }); 
 
});
