	var interval 	= 5;
	var loadRow 	= 0;
/*	var username 	= "TonyGeester";*/
	var username 	= "wincy08";
	var thumbWidth	= 110;
	var imgWidth	= 800;
	initial			= "yes";

$j(document).ready(function(){

	constructLinks();
	
	clearOut();
	$j("#prev").hide();
	$j("#next").hide();

/*	constructLinks() */
	
	$j("ul.kwicks li").bind("click",function(e) 
			{		
/*				clearOut(); */
				var nameValue = $j(this).attr("name");
				showAlbum(nameValue);
			});

	
	function clearOut() {
			$j("#gallery li").fadeOut("fast");
			$j("#gallery li a").attr("href","#").removeClass("hor").removeClass("vert");
			$j("#gallery li a img").attr("src","images/blankass.gif");
			}
		  
	function constructLinks() {
			for (j=1; j<=interval; j++) {
			$j("ul#gallery").append("<li><a class=\"thickbox\"><img id=\"box"+j+"\" src=\"\"></img></a></li>");
				}
			}

			
	//showAlbum
	
	function showAlbum(albumID) {
//			clearOut();
			$j("#prev").hide();
			$j("#next").hide();
		 	loadRow = 0;
    		$j.getJSON("http://picasaweb.google.com/data/feed/api/user/"+username+"/albumid/"+albumID+"?kind=photo&alt=json-in-script&callback=?",
        	function(data)
        		{
      				feed = data.feed;
					entries = feed.entry || [];
					loadPix(loadRow);
          		});
          	}
		  
			
		function nextClick() {
				loadRow = loadRow+interval;
				clearOut();
				if(loadRow+interval >= entries.length) {$j(this).hide();}
				loadPix(loadRow);
				}
		
			  
		function prevClick() {
				loadRow = loadRow-interval;
				clearOut();
				if(loadRow==0) {$j(this).hide();}
				loadPix(loadRow);
			}
		
	
			
		function loadPix(startPic) {

			// Clear the dimensions of the picture links . . . 
				$j("#gallery li a.hor").removeClass("hor");
				$j("#gallery li a.vert").removeClass("vert");
				
				
				if(startPic>0) {
					$j("#prev").show("fast",function(){$j(this).click(prevClick);});
				}
				
				if((startPic+interval)<entries.length) {
					$j("#next").show("fast",function(){$j(this).click(nextClick);});
				}


				if (startPic+interval-1 >= entries.length) {
					lastPic = entries.length;
					var textToShow = (startPic+1)+" to "+lastPic+" of "+entries.length;
						} else {lastPic = startPic+interval-1;
					var textToShow = (startPic+1)+" to "+(lastPic+1)+" of "+entries.length;
					}
				//Set text to indicate which pictures are being shown . . . 
				$j("#picIndex").text(textToShow);
				var boxNum = 0;
				for (p = startPic; p <=lastPic; p++) {
				boxNum++;
				var item = entries[p];
				var title = (item.title.$t != undefined ? item.title.$t : '<no title>');
				var imgsrc = item.content.src;//useful for downloading image
				var height = parseInt(item.gphoto$height.$t);
				var width = parseInt(item.gphoto$width.$t);
				var orientation =(height>width ? 'vert' : 'hor');
				var description = item.media$group.media$description.$t;
				var imgSelector = "img#box"+boxNum;
				$j(imgSelector).parent().parent().hide();
				$j(imgSelector).attr("src",imgsrc+"?imgmax="+thumbWidth);
				$j(imgSelector).parent().attr("href",imgsrc+"?imgmax="+imgWidth);
				//				$j(imgSelector).parent().parent().css({visibility: "visible"});
				// Set correct orientation for the li "parent" of the a img
				$j(imgSelector).parent().removeClass("loading").addClass(orientation);
				$j(imgSelector).parent().parent().fadeIn("slow");
				}
			}
});