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