/**
* jQuery RESTful Gallery - v2.0 - 5/18/2012
* http://www.flashyourweb.com/gallery2/embed_samples/g3_rest.php
*
* Copyright (c) 2012 "suprsidr" Wayne Patterson
* License: http://www.opensource.org/licenses/mit-license.php
*/
(function(a,b,c){b.fn.g3rest=function(d){var e=b.extend({},b.fn.g3rest.defaults,d);return this.each(function(){function h(c){b(d).empty().append(b("
").addClass("ajax-title").append("")).append(b("").attr({id:"ajax-breadcrumbs"})).append(b("").attr({id:"ajax-gallery"})).append(b("").attr({id:"ajax-description"}).append("")).append(b("").attr({id:"ajax-pager"}));b.ajaxSetup({type:"GET",dataType:"jsonp",beforeSend:function(a){a.setRequestHeader("X-Gallery-Request-Key",c)}});b(a).hashchange()}function i(a){b.ajax({url:e.url+"/items",data:{output:"jsonp",ancestors_for:a},success:function(a){b("#ajax-breadcrumbs").empty();b.each(a,function(c,d){if(c==a.length-1){b("#ajax-breadcrumbs").append(sprintf(" %s",d.entity.title));return}b("#ajax-breadcrumbs").append(sprintf('%s»',d.entity.id,d.url,d.entity.title))});b("#ajax-breadcrumbs a").on("click",function(a){a.preventDefault();b("#ajax-pager, #ajax-breadcrumbs").empty();location.hash="#"+b(this).attr("ref")})}})}function j(a,b,c){f.html="";f.page=b;if(a==1)return f;if(b>0){f.html+=sprintf('« ',c,parseInt(b)-1)}for(var d=0;d %s %s",d+1,e);continue}f.html+=sprintf('%s%s',c,d,d+1,e)}if(b »',c,parseInt(b)+1)}return f}function k(d,h){i(d);b.ajax({url:d,data:h,success:function(i){b(".ajax-title h2").fadeOut("fast",function(a){b(this).text(i.entity.title).fadeIn("slow")});b("#ajax-description p").css({display:"none"}).html(i.entity.description.replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,'$1').replace(/\n/g,"
")).fadeIn("slow");var k=l(i.members,e.max_items_per_page);f=j(k.length,h.page,d);b("#ajax-pager").empty().css({display:"none"}).append(f.html).fadeIn("slow");b("#ajax-pager a").on("click",function(c){c.preventDefault();b("#ajax-pager, #ajax-breadcrumbs").empty();if(a.location.hash.indexOf("page")==-1){location.hash=location.hash+"/page/"+Math.floor(parseInt(b(this).attr("ref"))+1)}else{var d=location.hash.substr(0,location.hash.lastIndexOf("/")+1);location.hash=d+Math.floor(parseInt(b(this).attr("ref"))+1)}});b.ajax({url:e.url+"/items",data:{output:"jsonp",urls:JSON.stringify(k[f.page])},success:function(d){b("#ajax-gallery").empty();b.each(d,function(a,c){if(c.entity.type=="album"){var e=c.entity.web_url;var f="item/"+c.entity.id}else if(c.entity.type=="photo"){var e=g==0?c.entity.file_url_public:c.entity.resize_url_public;var f=""}else if(c.entity.type=="movie"){var e=c.entity.file_url_public;var f=""}b("#ajax-gallery").append(b("").append(b("").attr({href:e,ref:f,alt:c.entity.title,"data-entity-type":c.entity.type,id:c.entity.type+"-"+c.entity.id}).css({height:c.entity.thumb_height}).data(c).append(b("
").attr({src:c.entity.thumb_url_public,alt:c.entity.title,"data-aspect":c.entity.thumb_height/c.entity.thumb_width}))));if(a==d.length-1){b("#ajax-gallery li:last-child img").on("load",function(a){m();if(b(".no-touch").length>0){b("#ajax-gallery li").on("mouseenter",function(a){a.preventDefault();var c=b(this).find("a").data();b(this).find("a").append(b('').html(c.entity.title).prepend(''));if(c.entity.description){b(this).append(b(sprintf('',c.entity.id,c.entity.id)));b(sprintf(".info-%s",c.entity.id)).on("mouseenter",function(a){a.preventDefault();b("body").append(b('').css({display:"none"}).append(b("").text(c.entity.title)).append(c.entity.description.replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,'$1').replace(/\n/g,"
")));b(sprintf(".info-%s",c.entity.id)).colorbox({inline:true,width:"360",href:"#info-box",onOpen:function(){b("#info-box").css({display:"block"})},onClosed:function(){b("#info-box").remove()}})});b(sprintf(".info-%s",c.entity.id)).on("mouseleave",function(a){a.preventDefault();if(b("#cboxLoadedContent > #info-box").length){return}b("#info-box").remove()})}});b("#ajax-gallery li").on("mouseleave",function(a){var c=b(this).find("a").data();b(this).find(".pop-title").remove();b(this).find(sprintf(".info-%s",c.entity.id)).remove()})}})}});if(b(".ie8").length>0||b(".ie9").length>0){b("#ajax-gallery").append(b(""));m();if(b("no-touch")){b("#ajax-gallery a").on("mouseenter",function(a){a.preventDefault();b(this).append(b('').html(b(this).attr("alt")))});b("#ajax-gallery a").on("mouseleave",function(a){b(this).find(".pop-title").remove()})}}var f={getImageMetaData:function(a){return{type:a.getAttribute("data-entity-type"),id:a.getAttribute("id")}}},h=b("#ajax-gallery a").photoSwipe(f);b(h).on(c.EventTypes.onHide,function(a){b("#multimedia").remove();m()});b(h).on(c.EventTypes.onBeforeShow,function(c){if(this.getCurrentImage().metaData.type=="movie"||this.getCurrentImage().metaData.type=="audio"){if(b("#multimedia").length)b("#multimedia").remove();b(".ps-toolbar-play, .ps-toolbar-previous, .ps-toolbar-next").css({visibility:"hidden"});b(".ps-carousel div").css({display:"none"});var d=b("#"+this.getCurrentImage().metaData.id).data();d.entity.code=e.code;b("body").append(b('').html(sprintf(getMediaTemplate(d.entity.mime_type),d.entity)));b("#multimedia").css({left:(b(a).innerWidth()-b("#multimedia object").width())/2,top:(b(a).innerHeight()-b("#multimedia object").height())/2})}});b('#ajax-gallery a[data-entity-type="album"]').unbind("click").on("click",function(a){a.preventDefault();var c=b(this).data();location.hash="#"+b(this).attr("ref")})}})}})}function l(a,b){for(var c,d=0,e=-1,f=a.length,g=[];dc||a>1){b(this).css({height:"100%",width:c/a,"margin-top":""})}else if(a<=1){b(this).css({height:d*a,width:"100%","margin-top":(c-d*a)/2})}})}var d=this,f={page:0,html:""},g=b(a).width()>b(a).height()?b(a).width():b(a).height();g=g<=1e3?g:0;b(a).hashchange(function(){if(location.hash.indexOf("page")>-1){var a=location.hash.replace("#","/").split("/page/");k(e.url+a[0],{output:"jsonp",scope:"direct",page:parseInt(a[1])-1})}else if(location.hash!=""){k(e.url+location.hash.replace("#","/"),{output:"jsonp",scope:"direct",page:0})}else{k(e.url+"/item/"+e.initial,{output:"jsonp",scope:"direct",page:0})}});h(e.key);b(a).resize(function(a){m()})})};b.fn.g3rest.defaults={initial:1,max_items_per_page:20,key:""}})(window,window.jQuery,window.Code.PhotoSwipe)