(function($){$.fn.getPhotoAlbums=function(options){var defaults={xml_path:"/xml/default.asp",uniqueListID:"",maxAlbums:3,randomizeAlbums:0,randomizePhotos:0,startRandomKeepOrder:0,writeInHorizontalOrder:0,maxItems:10,photosPerItem:1,setTitle:0,hardPhotoWidth:0,hardPhotoHeight:0,minPhotosPerAlbum:1,callback1:null,callback2:null};var options=$.extend(defaults,options);return this.each(function(){var obj=$(this),groupid=obj.attr("pid"),photos=new Array();if(groupid.length>0){$.ajax({type:"GET",url:options.xml_path+"?sid="+JavaScriptSchoolID+"&type=photoall&id="+groupid,dataType:"xml",success:function(xml){var albumCount=0;$(xml).find('item').each(function(){photos[albumCount]=new Array();var pcount=0;$(this).find('image').each(function(){photos[albumCount][pcount++]={path:$(this).find("path").text(),cap:$(this).find("cap").text(),height:$(this).find("height").text(),width:$(this).find("width").text()}});albumCount++})},error:function(request,tStatus,eThrown){if(window.console&&window.console.firebug){console.log("getPhotoAlbums plugin error: request='"+request+"', tStatus='"+tStatus+"', eThrown='"+eThrown+"'")}},complete:function(){if(photos.length>0){var $AllPhotos=new Array();if(options.randomizeAlbums>0){photos.sort(function(){return Math.round(Math.random())-0.5})}for(var h=0,ttlCnt=0;h<photos.length&&ttlCnt<options.maxAlbums;h++){var startIndex=(options.startRandomKeepOrder>0)?Math.floor(Math.random()*(photos[h].length-1)):0;if(photos[h].length>=options.minPhotosPerAlbum){if(options.randomizePhotos>0){photos[h].sort(function(){return Math.round(Math.random())-0.5})}var i=startIndex,totalPhotos=0,totalPhotosPerItem=(options.photosPerItem<=(photos[h].length/options.maxItems)||(options.photosPerItem==1))?options.photosPerItem:(photos[h].length/options.maxItems),horizPhotoAdjustment=(options.writeInHorizontalOrder>0)?(options.maxItems):1;$AllPhotos[h]=$("<ul></ul>").attr("id",options.uniqueListID+"photoAlbum_"+h+"_"+groupid).addClass("photosReturn");for(var listitem=1;listitem<=options.maxItems;listitem++){$PhotoItem=$("<li></li>").addClass("photoItem").addClass("listitem_"+listitem);for(var photosInItem=0;(photosInItem<totalPhotosPerItem)&&(totalPhotos<photos[h].length);totalPhotos++,photosInItem++){if(photos[h][i].path.length>0){$Image=$("<img />").attr("src",photos[h][i].path).attr("alt",photos[h][i].cap).attr("title",options.setTitle==1?photos[h][i].cap:"");if(options.hardPhotoWidth>0){$Image.attr("width",options.hardPhotoWidth)}else if(options.hardPhotoHeight>0){$Image.attr("height",options.hardPhotoHeight)}else{$Image.attr("width",photos[h][i].width).attr("height",photos[h][i].height)}$Image.appendTo($PhotoItem)}if(options.writeInHorizontalOrder>0){i+=((i+horizPhotoAdjustment)>(photos[h].length-1))?(horizPhotoAdjustment-1)-(photos[h].length-1):horizPhotoAdjustment}else{i++}}$PhotoItem.appendTo($AllPhotos[h]);if(!options.writeInHorizontalOrder>0){i=(i>photos[h].length-1)?0:i}else{i=(i>=(photos[h].length-1))?0:i+1}}ttlCnt++}}$($AllPhotos).each(function(){$(this).children().each(function(){if($(this).children().length<1){$(this).remove()}});obj.append($(this));if($.isFunction(options.callback1)){options.callback1($(this).attr("id"))}})}else{if(window.console&&window.console.firebug){console.log("getPhotoAlbums plugin error: no photos in array")}}if($.isFunction(options.callback2)){options.callback2(photos.length,groupid)}}})}else{if(window.console&&window.console.firebug){console.log("getPhotoAlbums plugin error: no or bad groupid passed")}}})}})(jQuery);