var wfg = new Array;

function oWFG(userid,flux,nbphotos) {
	this.userid = userid;
	this.flux = flux;
	this.nbphotos = nbphotos;
}

$(document).ready(function() {
	
	$.each(wfg, function(i,widget){
		if( typeof(widget)!='undefined' ) {
			
			if( widget.userid == null ) return;
			if( widget.nbphotos == null ) widget.nbphotos = 5;
			
			var fluxJson = "http://api.flickr.com/services/feeds/photos_faves.gne?nsid=" + widget.userid + "&lang=fr-fr&format=json&jsoncallback=?"
			if( widget.flux == "gal" ) {
					fluxJson = "http://api.flickr.com/services/feeds/photos_public.gne?id=" + widget.userid + "&lang=fr-fr&format=json&jsoncallback=?";
			}
				
			if( widget.flux == "fav" ) {
					fluxJson = "http://api.flickr.com/services/feeds/photos_faves.gne?nsid=" + widget.userid + "&lang=fr-fr&format=json&jsoncallback=?";
			}
			
			$.getJSON(fluxJson, function(data){
				
				var vWidth = $("#wflickrgallery-"+i).width();
				if( vWidth > 240 ) {
					$("#wflickrgallery-"+i).css("width","240px");
					vWidth = 240;
				}

				$.each(data.items, function(j,item){
					if(j < widget.nbphotos) { $("<img/>").attr("src", item.media.m)
						.attr("alt",item.title)
						.attr("width",vWidth)
						.appendTo("#wflickrgallery-"+i)
						.wrap("<div class=\"imgholder cWfg-"+i+"\"><a href=\"" + item.link + "\" title=\"" + item.title + "\" target=\"_blank\"></a></div>");
					} else {
						return false;
					}
				});
					
				// Set up the image container divs to collapse
				$(".cWfg-"+i).not(":first").css("height","25px");
				// Add the container mouseover event function
				$(".cWfg-"+i).mouseover(function(){
					// Make every image other than the one being mousedover small
					$(".cWfg-"+i).stop().not(this).animate({height:"25px"});
					// Make the currently active image big (set width to image width)
					$(this).animate({height:$(this).find("img").height()+"px"});
				});
			});
			
		}
	});

});	