/* script by frederic Le guluche emencia fred@emencia.com*/
/**
 * --------------------------------------------------------------------
 * jQuery-Plugin 
 * Version beta, 09.03.2010
 * by Frederic Le guluche, frederic.leguluche@gmail.com

 *
 * 
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * 
 * --------------------------------------------------------------------
 * Zwook module with patch 
 * --------------------------------------------------------------------
 */

function resizeCont () {
 $('table.tabletop').height($(window).height()-160);;
 $('table.tabletop').width($(window).width()-40);;
$('#collection_viewer').width($(window).width()-40);
$('#collection_viewer').height($(window).height()-40);

 $('.album_jq ').css('top',function() {
  return $(window).height() * 0.75;
})
 
var rapport =1.5;
var rapport2 =0.667;
var rapportWindow =$(window).width()/$(window).height();

$('#collection_viewer').height($(window).height()-40);

if (rapportWindow > rapport) {
	$('#collection_viewer img').width($(window).width()-40);
	$('#collection_viewer img').css('margin-left', '0');
	$('#collection_viewer img').css('position', 'relative');
	$('#collection_viewer img').css('left','0');
	$('#collection_viewer img').height(($(window).width()-40)/rapport);
	var scollImg = -($('#collection_viewer img').height()-$(window).height()+40 )/2+"px";
	$('#collection_viewer img').css('top', scollImg);
} else {
	$('#collection_viewer img').height($(window).height()-40);;

	$('#collection_viewer img').width($('#collection_viewer img').height()*rapport);
	$('#collection_viewer img').css('margin-left',(($('#collection_viewer img').width()-40)/-2));
	$('#collection_viewer img').css('left', '50%');
	$('#collection_viewer img').css('position', 'relative');
	$('#collection_viewer img').css('top', '0px');
	
}

}
$(window).resize(function(){resizeCont (); return false });

//////////   album jquery/////////////////////
$(document).ready( function () {
/*** specifique a zwook -- replace le tableau generale en  index maximum***/
 $('table').eq(0).css('z-index', '50');
 $('table').eq(0).addClass('tabletop');
 
 
 
resizeCont ();

/***album***/
 
jQuery.preloadImages = function(argument,lien)
{
argument = new Image();
argument.src = ""+lien+"";

}		 
// when the DOM is ready
jQuery.preloadbkg=function (src_img) {
  var img = new Image();
  $('#collection_viewer')
	.addClass('loading')
	.empty();
  // wrap our new image in jQuery, then:
  $(img).load(function () {
      // set the image hidden by default    
      $(this).hide();
    
      // with the holding div #collection_viewer, apply:
      $('#collection_viewer')
        // remove the loading class (so no background spinner), 
        .removeClass('loading')
        // then insert our image
        .append(this);
		resizeCont ()
      // fade our image in to create a nice effect
	  
      $(this).fadeIn();
    })
    
    // if there was an error loading the image, react accordingly
   $(img).error(function () {
      // notify the user that the image could not be loaded
    })
    
    // *finally*, set the src attribute of the new image to our image
    $(img).attr('src',src_img);
  
};


var img_viewer_array =[]

												 
					
					
if ($("#f_album_id  a").length != 0) {			 
		  var imgviewer=$("#f_album_id  table tbody tr td a").attr("href");
		  var infoviewer='<div>'+$("#f_album_id a").attr("title")+'</div>';
		  var i_thumb=0;
			$("#f_album_id  a.thumbcol").each(function() {
				if (i_thumb!=0) {
					$(this).fadeTo("fast", 0.2);
					};
				i_thumb=i_thumb+1;
			
			} )
			
		   $("#collection_viewer img").fadeOut("slow", function() {
				$(" #info .subInfo").empty()
				$(" #info .subInfo").append( infoviewer );
				$.preloadbkg(imgviewer );
		   $("#collection_viewer img").fadeIn("fast", function() {});
			});
	

} else {			$.preloadbkg("image_locale.jpg" );
};
 // On cible les thumbmail de collection :
$("a.thumbcol").click( function () {
      var imgviewer=$(this).attr("href");
      var infoviewer='<div>'+$(this).attr("title")+'</div>';
      var thumb_encours=$(this);
       $("#collection_viewer img").fadeOut("slow", function() {
            $(" #info .subInfo").empty()
            $(" #info .subInfo").append( infoviewer );
			$.preloadbkg(imgviewer );
			$("#f_album_id  a.thumbcol").each(function() {
					$(this).fadeTo("fast", 0.2);				thumb_encours.fadeTo("fast", 1);
				} )
			$("#collection_viewer img").fadeIn("fast", function() {
			});
					
      		
        });

        return false;
    }); 

    // On cache les info :
$('div#info').removeClass('beandselected');
   //$(".panneau div.subInfo").hide();
    $(".panneau div.subInfo").attr("vue", "no");
    // On modifie l'évènement "click" 
    // qui portent la classe "toggleSubMenu" :
$("a#more_info").click( function () {

		bouton=$(this);
		$('div#info').addClass('beandselected');
        // Si les infos étaient déjà ouvert, on le referme :
		($(this).attr("onblure")=="") 
        if ($(".panneau div.subInfo").attr("vue")=="no") {
		    $(".panneau div.subInfo").attr("vue", "yes");
					var action="Masquer <strong>-</strong>";
					$(this).empty()
					$(this).append(action);
                	$(this).removeClass('panselected');
			$('div#info').removeClass('beandselected');
			inf_top=$('div#info').height()+"px"
$('div#info').animate({"bottom":"100px"}, 600);


			$("div#info").fadeTo("fast", 0.92);
        }
        // Si le sous-menu est caché, on ferme les autres et on l'affiche :
        else {
    $(".panneau div.subInfo").attr("vue", "no");
					var action=" En savoir  <strong>+</strong>";
					$(this).empty()
					$(this).append(action);
                $(this).addClass('panselected');
		$('div#info').addClass('beandselected');
$('div#info').animate({"bottom":"20px"}, 600);
					$("div#info").fadeTo("fast", 0.92);
        }
        // On empêche le navigateur de suivre le lien :
        return false;
    });   
	
$("div.panneau").hover( function (){



			$("div#info").fadeTo("fast", 0.92);

},function (){


				$("div#info").fadeTo("fast", 0.2);

})
$("#f_album_id  a.thumbcol").each(function(i) {
$.preloadImages( i,$(this).attr("href"));
} )
});

