!function(e){"use strict";var a,t,o,n,i,l,r,p,d,c,s,u={},g={arrowkeys:!0,controls:!0,loop:!0,maxwidth:null,maxheight:null,maxscreen:90,updatersz:!0,callback:null,lockscroll:!0,contenttype:"image",ajaxcontainer:"body > *"},f={init:function(a){return this.click(function(t){e(this).galpop("openbox",a),t.preventdefault()})},openbox:function(t,o,n){t=e.extend({},g,t),a.data({controls:t.controls,loop:t.loop,maxwidth:t.maxwidth,maxheight:t.maxheight,maxscreen:t.maxscreen,callback:t.callback,contenttype:t.contenttype});var i=o,l="",r=this,p=this.data("galpop-container")?this.data("galpop-container"):t.ajaxcontainer;return n||(n=0),"[object array]"===object.prototype.tostring.call(o)&&(i=(r=o)[n]),o||(i=this.attr("href"),l=this.data("galpop-group"),n=(r=e('[data-galpop-group="'+l+'"]')).index(this),t.arrowkeys&&e(document).on("keydown",c),t.updatersz&&e(window).resize(s),t.lockscroll&&e("html").addclass("lock-scroll")),a.data({rel:l,group:r,index:n,status:!0,count:r.length,ajaxcontainer:p}),a.fadein(500,"swing"),this.galpop("preload",i),this},closebox:function(){a.removeclass("complete").fadeout(500,"swing",function(){i.empty(),l.hide().empty(),e(this).data("status",!1),r.hide(),p.hide(),t.removeattr("style"),a.removeclass("loaded-ajax loaded-image loaded-iframe"),e(document).off("keydown",c),e(window).off("resize",s),e("html").removeclass("lock-scroll")})},preload:function(e){switch(a.data("contenttype")){case"ajax":a.addclass("loaded-ajax"),this.galpop("loadajax",e);break;case"iframe":a.addclass("loaded-iframe"),this.galpop("loadiframe",e);break;case"image":default:a.addclass("loaded-image"),this.galpop("loadimage",e)}return this},loadimage:function(e){var t=new image;return t.src=e,u.object=t,u.resizable=!0,t.onload=function(){a.galpop("display")},t.onerror=function(){console.log(e+" contains a broken image!")},this},loadiframe:function(t){var o=e('');return u.object=o,u.resizable=!1,a.galpop("display"),this},loadajax:function(t){var o=a.data("ajaxcontainer");return u.resizable=!1,e.ajax({url:t,type:"get",datatype:"html",success:function(t){var n=e(t).filter(o),i=e(t).find(o);n.length?(u.object=n,a.galpop("display")):i.length?(u.object=i,a.galpop("display")):console.log("element "+o+" not found in dom.")},error:function(e,a){0===e.status?console.log("not connect.\n verify network."):404==e.status?console.log("requested page not found. [404]"):500==e.status?console.log("internal server error [500]."):"parsererror"===a?console.log("requested json parse failed."):"timeout"===a?console.log("time out error."):"abort"===a?console.log("ajax request aborted."):console.log("uncaught error.\n"+e.responsetext)}}),this},resize:function(){var o=u.resizable,n=u.object.naturalheight,i=u.object.naturalwidth,l=a.data("maxwidth"),r=a.data("maxheight"),p=a.data("maxscreen"),d=e(window).height(),c=e(window).width(),s=0;return(!l||l>c*p/100)&&(l=c*p/100),(!r||r>d*p/100)&&(r=d*p/100),o&&(i>l&&(n*=s=l/i,i*=s),n>r&&(i*=s=r/n,n*=s)),t.css({height:n,width:i}),this},display:function(){this.galpop("resize"),settimeout(function(){a.addclass("complete"),i.append(u.object).fadein(500,"swing",function(){a.galpop("complete")})},500)},complete:function(){var t=a.data("controls"),o=a.data("callback"),n=a.data("index"),i=a.data("count"),l=a.data("loop");a.galpop("infoparse"),!t||0===n&&!l||i<=1?r.hide():r.show(),!t||n+1>=i&&!l||i<=1?p.hide():p.show(),e.isfunction(o)&&o.call(this)},moveitem:function(t){var o=a.data("group"),n=!1,r="";return a.removeclass("complete"),l.fadeout(500,"swing",function(){e(this).contents().remove()}),i.fadeout(500,"swing",function(){e(this).empty(),"[object array]"===object.prototype.tostring.call(o)?r=o[t]:(n=o.eq(t)).attr("href")?r=n.attr("href"):n.attr("src")&&(r=n.attr("href")),e.fn.galpop("preload",r),a.data("index",t)}),this},next:function(){var e=a.data("index"),t=a.data("loop");return e+10?(e--,a.galpop("moveitem",e)):t&&(e=o-1,a.galpop("moveitem",e)),this},infoparse:function(){var t=a.data("group");if(t instanceof jquery){var o=a.data("index"),n=t.eq(o),i=e.trim(n.attr("title")),r=e.trim(n.data("galpop-link")),p=e.trim(n.data("galpop-link-title")),d=e.trim(n.data("galpop-link-target"));l.html(""),i&&e(""+i+"
").appendto(l),r&&(p||(p=r),d&&(d='target="'+d+'"'),e('"+p+"
").appendto(l)),(i||r)&&l.fadein(500,"swing")}},update:function(){var e=a.data("index");return a.galpop("moveitem",e),this},destroy:function(){return this.off("click")}};e.fn.galpop=function(a){return f[a]?f[a].apply(this,array.prototype.slice.call(arguments,1)):"object"!=typeof a&&a?void e.error("method "+a+" does not exist on jquery.galpop"):f.init.apply(this,arguments)},e.galpop={},e.galpop.extend=function(e,a){f[e]=a},e(document).ready(function(){a=e('').appendto("body"),t=e('').appendto(a),r=e('').appendto(t),p=e('').appendto(t),o=e('').appendto(t),n=e('').appendto(t),i=e('').appendto(n),l=e('').appendto(n),d=e('').appendto(n),a.click(function(a){e(this).galpop("closebox"),a.preventdefault()}),t.click(function(e){e.stoppropagation()}),r.hide().click(function(e){a.galpop("prev"),e.preventdefault()}),p.hide().click(function(e){a.galpop("next"),e.preventdefault()}),d.click(function(e){a.galpop("closebox"),e.preventdefault()}),l.on("click","a",function(){a.galpop("closebox")}),c=function(e){var t=!1;switch(e.which){case 27:a.galpop("closebox"),t=!0;break;case 37:a.galpop("prev"),t=!0;break;case 39:a.galpop("next"),t=!0}t&&e.preventdefault()},s=function(){a.galpop("resize")}})}(jquery);