$(function() {
	var fr={theme: 'light_square', showTitle:false, padding: 20, counter_separator_label:' de '};
	$("a[rel^='prettyPhoto']").prettyPhoto(fr);
	var itag = $('td.nouveau>a[rel]>img');
	
	itag.each(function(i,val){
		idx.push(i);
		container.push($(this).parent());
		imgs.push($(this).attr('src'));
		var ww=$(this).attr('width');
		w.push(ww);
		//alert(w);
		//w.push(ww==0?150:ww);
		var hh = $(this).attr('height');
		h.push(hh);
		$(this).parent().parent().css({"height":hh+($.browser.msie?26 : 22)});
		
	});
	itag.show();
	itag.css({'visibility':'visible'});
	itag.parent().hide();
	itag.parent().parent().addClass('loaderimg');
	itag.parent().parent().css({'width':'33%'});
	
	
	itag.removeAttr('src');
	idx.reverse();
	initImage(0);
	$('td.nouveau').not(":has(a)").not(":has(img)").removeClass('nouveau');
	
});
/*
$(function() {
	var fr={theme: 'light_square', showTitle:false, padding: 20, counter_separator_label:' de '};
	$("a[rel^='prettyPhoto']").prettyPhoto(fr);
	var itag = $('td.nouveau>a[rel]>img');
	itag.show();
	itag.css({'visibility':'visible'});
	itag.parent().hide();
	itag.parent().parent().addClass('loaderimg');
	itag.parent().parent().css({'width':'33%'});
	itag.each(function(i,val){
		idx.push(i);
		container.push($(this).parent());
		imgs.push($(this).attr('src'));
		var ww=$(this).attr('width');
		
		w.push(ww==0?150:ww);
		var hh = $(this).attr('height');
		h.push(hh);
		$(this).parent().parent().css({"height":hh+($.browser.msie?26 : 22)});
		
	});
	
	itag.removeAttr('src');
	idx.reverse();
	initImage(0);
	$('td.nouveau').not(":has(a)").not(":has(img)").removeClass('nouveau');
	
});

*/
var idx = new Array();
var container =new Array();
var imgs = new Array();
var w = new Array();
var h = new Array();

function over(event){
	$(this).addClass('hover');
	$(this).bind('click',
				 function(){ 
				 	$(this).find("a").trigger('click');
				 });
}
function out(event){
	$(this).removeClass('hover');
}

function initImage(x){
	if(x<imgs.length){
		//var r=Math.random()*1000;
		var objImagePreloader = new Image();
		container[x].children().attr('id','img_'+x);
		container[x].children().attr('width',w[x]);
		container[x].children().attr('height',h[x]);
		
		//Image.onload has to be set before Image.src
		objImagePreloader.onload = function() {
			idx.pop();
			document.getElementById("img_"+x).src=imgs[x];
			container[x].parent().removeClass('loaderimg');
			// Perfomance an effect in the image container resizing it
			container[x].fadeIn('slow');
			container[x].parent().hover(over,out);
			var t = window.setTimeout("initImage("+(x+1)+");",50);
			//	clear onLoad, IE behaves irratically with animated gifs otherwise
			objImagePreloader.onload=function(){};
		};
		objImagePreloader.src = imgs[x];
	}else{
		return false;
	}
}
window.onload=function(){
	if($.browser.opera){
		//$('body').append('<div>Opera detected, '+idx.toString()+' was not showed</div>');
		//$('td.nouveau>a[rel]').parent().removeClass('loaderimg');
		//$('td.nouveau>a[rel]').parent().hover(over,out);
		//$('td.nouveau>a[rel]').fadeIn('slow');
		window.setTimeout("refreshThumb("+idx.pop()+");",250);
		//refreshThumb(idx.pop());
	}
}
function refreshThumb(i){
	if(isNaN(i)){
		return false;
	}
	//$('body').append('<div>'+imgs[i]+' Refreshed</div>');
	container[i].parent().removeClass('loaderimg');
	container[i].parent().hover(over,out);
	container[i].fadeIn('slow');
	//container[i].fadeIn('slow',refreshThumb(idx.pop()));
	window.setTimeout("refreshThumb("+idx.pop()+");",250);
}
document.writeln('<style type="text/css">');
document.writeln('<!--');
document.writeln('td.nouveau>a>img {visibility:hidden;}');
document.writeln('-->');
document.writeln('</style>');
