//requestVars start

/*
 * @author      Jesse Berman
 * @copyright   2008-01-31
 * @version     1.0
 * @license     http://www.gnu.org/copyleft/lesser.html
 * @original 	http://sourceforge.net/projects/pwa/
*/


/*
 * Portions by Dieter Raber <dieter@dieterraber.net>
 * copyright   2004-12-27
*/


/*
 * Additional edits by Eric C. Powell <ecpowell@esomething.org>
 * Edits made for Hannaford Street Bible Church & eSomething photo galleries 2007-11-17
 * File named changed to gallerygenerator.js on Hannaford site
 * Added descriptions, photo totals, & dates to gallery home. Also added CSS style edits & navigation urls.
*/


/* pwa.js: a drop-in JavaScript utility that displays galleries from picasaweb.google.com in your website */

/* This JavaScript file, when called from a webpage, will load all the thumbnail images of all the galleries
   in a user's Picasa Web Albums account into an HTML table that's 4 rows wide.  Clicking on any of the
   galleries will display thumbnails of all the photos in that gallery, and clicking on any of those thumbnails
   will display the photo.  

   To call this file from your own webpage, use the following syntax:

       <script type="text/javascript">username='YourPicasawebUsername'; photosize='800'; columns='4';</script>
       <script type="text/javascript" src="http://www.yoursite.com/pwa.js"></script>

   Make sure you change YourPicasawebUsername to your actual Picasaweb username.  For more information about
   Picasa, check out picasaweb.google.com.  Also, www.yoursite.com should point to your actual site name, and
   the location of the pwa.js file.  The script looks for the images prev.gif, next.gif, and home.gif, in the
   same directory as pwa.js, to create the navigation arrows.  Please make sure those exist!  I'm providing
   samples in the SourceForce repository, but feel free to substitute your own.

   Note: "Photosize" is the size of the image to be displayed when viewing single images.  I like 800.  :-)
   Note: "columns" is the number of columns of photos to be displayed on your site in the gallery and album views.
   You may omit either of these values; if you do, the default settings are 800 for photosize and 4 for columns.

*/



function readGet(){var _GET = new Array();var uriStr  = window.location.href.replace(/&amp;/g, '&');var paraArr, paraSplit;if(uriStr.indexOf('?') > -1){var uriArr  = uriStr.split('?');var paraStr = uriArr[1];}else{return _GET;}if(paraStr.indexOf('&') > -1){paraArr = paraStr.split('&');}else{paraArr = new Array(paraStr);}for(var i = 0; i < paraArr.length; i++){paraArr[i] = paraArr[i].indexOf('=') > -1 ? paraArr[i] : paraArr[i] + '=';paraSplit  = paraArr[i].split('=');_GET[paraSplit[0]] = decodeURI(paraSplit[1].replace(/\+/g, ' '));}return _GET;}var _GET = readGet();
//requestVars end


function $(a){document.write(a);}

var columns;
if(!columns || isNaN(columns) || columns < 1) {columns = 4;}


var searchterm;
if(!searchterm) {searchterm = "";}

if(_GET['keyword']) {searchterm = _GET['keyword'];}

var searchterm_lc=searchterm.toLowerCase();

var gallerylink;
if(!gallerylink) {gallerylink = "http://www.hannaford.org/gallery.php";}

var imgmax;
if(!imgmax || isNaN(imgmax) || imgmax < 1) {imgmax = 160;} //The size of gallery photo & column width 72, 144, 160, 200

var colwidth;
if(!colwidth || isNaN(colwidth) || colwidth < 1) {colwidth = 160;} //The size of gallery photo & column width 72, 144, 160, 200

var border;
if(!border || isNaN(border) || border < 0) {border = 4;}

var charlim;
if(!charlim || isNaN(charlim) || charlim < 0) {charlim = 0;}

var padding;
if(!padding || isNaN(padding) || padding < -1) {padding = 10;}

//Global variables
var photolist = new Array(); //this is used globally to store the entire list of photos in a given album, rather than pass the list around in a URL (which was getting rediculously long as a result)



function picasaweb(j){ //returns the list of all albums for the user // Eric edits
 $("<table border=0 style='margin:10px 0 15px 0'><tr>");

 var ii_col=-1
 for(i=0;i<j.feed.entry.length;i++){

 // for each of the albums in the feed, grab its album cover thumbnail and the link to that album,
 // then display them in a table with 4 columns (along with the album title)

search_description = j.feed.entry[i].summary.$t.toLowerCase() + j.feed.entry[i].media$group.media$description.$t.toLowerCase();

  // Skip gallery if search term in not in the description
//  if (j.feed.entry[i].summary.$t.search(searchterm) > -1 || j.feed.entry[i].summary.$t.search(searchterm_lc) > -1 || j.feed.entry[i].media$group.media$description.$t.search(searchterm) >-1 || feed.entry[i].media$group.media$description.$t.search(searchterm_lc) >-1){
  if (search_description.search(searchterm_lc) > -1){

  	ii_col=ii_col+1;

  	var img_base = j.feed.entry[i].media$group.media$content[0].url;

  
  	var id_begin = j.feed.entry[i].id.$t.indexOf('albumid/')+8;
  	var id_end = j.feed.entry[i].id.$t.indexOf('?');
  	var id_base = j.feed.entry[i].id.$t.slice(id_begin, id_end);
  
  	var id_begin = j.feed.entry[i].id.$t.indexOf('albumid/')+8;
  	var id_end = j.feed.entry[i].id.$t.indexOf('?');
  	var id_base = j.feed.entry[i].id.$t.slice(id_begin, id_end);

	// Eric added date
  	var date_base = j.feed.entry[i].published.$t.slice(0, 7);

	// Eric added number of photos
  	var num_begin = j.feed.entry[i].summary.$t.indexOf('Number of Photos in Album: ')+56;
  	var num_end = j.feed.entry[i].summary.$t.lastIndexOf('a href')-9;
  	var num_base = j.feed.entry[i].summary.$t.slice(num_begin, num_end);
  
	// Eric added for album description
  	var desc_base = j.feed.entry[i].media$group.media$description.$t;
  
  	// Possibe character limit on the description
  	if (charlim > 0){
  		if (desc_base.length > charlim){
  			var desc_base = desc_base.slice(0,charlim);
  			var desc_charlim_last = desc_base.lastIndexOf(' ');
  			var desc_base = desc_base.slice(0,desc_charlim_last)+'...';
  		}
  	}	
   
  	// Eric added code if Picasa description has URL for YouTube video or website. 
  	// It was too long for the columns so now it just says 'here' with an href tag. 
  	// This if statement determines a YouTube URL
  	if (desc_base.indexOf('YouTube') > 0){
  			var desc_yttextend = desc_base.indexOf('on YouTube at ');
  			var desc_yturlstart = jdesc_base.indexOf('http');
  			var desc_yturl = desc_base.slice(desc_yturlstart);
  			var desc_yttextstart = desc_base.slice(0, desc_yttextend);
			// var desc_base = desc_yttextstart+"<a href='"+desc_yturl+"' target='_blank'>here.</a>"; // Code for the real URL
  			var desc_base = desc_yttextstart+"in our <a href='galleryvideoall.php'>Video Gallery</a>."; // Our video gallery URL
	}

// This if statement determines a website URL
  	if (desc_base.indexOf('website at') > 0){
  			var desc_webtextend = desc_base.indexOf('website at ');
  			var desc_weburlstart = desc_base.indexOf('http');
 			var desc_weburl = desc_base.slice(desc_weburlstart);
  			var desc_webtextstart = desc_base.slice(0, desc_webtextend);
  			var desc_base = desc_webtextstart+"website <a href='"+desc_weburl+"' target='_blank'>here</a>.";
	}
	

	// Eric edits // Also added description, number of photos, and date from Picasa
  	$("<td valign=top bgcolor='#ffffff' style='border: 1px dotted #195452'><center><a class='standard' href='"+gallerylink+"?albumid="+id_base+"'><img src='"+img_base+"?imgmax="+imgmax+"&crop=1' width="+colwidth+" class='pwimages' style='margin: "+border+"'/></a></center>");
  	$("<center><table border=0 cellspacing='2' cellpadding='0' width="+colwidth+" class='v12'><tr><td class'v12'><b><a href='"+gallerylink+"?albumid="+id_base+"'>"+ j.feed.entry[i].title.$t +"</a></b></td></tr>");
  	$("<tr><td class='v11'><div style='margin-top:10px'>"+ desc_base +"</div></td></tr>");
  	$("<tr><td class='v10'><div style='margin:3px 0px 10px 0px; color:#555555'><i>"+ num_base +" photos | "+ date_base +"</i></div></td></tr></table></center></td>");

  		if (ii_col % columns < columns-1) {
    		$("<td width="+padding+"></td>");
  		}

  		if (ii_col % columns == columns-1) {
    		$("</tr><tr><td height="+padding+"></td></tr><tr><td></td></tr><tr>");
  		}
 	}
  }
 $("</tr></table>");
}



if(_GET['photoid']&&_GET['albumid']){
 $('<script type="text/javascript" src="http://picasaweb.google.com/data/feed/base/user/'+username+'/albumid/'+_GET['albumid']+'?category=photo&alt=json&callback=getphotolist"></script>');//get the list of photos in the album and put it in the global "photolist" array so we can properly display the navigation arrows; this eliminates the need for really long URLs :-) 7/16/2007
// $('<script type="text/javascript" src="http://picasaweb.google.com/data/entry/base/user/'+username+'/albumid/'+_GET['albumid']+'/photoid/'+_GET['photoid']+'?alt=json&callback=photo&np='+_GET['np']+'&galleryname='+_GET['galleryname']+'"></script>');//photo
 $('<script type="text/javascript" src="http://picasaweb.google.com/data/entry/base/user/'+username+'/albumid/'+_GET['albumid']+'/photoid/'+_GET['photoid']+'?alt=json&callback=photo"></script>');//photo - Revised for new Picasa XML in 01-08
}else if(_GET['albumid']&&!_GET['photoid']){
 $('<script type="text/javascript" src="http://picasaweb.google.com/data/feed/base/user/'+username+'/albumid/'+_GET['albumid']+'?category=photo&alt=json&callback=albums"></script>');//albums
}else{
 $('<script type="text/javascript" src="http://picasaweb.google.com/data/feed/base/user/'+username+'?category=album&alt=json&callback=picasaweb&access=public"></script>');//picasaweb
}


//$Update: January 31, 2008$
//Edits & Deletes by Eric C. Powell For Youth Hannaford Gallery - November 26, 2007