/* Copyright © Pluck Corporation 2008. This software code and related intellectual property are the property of Pluck Corporation and are licensed for use solely on designated websites. Any distribution, copying, or other use of this intellectual property other than pursuant to a written agreement with Pluck Corporation is strictly prohibited. All Rights Reserved. */
// THIS FILE IS AUTOGENERATED. DO NOT EDIT THIS FILE DIRECTLY.
if (typeof(slwidgets) === 'undefined') {
  slwidgets = {};
}
if (typeof(slwidgets.addEvent) === 'undefined') {
  // from http://ajaxcookbook.org/event-handling-memory-leaks/
  slwidgets.addEvent = function(instance, eventName, listener){
    var listenerFn = listener;
    if (instance.addEventListener) {
      instance.addEventListener(eventName, listenerFn, false);
    } else 
      if (instance.attachEvent) {
        listenerFn = function(){
          listener(window.event);
        }
        instance.attachEvent("on" + eventName, listenerFn);
      }
  }
}
if (typeof(slwidgets.widgetLoader) === 'undefined') {
  slwidgets.widgetLoader = {};
  (function(){
    // the local variable we'll use to queue up load calls
    var callbacks = [];
    // keeps track of what scripts we've already added
    var addedScripts = {};
    // have we added our onload handler before?
    var onLoadHandlerAdded = false;
    // called to check if every url is loaded
    var onLoadHandler = function(){
      // check that every url is loaded
      for (url in addedScripts) {
        if (addedScripts[url] == false) {
          // found a url that hasn't loaded, so call us again in 100 mills
          setTimeout(onLoadHandler, 100);
          return;
        }
      }
      // every url is loaded, so call all the callbacks
      for (var callbackIndex = 0; callbackIndex < callbacks.length; callbackIndex++) {
        callbacks[callbackIndex]();
      }
    };
    // expose the onLoad handler for polls in forums... remove in next release
    if (typeof(slwidgets.onLoadHandler) === 'undefined') {
        slwidgets.onLoadHandler = function() {
            var handlers = slwidgets.onLoadHandler.handlers;
            for (var i = 0; i < handlers.length; i++) {
                handlers[i]();
            }
        }
        slwidgets.onLoadHandler.handlers = [];
    }
    slwidgets.onLoadHandler.handlers.push(onLoadHandler);
    
    var addUrlHandler = function(url) {
        // check to see if we've added this script before
        if (url in addedScripts) {
          // we've added it before, short circuit adding the script node to the head
          return;
        }
        // we've added the script, but haven't loaded it yet
        addedScripts[url] = false;
        // there should only be one head node
        var headNode = document.getElementsByTagName("head")[0];
        // make the script node
        var scriptNode = document.createElement("script");
        scriptNode.setAttribute("src", url);
        // if we're using Internet Explorer, use the onreadystatechange event; otherwise, use onload
        if ((/msie/i).test(navigator.userAgent)) {
          scriptNode.onreadystatechange = function(){
            if (this.readyState === 'loaded' || this.readyState === 'complete') {
              slwidgets.widgetLoader.requestComplete(url);
            }
          };
        } else {
          scriptNode.setAttribute("onload", "javascript:slwidgets.widgetLoader.requestComplete('" + url + "');");
        }
        headNode.appendChild(scriptNode);
    };
    
    slwidgets.widgetLoader.load = function(urls, callback){
        if (typeof(urls).length === 'undefined') {
            urls = [urls];
        }
        for (var i=0; i < urls.length; i++) {
            addUrlHandler(urls[i]);
        }
        
        // add the callback to our list of callbacks
        callbacks.push(callback);;
    };
    
    slwidgets.widgetLoader.requestComplete = function(urlThatFinished){
      // set this url to loaded so our onload handler can check to make sure everything was loaded  before calling the callbacks
      addedScripts[urlThatFinished] = true;
    }
    slwidgets.widgetLoader.addWidgetDiv = function(){
        if (typeof(PLUCKSL_WIDGET_DIV) === 'string') {
            var id = PLUCKSL_WIDGET_DIV;
            delete PLUCKSL_WIDGET_DIV
            return id;
        }
      var id = "widgetDiv-" + Math.random() + '-' + Math.random();
      document.write('<div id="' + id + '"><\/div>');
      return id;
    };
    // add our onload listener that will check that the urls are finished loading
    if (!onLoadHandlerAdded) {
      onLoadHandlerAdded = true;
      slwidgets.addEvent(window, "load", onLoadHandler);
    }
  })();
}
if (typeof(slwidgets.getServerBaseUrl) === 'undefined') {
	slwidgets.getServerBaseUrl = function(url){
		return 'http://community2.trails.com/ver1.0';
	};
}

var PLUCKSL_WIDGET_OPTIONS_DEFAULT = {"urls":false,"useDefaultStylesheet":"true","galleryKey":"","templateId":""};
if (typeof window.slTrailsRecentPublicPhotos == 'undefined') {
	slTrailsRecentPublicPhotos = function() { }
};

(function(){
	var widgetId = slwidgets.widgetLoader.addWidgetDiv();
var localOptions = {};
if (typeof(PLUCKSL_WIDGET_OPTIONS) !== 'undefined') { localOptions = PLUCKSL_WIDGET_OPTIONS; }
var localDefaultOptions = PLUCKSL_WIDGET_OPTIONS_DEFAULT;
var localEvents = {};
if (typeof(PLUCKSL_WIDGET_EVENTS) !== 'undefined') { localEvents = PLUCKSL_WIDGET_EVENTS; }
	slwidgets.widgetLoader.load([slwidgets.getServerBaseUrl(window.location.domain) +'/content/widgets/globalOptions.js'], function() {
	    if (typeof slTrailsRecentPublicPhotos.__code === 'undefined') {

		    slTrailsRecentPublicPhotos.__code = true;
slTrailsRecentPublicPhotos.prototype = new slwidgets.slWidgetBase();

slTrailsRecentPublicPhotos.prototype.template = '<div class="slV2 slPublicRecentPhotos"\>\r\n\t<div class="slTitle"\>Recent Photos {if photos.length != 0} <span\>(<a href="${slTrailsUrls.publicPhotos.showGalleryThumbnails(options.galleryKey)}"\>View All Photos</a\>)</span\>{/if}</div\>\r\n{if photos.length != 0}\r\n\t<ul class="slItems"\>\r\n\t\t{for photo in photos}\r\n\t\t\t{var url = slTrailsUrls.publicPhotos.showGallery(photo.GalleryKey.Key, photo.PhotoKey.Key, photo.Author.UserKey.Key)}\r\n\t\t\t<li\><a href="${url}" class="slPhoto"\><img src="${photo.Image.Small}"/\></a\></li\>\r\n\t\t{/for}\r\n\t</ul\>\r\n{else}\r\n\t<div class="slNoPhotos"\>There aren\'t any photos yet.{if !isAnonymous}<br/\> Be the first to <a href="${slTrailsUrls.publicPhotos.showUpload(user.UserKey.Key, options.galleryKey)}"\>upload a photo!</a\>{/if}</div\>\r\n{/if}\r\n</div\>\r\n';

slTrailsRecentPublicPhotos.prototype.addChildWidgets = function() {
};

slTrailsRecentPublicPhotos.prototype.addRequests = function() {
	this.addRequest(new PhotoPage(new GalleryKey(this.context.options.galleryKey), 3, 1));
	this.addRequest(new GalleryKey(this.context.options.galleryKey));
};

slTrailsRecentPublicPhotos.prototype.buildContextFromResponses = function(responses) {
	if (responses.length != 0) {
		this.context.gallery = responses[1].Gallery;
		this.context.photoCount = responses[0].PhotoPage.NumberOfPhotos;
		this.context.photos = responses[0].PhotoPage.Photos;
		this.context.isAnonymous = this.getCurrentUser().isAnonymous;
		this.context.user = this.getCurrentUser();
	}
};

};
	    PluckSlWidget.runWidget('slTrailsRecentPublicPhotos', widgetId, localDefaultOptions, localOptions, localEvents);
    });
})();

