/*
	picasaViewer v1.0 - mooTools script to embed a picasa gallery in your website
	Lennart Pilon (http://pilon.nl)	
*/
/*
window.addEvent('domready', function() {*/

function view(aId) {									 

	var username	= 'conundrumgirl';

	/*
	The following values are valid for the thumbsize and imgmax query parameters and are embeddable on a webpage. 
	These images are available as both cropped(c) and uncropped(u) sizes by appending c or u to the size. As an 
	example, to retrieve a 72 pixel image that is cropped, you would specify 72c, while to retrieve the uncropped 
	image, you would specify 72u for the thumbsize or imgmax query parameter values.

	32, 48, 64, 72, 144, 160
	*/
	var thumbsize	= '72c';
	
	/*
	The following values are valid for the thumbsize and imgmax query parameters and are embeddable on a webpage. 
	These images are available as only uncropped(u) sizes by appending u to the size or just passing the size 
	value without appending anything.

	200, 288, 320, 400, 512, 576, 640, 720, 800

	*/
	var imgmax = '800';

	/*var url = (albumId != null) ? 'http://picasaweb.google.com/data/feed/base/user/'+ username +'/albumid/'+ albumId +'?category=photo&alt=json&callback=viewPhotoList&thumbsize=' + thumbsize +'&imgmax='+imgmax : 'http://picasaweb.google.com/data/feed/base/user/' + username + '?category=album&alt=json&callback=viewAlbumList&access=public&thumbsize=' + thumbsize;*/
	var albumId= aId;
var url = "";
if  (albumId != null)
{
		thumbsize = '64c';
url = 'http://picasaweb.google.com/data/feed/api/user/' + username + '/albumid/'+ albumId +'?category=photo&alt=json&access=public&thumbsize=' + thumbsize+'&imgmax='+imgmax+'&callback=?';

	viewPhotoList (url);
}

else
{

url = 'http://picasaweb.google.com/data/feed/api/user/' + username + '?category=album&alt=json&access=public&thumbsize=' + thumbsize+'&callback=?';

	viewAlbumList (url);
}


}


function viewAlbumList(url) {
		$("#albums").empty();
	$.getJSON(url, function(list){

		href  = list.feed.author[0].uri.$t;
		user = list.feed.author[0].name.$t;
	
		//$('navigate').adopt(new Element('a', {'href': href, 'html': 'To Picasa', 'title': 'View '+user+'\'s gallery at Picasa', 'class': 'picasalink'}));

		//jQuery(" <div />" ).attr( "id", "wrapper-header").addClass( "header" ).html( "hello world").appendTo( jQuery( "#albums" ) );

		//$(document.createElement("a")).attr("href", href).text('To Picasa').attr('title','View '+user+'\'s gallery at Picasa').addClass('picasalink').appendTo("#albums"); 
		  var picsCount = list.feed.entry.length ;   
		for (var i = 0; i < picsCount ; i++)  {
			 var item = list.feed.entry[i]; 						  
		var title	= item.title.$t;
	
		var thumb	= item.media$group.media$thumbnail[0].url;
	
		id_begin	= item.id.$t.indexOf('albumid/')+8;
		
		id_end		= item.id.$t.indexOf('?');
		var id		= item.id.$t.slice(id_begin, id_end);
	//	var href	= Browser.setQueryStringValues({'albumid': id});
		d			= item.published.$t;
		var date	= d.substr(8,2) + '-' + d.substr(5,2) + '-' + d.substr(0,4);
		
		var div = $(" <div />" ).addClass("image-container");


		var a = $("<a/>").attr('title',title); 
		a.attr("href", "javascript:view('"+id +"')");
		//a.bind("click", function(e){ view(id);});
		var img = $("<img/>").attr("src",thumb).attr("alt",title).appendTo(a);
		var p = $("<p/>").text(title).appendTo(a);
		var pdt = $("<p/>").text(date).addClass("date").appendTo(a); 
		a.appendTo(div);
		div.appendTo("#albums") ;
		} 
	
	});
}

function viewPhotoList(url) {
	$("#pictures").empty();
 $.getJSON(url, function(list){
	var album = list.feed.title.$t;
//	var href  = Browser.setQueryStringValues({'albumid': ''});

	//$('navigate').adopt(new Element('a', {'href': href, 'html': 'Back to the album list', 'class': 'backlink'}), new Element('h2', {'html': album}));
	
	
								  
	 var picsCount = list.feed.entry.length ;   
		for (var i = 0; i < picsCount ; i++)  {
			 var item = list.feed.entry[i]; 											  
								  

		var title	= item.title.$t;
		var link	= item.media$group.media$content[0].url;
		var size		= item.media$group.media$content[0].width;
		var thumb	= item.media$group.media$thumbnail[0].url;
		
		id_begin	= item.id.$t.indexOf('albumid/')+8;
		id_end		= item.id.$t.indexOf('?');
		var id		= item.id.$t.slice(id_begin, id_end);
		
	//	$('photos').adopt(new Element('a', {'href': link, 'title': title, 'class': 'lightbox', 'rel': 'lightbox-album'}).adopt(new Element('img', {'src': thumb, 'alt': title})));
		
		 var a = $("<a/>").attr("href", link).attr('title',title).attr('size', size).addClass("preview"); 
	
		  var img = $("<img/>").attr("src",thumb).attr("alt",title).appendTo(a);
		a.appendTo("#pictures");
		  }
		  
		/*$.fn.jScrollPane.defaults.showArrows = true;
$.fn.jScrollPane.defaults.reinitialiseOnImageLoad = true;
$("#pictures").jScrollPane(); */

/*tb_init('a.thickbox, area.thickbox, input.thickbox');
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;*/
imagePreview();
	});

	/*$$("a").filter(function(el) {
		return el.href && el.firstChild && el.firstChild.src;
	}).slimbox({}, function(el) {	
		return [el.href, (el.title || el.firstChild.alt) + '<br /><a href="../picasa/js/' + el.href + '">Album: '+ album +' </a>'];
	});*/
	



	
}





function imagePreview()
{
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		alert (e);
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
}
