/*
 * Galleria v 1.1.2
 * http://galleria.aino.se
 *
 * Copyright 2010, Aino
 * Licensed under the MIT license.
 */
(function(){var g=false,j=/xyz/.test(function(){xyz})?/\b__super\b/:/.*/,c=function(){},i=this;c.extend=function(r){var q=this.prototype;g=true;var p=new this();g=false;for(var o in r){if(o){p[o]=typeof r[o]=="function"&&typeof q[o]=="function"&&j.test(r[o])?(function(s,t){return function(){var v=this.__super;this.__super=q[s];var u=t.apply(this,arguments);this.__super=v;return u}})(o,r[o]):r[o]}}function n(){if(!g&&this.__constructor){this.__constructor.apply(this,arguments)}}n.prototype=p;n.constructor=n;n.extend=arguments.callee;return n};var h=c.extend({loop:function(p,o){var n=this;if(typeof p=="number"){p=new Array(p)}jQuery.each(p,function(){o.call(n,arguments[1],arguments[0])});return p},create:function(p,o){p=p||"div";var n=document.createElement(p);if(o){n.className=o}return n},getElements:function(n){var o={};this.loop(jQuery(n),this.proxy(function(p){this.push(p,o)}));return o},setStyle:function(o,n){jQuery(o).css(n);return this},cssText:function(n){var p=document.createElement("style");this.getElements("head")[0].appendChild(p);if(p.styleSheet){p.styleSheet.cssText=n}else{var o=document.createTextNode(n);p.appendChild(o)}return this},cssFile:function(o){var n=document.createElement("link");n.media="all";n.rel="stylesheet";n.href=o;this.getElements("head")[0].appendChild(n)},moveOut:function(n){return this.setStyle(n,{position:"absolute",left:"-10000px"})},moveIn:function(n){return this.setStyle(n,{left:"0"})},reveal:function(n){return jQuery(n).show()},hide:function(n){return jQuery(n).hide()},mix:function(o,n){return jQuery.extend(o,n)},proxy:function(o,n){if(typeof o!=="function"){return function(){}}n=n||this;return function(){return o.apply(n,Array.prototype.slice.call(arguments))}},listen:function(p,o,n){jQuery(p).bind(o,n)},forget:function(o,n){jQuery(o).unbind(n)},dispatch:function(o,n){jQuery(o).trigger(n)},clone:function(o,n){n=n||false;return jQuery(o).clone(n)[0]},removeAttr:function(o,n){this.loop(n.split(" "),function(p){jQuery(o).removeAttr(p)})},push:function(n,o){if(typeof o.length=="undefined"){o.length=0}Array.prototype.push.call(o,n);return n},width:function(o,n){return this.meassure(o,n,"Width")},height:function(o,n){return this.meassure(o,n,"Height")},meassure:function(p,o,s){var q=jQuery(p);var n=o?q["outer"+s](true):q[s.toLowerCase()]();if(l.QUIRK){var r=s=="Width"?["left","right"]:["top","bottom"];this.loop(r,function(t){n+=q.css("border-"+t+"-width").replace(/[^\d]/g,"")*1;n+=q.css("padding-"+t).replace(/[^\d]/g,"")*1})}return n},toggleClass:function(q,p,n){if(typeof n!=="undefined"){var o=n?"addClass":"removeClass";jQuery(q)[o](p);return this}jQuery(q).toggleClass(p);return this},hideAll:function(n){jQuery(n).find("*").hide()},animate:function(o,n){var p=jQuery(o);if(!p.length){return}if(n.from){p.css(from)}p.animate(n.to,{duration:n.duration||400,complete:n.complete||function(){}})},wait:function(o,r,q,n){o=this.proxy(o);r=this.proxy(r);q=this.proxy(q);var p=new Date().getTime()+(n||3000);i.setTimeout(function(){if(o()){r();return false}if(new Date().getTime()>=p){q();r();return false}i.setTimeout(arguments.callee,1)},1);return this},getScript:function(p,r){var q=document.getElementsByTagName("head")[0];var o=document.createElement("script");o.src=p;r=this.proxy(r);var n=false;o.onload=o.onreadystatechange=function(){if(!n&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")){n=true;r();o.onload=o.onreadystatechange=null}};q.appendChild(o);return this}});var e=h.extend({__constructor:function(n){this.image=null;this.elem=this.create("div","galleria-image");this.setStyle(this.elem,{overflow:"hidden",position:"relative"});this.order=n;this.orig={w:0,h:0,r:1}},cache:{},add:function(o){if(this.cache[o]){return this.cache[o]}var n=new Image();n.src=o;this.setStyle(n,{display:"block"});if(n.complete&&n.width){this.cache[o]=n;return n}n.onload=(function(p){return function(){p.cache[o]=n}})(this);return n},isCached:function(n){return this.cache[n]?this.cache[n].complete:false},make:function(o){var n=this.cache[o]||this.add(o);return this.clone(n)},load:function(n,o){o=this.proxy(o);this.elem.innerHTML="";this.image=this.make(n);this.moveOut(this.image);this.elem.appendChild(this.image);this.wait(function(){return(this.image.complete&&this.image.width)},function(){this.orig={h:this.image.height,w:this.image.width};o({target:this.image,scope:this})},function(){l.raise("image not loaded in 10 seconds: "+n)},10000);return this},scale:function(p,r,q,n,s,o){s=s||0;o=o||function(){};if(!this.image){return this}this.wait(function(){width=p||this.width(this.elem);height=r||this.height(this.elem);return width&&height},function(){var t=Math[(q?"max":"min")](width/this.orig.w,height/this.orig.h);if(n){t=Math.min(n,t)}this.setStyle(this.elem,{width:width,height:height});this.image.width=Math.ceil(this.orig.w*t)-s*2;this.image.height=Math.ceil(this.orig.h*t)-s*2;this.setStyle(this.image,{position:"relative",top:Math.round(this.image.height*-1/2+(height/2))-s,left:Math.round(this.image.width*-1/2+(width/2))-s});o.call(this)});return this}});var k;var l=i.Galleria=h.extend({__constructor:function(o){if(typeof o.target==="undefined"){l.raise("No target.")}this.playing=false;this.playtime=3000;this.active=null;this.queue={};this.data={};this.dom={};this.controls={active:0,swap:function(){this.active=this.active?0:1},getActive:function(){return this[this.active]},getNext:function(){return this[Math.abs(this.active-1)]}};this.thumbnails={};this.options=this.mix({preload:2,image_crop:false,thumb_crop:true,thumb_quality:"auto",image_margin:0,thumb_margin:0,transition:l.transitions.fade,transition_speed:400,carousel:true,carousel_speed:200,carousel_steps:"auto",carousel_follow:true,keep_source:false,popup_links:false,max_scale_ratio:undefined,thumbnails:true,link_source_images:true,data_type:"auto",data_image_selector:"img",data_source:o.target,data_config:function(p){return{}},queue:true,remove_original:true},o);this.target=this.dom.target=this.getElements(this.options.target)[0];if(!this.target){l.raise("Target not found.")}this.stageWidth=0;this.stageHeight=0;var n="container stage images image-nav image-nav-left image-nav-right info info-link info-text info-title info-description info-author info-close thumbnails thumbnails-list thumbnails-container thumb-nav-left thumb-nav-right loader counter";n=n.split(" ");this.loop(n,function(p){this.dom[p]=this.create("div","galleria-"+p)})},bind:function(o,n){this.listen(this.get("container"),o,this.proxy(n));return this},trigger:function(n){n=typeof n=="object"?this.mix(n,{scope:this}):{type:n,scope:this};this.dispatch(this.get("container"),n);return this},run:function(){var s=this.options;if(!this.data.length){l.raise("Data is empty.")}if(!s.keep_source){this.target.innerHTML=""}this.loop(2,function(){var o=new e();this.setStyle(o.elem,{position:"absolute",top:0,left:0});this.setStyle(this.get("images"),{position:"relative",top:0,left:0,width:"100%",height:"100%"});this.get("images").appendChild(o.elem);this.push(o,this.controls)},this);for(var p=0;this.data[p];p++){var n;if(s.thumbnails===true){n=new e(p);var r=this.data[p].thumb||this.data[p].image;this.get("thumbnails").appendChild(n.elem);n.load(r,this.proxy(function(o){var t=this.width(o.target);o.scope.scale(null,null,s.thumb_crop,null,s.thumb_margin,this.proxy(function(){this.toggleQuality(o.target,s.thumb_quality===true||(s.thumb_quality=="auto"&&t<o.target.width*3));this.trigger({type:l.THUMBNAIL,thumbTarget:o.target,thumbOrder:o.scope.order})}))}));if(s.preload=="all"){n.add(this.data[p].image)}}else{if(s.thumbnails=="empty"){n={elem:this.create("div","galleria-image"),image:this.create("span","img")};n.elem.appendChild(n.image);this.get("thumbnails").appendChild(n.elem)}else{n={elem:false,image:false}}}var q=this.proxy(function(t){t.preventDefault();var o=t.currentTarget.rel;if(this.active!==o){this.show(o)}});if(s.thumbnails!==false){n.elem.rel=p;this.listen(n.elem,"click",q)}if(s.link_source_images&&s.keep_source&&this.data[p].elem){this.data[p].elem.rel=p;this.listen(this.data[p].elem,"click",q)}this.push(n,this.thumbnails)}this.build();this.target.appendChild(this.get("container"));this.wait(function(){this.stageWidth=this.width(this.get("stage"));this.stageHeight=this.height(this.get("stage"));return this.stageHeight&&this.stageWidth},function(){var o=this.thumbnails[0]?this.width(this.thumbnails[0].elem,true):0;var t=o*this.thumbnails.length;if(t<this.stageWidth){s.carousel=false}if(s.carousel){this.toggleClass(this.get("thumbnails-container"),"galleria-carousel");this.carousel={right:this.get("thumb-nav-right"),left:this.get("thumb-nav-left"),overflow:0,setOverflow:this.proxy(function(u){u=u||this.width(this.get("thumbnails-list"));this.carousel.overflow=Math.ceil(((t-u)/o)+1)*-1}),pos:0,setClasses:this.proxy(function(){this.toggleClass(this.carousel.left,"disabled",this.carousel.pos===0);this.toggleClass(this.carousel.right,"disabled",this.carousel.pos==this.carousel.overflow+1)}),animate:this.proxy(function(){this.carousel.setClasses();this.animate(this.get("thumbnails"),{to:{left:o*this.carousel.pos},duration:s.carousel_speed})})};this.carousel.setOverflow();this.setStyle(this.get("thumbnails-list"),{overflow:"hidden",position:"relative"});this.setStyle(this.get("thumbnails"),{width:t,position:"relative"});this.proxy(function(v,u){u=(typeof u=="string"&&u.toLowerCase()=="auto")?this.thumbnails.length+v.overflow:u;v.setClasses();this.loop(["left","right"],this.proxy(function(w){this.listen(v[w],"click",function(x){if(v.pos===(w=="right"?v.overflow:0)){return}v.pos=w=="right"?Math.max(v.overflow+1,v.pos-u):Math.min(0,v.pos+u);v.animate()})}))})(this.carousel,s.carousel_steps)}this.listen(this.get("image-nav-right"),"click",this.proxy(function(){this.next()}));this.listen(this.get("image-nav-left"),"click",this.proxy(function(){this.prev()}));this.trigger(l.READY)},function(){l.raise("Galleria could not load. Make sure stage has a height and width.")},5000)},addElement:function(){this.loop(arguments,function(n){this.dom[n]=this.create("div","galleria-"+n)});return this},getDimensions:function(n){return{w:n.width,h:n.height,cw:this.stageWidth,ch:this.stageHeight,top:(this.stageHeight-n.height)/2,left:(this.stageWidth-n.width)/2}},attachKeyboard:function(n){jQuery(document).bind("keydown",{map:n,scope:this},this.keyNav);return this},detachKeyboard:function(){jQuery(document).unbind("keydown",this.keyNav);return this},keyNav:function(t){var q=t.keyCode||t.which;var s=t.data.map;var r=t.data.scope;var o={UP:38,DOWN:40,LEFT:37,RIGHT:39,RETURN:13,ESCAPE:27,BACKSPACE:8};for(var p in s){var n=p.toUpperCase();if(o[n]){s[o[n]]=s[p]}}if(typeof s[q]=="function"){s[q].call(r,t)}},build:function(){this.append({"info-text":["info-title","info-description","info-author"],info:["info-link","info-text","info-close"],"image-nav":["image-nav-right","image-nav-left"],stage:["images","loader","counter","image-nav"],"thumbnails-list":["thumbnails"],"thumbnails-container":["thumb-nav-left","thumbnails-list","thumb-nav-right"],container:["stage","thumbnails-container","info"]})},appendChild:function(n,p){try{this.get(n).appendChild(this.get(p))}catch(o){}},append:function(p){for(var o in p){if(p[o].constructor==Array){for(var n=0;p[o][n];n++){this.appendChild(o,p[o][n])}}else{this.appendChild(o,p[o])}}return this},rescale:function(p,n){var o=this.proxy(function(){this.stageWidth=p||this.width(this.get("stage"));this.stageHeight=n||this.height(this.get("stage"));return this.stageWidth&&this.stageHeight});if(l.WEBKIT){this.wait(o)}else{o.call(this)}this.controls.getActive().scale(this.stageWidth,this.stageHeight,this.options.image_crop,this.options.max_scale_ratio,this.options.image_margin);if(this.carousel){this.carousel.setOverflow()}},show:function(o,n){if(!this.options.queue&&this.queue.stalled){return}n=typeof n!="undefined"?!!n:o<this.active;this.active=o;this.push([o,n],this.queue);if(!this.queue.stalled){this.showImage()}return this},showImage:function(){var t=this.options;var C=this.queue[0];var A=C[0];var x=!!C[1];if(t.carousel&&this.carousel&&t.carousel_follow){this.proxy(function(n){if(A<=Math.abs(n.pos)){n.pos=Math.max(0,(A-1))*-1;n.animate()}else{if(A>=this.thumbnails.length+n.overflow+Math.abs(n.pos)){n.pos=this.thumbnails.length+n.overflow-A-1+(A==this.thumbnails.length-1?1:0);n.animate()}}})(this.carousel)}var q=this.getData(A).image;var w=this.controls.getActive();var z=this.controls.getNext();var v=z.isCached(q);if(w.image){this.toggleQuality(w.image,false)}var s=this.proxy(function(){this.queue.stalled=false;this.toggleQuality(z.image,t.image_quality);this.setStyle(w.elem,{zIndex:0});this.setStyle(z.elem,{zIndex:1});this.moveOut(w.image);this.controls.swap();if(this.getData(A).link){this.setStyle(z.image,{cursor:"pointer"});this.listen(z.image,"click",this.proxy(function(){if(t.popup_links){var n=i.open(this.getData(A).link,"_blank")}else{i.location.href=this.getData(A).link}}))}Array.prototype.shift.call(this.queue);if(this.queue.length){this.showImage()}this.playCheck()});if(typeof t.preload=="number"&&t.preload>0){var r,u=this.getNext();try{for(var y=t.preload;y>0;y--){r=new e();r.add(this.getData(u).image);u=this.getNext(u)}}catch(B){}}this.trigger({type:l.LOADSTART,cached:v,imageTarget:z.image,thumbTarget:this.thumbnails[A].image});z.load(q,this.proxy(function(n){z.scale(this.stageWidth,this.stageHeight,t.image_crop,t.max_scale_ratio,t.image_margin,this.proxy(function(o){this.toggleQuality(z.image,false);this.trigger({type:l.LOADFINISH,cached:v,imageTarget:z.image,thumbTarget:this.thumbnails[A].image});this.queue.stalled=true;var p=l.transitions[t.transition]||t.transition;if(typeof p=="function"){p.call(this,{prev:w.image,next:z.image,rewind:x,speed:t.transition_speed||400},s)}else{s()}}));this.setInfo(A);this.get("counter").innerHTML='<span class="current">'+(A+1)+'</span> / <span class="total">'+this.thumbnails.length+"</span>"}))},getNext:function(n){n=n||this.active;return n==this.data.length-1?0:n+1},getPrev:function(n){n=n||this.active;return n===0?this.data.length-1:n-1},next:function(){if(this.data.length>1){this.show(this.getNext(),false)}return this},prev:function(){if(this.data.length>1){this.show(this.getPrev(),true)}return this},get:function(n){return this.dom[n]||false},getData:function(n){return this.data[n]||this.data[this.active]},play:function(n){this.playing=true;this.playtime=n||this.playtime;this.playCheck();return this},pause:function(){this.playing=false;return this},playCheck:function(){if(this.playing){i.clearInterval(k);k=i.setTimeout(this.proxy(function(){if(this.playing){this.next()}}),this.playtime)}},setActive:function(n){this.active=n;return this},setInfo:function(n){var o=this.getData(n);var p=this.proxy(function(){this.loop(arguments,function(r){var s=this.get("info-"+r);var q=o[r]&&o[r].length?"reveal":"hide";this[q](s);s.innerHTML=o[r]})});p("title","description","author");return this},hasInfo:function(o){var p=this.getData(o);var n=p.title+p.description+p.author;return !!n.length},getDataObject:function(p){var n={image:"",thumb:"",title:"",description:"",author:"",link:""};return p?this.mix(n,p):n},jQuery:function(p){var n=[];this.loop(p.split(","),this.proxy(function(q){q=q.replace(/^\s\s*/,"").replace(/\s\s*$/,"");if(this.get(q)){n.push(q)}}));var o=jQuery(this.get(n.shift()));this.loop(n,this.proxy(function(q){o=o.add(this.get(q))}));return o},$:function(n){return this.jQuery(n)},toggleQuality:function(n,o){if(!l.IE7||typeof n=="undefined"||!n){return this}if(typeof o==="undefined"){o=n.style.msInterpolationMode=="nearest-neighbor"}n.style.msInterpolationMode=o?"bicubic":"nearest-neighbor";return this},load:function(){var q=0;var r=this.options;if((r.data_type=="auto"&&typeof r.data_source=="object"&&!(r.data_source instanceof jQuery)&&!r.data_source.tagName)||r.data_type=="json"||r.data_source.constructor=="Array"){this.data=r.data_source;this.trigger(l.DATA)}else{var p=jQuery(r.data_source).find(r.data_image_selector);var n=this.proxy(function(u){var t,s,o=u.parentNode;if(o&&o.nodeName=="A"){if(o.href.match(/\.(png|gif|jpg)/i)){t=o.href}else{s=o.href}}var v=this.getDataObject({title:u.title,thumb:u.src,image:t||u.src,description:u.alt,link:s||u.getAttribute("longdesc"),elem:u});return this.mix(v,r.data_config(u))});this.loop(p,function(o){q++;this.push(n(o),this.data);if(!r.keep_source){o.parentNode.removeChild(o)}if(q==p.length){this.trigger(l.DATA)}})}}});l.log=function(){try{console.log.apply(console,Array.prototype.slice.call(arguments))}catch(n){try{opera.postError.apply(opera,arguments)}catch(o){alert(Array.prototype.join.call(arguments," "))}}};l.DATA="data";l.READY="ready";l.THUMBNAIL="thumbnail";l.LOADSTART="loadstart";l.LOADFINISH="loadfinish";var b=navigator.userAgent.toLowerCase();l.IE7=(i.XMLHttpRequest&&document.expando);l.IE6=(!i.XMLHttpRequest);l.IE=!!(l.IE6||l.IE7);l.WEBKIT=/webkit/.test(b);l.SAFARI=/safari/.test(b);l.CHROME=/chrome/.test(b);l.QUIRK=(l.IE&&document.compatMode&&document.compatMode=="BackCompat");l.MAC=/mac/.test(navigator.platform.toLowerCase());var a="";var d="";var m=false;var f="";l.themes={create:function(p){var q=["name","author","version","defaults","init"];var o=l.prototype;o.loop(q,function(r){if(!p[r]){l.raise(r+" not specified in theme.")}if(typeof l.themes[p.name]=="undefined"){l.themes[p.name]={}}if(r!="name"&&r!="init"){l.themes[p.name][r]=p[r]}});if(p.css){if(!a.length){var n=o.getElements("script");o.loop(n,function(s){var r=new RegExp("galleria."+p.name+".js");if(r.test(s.src)){a=s.src.replace(/[^\/]*$/,"")}})}p.cssPath=a+p.css;a=""}d=p.name;l.themes[p.name].init=function(t){if(p.cssPath){var s=o.getElements("#galleria-styles");if(s.length){s=s[0]}else{s=o.create("link");s.id="galleria-styles";s.rel="stylesheet";s.media="screen";o.getElements("head")[0].appendChild(s)}s.href=p.cssPath}if(p.cssText){o.cssText(p.cssText)}t=o.mix(l.themes[p.name].defaults,t);var r=new l(t);r.bind(l.DATA,function(){r.run()});r.bind(l.READY,function(){p.init.call(r,t);if(typeof t.extend=="function"){t.extend.call(r,t)}});r.load();return r}}};l.raise=function(n){if(l.debug){throw Error(n)}},l.loadTheme=function(n,o){m=true;a=n.replace(/[^\/]*$/,"");f=n;l.prototype.getScript(n,function(){m=false;if(typeof o=="function"){o()}})};jQuery.easing.galleria=function(o,p,n,r,q){if((p/=q/2)<1){return r/2*p*p*p*p+n}return -r/2*((p-=2)*p*p*p-2)+n};l.transitions={add:function(n,o){if(n!=arguments.callee.name){this[n]=o}},fade:function(o,n){jQuery(o.next).show().css("opacity",0).animate({opacity:1},o.speed,n);if(o.prev){jQuery(o.prev).css("opacity",1).animate({opacity:0},o.speed)}},flash:function(o,n){jQuery(o.next).css("opacity",0);if(o.prev){jQuery(o.prev).animate({opacity:0},(o.speed/2),function(){jQuery(o.next).animate({opacity:1},o.speed,n)})}else{jQuery(o.next).animate({opacity:1},o.speed,n)}},slide:function(r,o){var q=jQuery(r.next).parent();var n=this.$("images");var p=this.stageWidth;q.css({left:p*(r.rewind?-1:1)});n.animate({left:p*(r.rewind?1:-1)},{duration:r.speed,queue:false,easing:"galleria",complete:function(){n.css("left",0);q.css("left",0);o()}})},fadeslide:function(o,n){if(o.prev){jQuery(o.prev).css({opacity:1,left:0}).animate({opacity:0,left:50*(o.rewind?1:-1)},{duration:o.speed,queue:false,easing:"swing"})}jQuery(o.next).css({left:50*(o.rewind?-1:1),opacity:0}).animate({opacity:1,left:0},{duration:o.speed,complete:n,queue:false,easing:"swing"})}};l.flickr={key:null,options:{max:30,use_original:false,data_config:function(){}},setOptions:function(n){this.options=Galleria.prototype.mix(this.options,n);return this},search:function(n,q,r){this.key=n;var p={};var o=Galleria.prototype;q=o.mix({method:"flickr.photos.search",extras:"o_dims, url_t, url_m, url_o",sort:"interestingness-desc"},q);this.load(n,q,function(v){var w=v.photos.photo;var s=Math.min(this.options.max,w.length);for(var t=0;t<s;t++){var u=o.getDataObject({thumb:w[t].url_t,image:(w[t].url_o&&this.options.use_original)?w[t].url_o:w[t].url_m,title:w[t].title});o.push(o.mix(u,this.options.data_config(w[t])),p)}r(p)});return this},load:function(o,q,r){var n="http://api.flickr.com/services/rest/?";var p=this;q=$.extend({format:"json",jsoncallback:"?",api_key:o||this.key},q);jQuery.each(q,function(s,t){n+="&"+s+"="+t});jQuery.getJSON(n,function(s){if(s.stat=="ok"){r.call(p,s)}else{l.raise("Flickr data failed. Check API Key.")}});return this}};jQuery.fn.galleria=function(){var n=this.selector;var o=arguments;l.prototype.wait(function(){return !m},function(){var q=typeof o[0]=="string";var s=q?o[0]:d;var p=q?o[1]||{}:o[0]||{};p=l.prototype.mix(p,{target:n});l.debug=!!p.debug;if(typeof l.themes[s]=="undefined"){var r=s?"Theme "+s+" not found.":"No theme specified";l.raise(r);return null}else{return l.themes[s].init(p)}},function(){l.raise("Theme file "+f+" not found.")})}})();