//Carrega todos os albuns do usuario informado no Picasa, retornando a primeira foto de cada no tamanho informado.
function CarregaAlbunsPicasa(idusuario, tamanho, divAlbuns, showLinks){
	//32, 48, 64, 72, 104, 144, 150, 160 - cropped sizes
	//94, 110, 128, 200, 220, 288, 320, 400, 512, 576, 640, 720, 800, 912, 1024, 1152, 1280, 1440, 1600 - uncropped sizes
		
	$.getJSON('http://picasaweb.google.com/data/feed/api/user/' + idusuario + '?kind=album&access=visible&alt=json-in-script&thumbsize=' + tamanho + '&callback=?', function(data){
		
		$.each(data.feed.entry,function(i,item){
				
			//item.gphoto$id.$t - ID do Album
			//item.gphoto$name.$t - Nome do Álbum (URL)
			//item.media$group.media$title.$t - Nome do Álbum (amigável)
			//item.media$group.media$description.$t - Descrição do Álbum
			//item.media$group.media$thumbnail[0].url - Primeira foto do album
			//item.content.src - foto original
			//item.gphoto$numphotos.$t - número de fotos do album
			//item.link[1].href - link do álbum
			
			conteudo = "";
			
			if (showLinks==true){
				conteudo = "<a href='#' onClick=\"CarregaAlbum('" + item.media$group.media$title.$t + "');return false;\">";
			}
			
			conteudo = conteudo + "<img src='" + item.media$group.media$thumbnail[0].url + "' alt='" + item.media$group.media$description.$t + "' title='" + item.media$group.media$description.$t + "' border='0'>";
			
			if (showLinks==true){
				conteudo = conteudo + "</a>";
			}
	
			$(divAlbuns).append(conteudo);
			
		});
			
	});
};

function CarregaAlbumPicasa(idusuario, tamanho, divAlbuns, linksType, nome_album, showAll, showMode, callback_, photodescription_){

	//linksType (no valid with showMode = 2)
	// 1 - to album
	// 2 - to photo in album
	// 3 - to original foto
	// 4 - no links
	
	//showMode 
	// 1 - img content
	// 2 - css background (only valid with ShowAll = false)
	// 3 - img in a LI content

	
	$.getJSON('http://picasaweb.google.com/data/feed/api/user/' + idusuario + '?kind=album&access=visible&alt=json-in-script&thumbsize=' + tamanho + '&callback=?', function(data){
		$.each(data.feed.entry,function(i,item){
			
				if (item.media$group.media$title.$t==nome_album){
					
					$.getJSON('http://picasaweb.google.com/data/feed/api/user/' + idusuario + '/albumid/' + item.gphoto$id.$t + '?kind=photo&access=visible&alt=json-in-script&thumbsize=' + tamanho + '&callback=?', function(data){
												
						if (showAll==true){
							$.each(data.feed.entry,function(i,item){

								conteudo = "";
								
								if (showMode==3){
									conteudo = conteudo + "<li>";
								}
									
								switch (linksType){
									case 1: // 1 - to album
										conteudo = conteudo + "<a href='" + item.link[1].href.replace('#' + item.gphoto$id.$t,'') + "' target='_blank'>";
										break;
									case 2:	 // 2 - to photo in album
										conteudo = conteudo + "<a href='" + item.link[1].href + "' target='_blank'>";
										break;	
									case 3:	 // 3 - to original foto
										conteudo = conteudo + "<a href='" + item.content.src + "' target='_blank'>";
										break;								
								}
								
								conteudo = conteudo + "<img src='" + item.media$group.media$thumbnail[0].url + "' alt='" + item.media$group.media$description.$t + "' title='" + item.media$group.media$description.$t + "' border='0'>";
								
								if (linksType==1 || linksType==2 || linksType==3){
									conteudo = conteudo + "</a>";
								}
								
								if (showMode==3){
									conteudo = conteudo + "</li>";
								}
								
								$(divAlbuns).append(conteudo);
							});
						}else{
							
							$.each(data.feed.entry,function(i,item){
							
								Exibe_ = false;
							
								if (photodescription_!=""){
									if (item.media$group.media$description.$t==photodescription_){
										Exibe_ = true;
									}
								}else{
									if (i==0){
										Exibe_ = true;
									}
								}
							
								if (Exibe_==true){
							
									if (showMode==1 || showMode==3){ //img content
										
										conteudo = "";

										if (showMode==3){
											conteudo = conteudo + "<li>";
										}

										switch (linksType){
											case 1: // 1 - to album
												conteudo = conteudo + "<a href='" + item.link[1].href.replace('#' + item.gphoto$id.$t,'') + "' target='_blank'>";
												break;
											case 2:	 // 2 - to photo in album
												conteudo = conteudo + "<a href='" + item.link[1].href + "' target='_blank'>";
												break;	
											case 3:	 // 3 - to original foto
												conteudo = conteudo + "<a href='" + item.content.src + "' target='_blank'>";
												break;								
										}
			
			
										conteudo = conteudo + "<img src='" + item.media$group.media$thumbnail[0].url + "' alt='" + item.media$group.media$description.$t + "' title='" + item.media$group.media$description.$t + "' border='0'>";
										
										if (linksType==1 || linksType==2 || linksType==3){
											conteudo = conteudo + "</a>";
										}
												
										if (showMode==3){
											conteudo = conteudo + "</li>";
										}
																	
										$(divAlbuns).append(conteudo);
										
									}else{ //css background
										$(divAlbuns).css("background-image", "url(" + item.media$group.media$thumbnail[0].url + ")");
									}
									

								}
							});

						}
						
						if (typeof callback_ == "function"){
							callback_(); 
						}
						
					});
					
				}
			});
		});
	}


