/*
    Yet Another Gallery for jQuery (aka YAG) 1.0
    Copyright (C) 2008-9  Hervé "Setaou" BRY

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
(function(){YAG=window.YAG=function(l,p){l=$(l);var j={viewportPosition:"top",infoBoxPosition:"bottom",infoBoxOpacity:0.8,infoBoxAutoShow:"normal",infoBoxAutoHideDelay:5000,buttonsFade:true,buttonsFadeDuration:200,spinnersFade:true,spinnersFadeDuration:200,transitionDuration:1500,centerThumbnails:true,squareThumbnails:false,thumbnailsOpacity:0.5,thumbnailsFadeDuration:200,realSizeOverlayOpacity:0.8,realSizeFadeDuration:1000};this.options=$.extend(j,p||{});if(l.length!=1){throw new String("Only one element should be given to the gallery constructor. To create several galleries at a time, use $(selector).YAG(options).")}else{if(l.get(0).tagName!="UL"){throw new String("The element given to the gallery constructor is not an unordered list (UL).")}else{if(l.find("li a img").length==0){throw new String("The element does not match the needed structure (UL > LI > A > IMG).")}else{if(!!(l.get(0).YAG)){throw new String("A YAG gallery has already been created for that element.")}}}}var q=l.get(0).YAG=this;l.wrap($("<div></div>"));var n=q.root=l.parent();n.get(0).className=l.get(0).className;l.get(0).className="";n.find("ul").css({width:1000000});n.find("ul").wrap($("<div></div>").addClass("YAG-thumbs"));n.find("ul").css("visibility","hidden");n.find("li img").css("opacity",q.options.thumbnailsOpacity);n.find(".YAG-thumbs").prepend($("<div></div>").css({display:"none"}).addClass("YAG-button-forward"));n.find(".YAG-thumbs").prepend($("<div></div>").css({display:"none"}).addClass("YAG-button-backward"));if(this.options.buttonsFade){n.find(".YAG-button-backward,.YAG-button-forward").css({opacity:0})}var m=$("<div></div>").addClass("YAG-viewport");var h=$("<div></div>").addClass("YAG-infobox");var k=$("<div></div>").addClass("YAG-infobox-content");var i=$("<div></div>").addClass("YAG-infobox-overlay");var f=$("<div></div>").addClass("YAG-title");var o=$("<div></div>").addClass("YAG-description");i.css("opacity",this.options.infoBoxOpacity).appendTo(h);k.appendTo(h);if(this.options.infoBoxPosition=="bottom"){k.append(f).append(o)}else{k.append(o).append(f)}h.prependTo(m);if(this.options.viewportPosition=="bottom"){n.append(m)}else{n.prepend(m)}if(this.options.infoBoxPosition=="bottom"){h.css({top:h.parent().height()})}else{h.css({bottom:h.parent().height()})}b(n.find(".YAG-thumbs"),this.options.spinnersFade,this.options.spinnersFadeDuration);if($().mousewheel){n.find("ul").mousewheel(function(r,s){q.slide(-Math.ceil(s));return false},false,true)}n.find("ul").keydown(function(r){switch(r.which){case 32:q.show($(this).children("li.YAG-current").next());return false;break;case 35:q.show($(this).children("li:last"));return false;break;case 36:YAG.show($(this).children("li:first"));return false;break;case 37:q.show($(this).children("li.YAG-current").prev());return false;break;case 39:q.show($(this).children("li.YAG-current").next());return false;break}});n.find("li").hover(function(){$(this).not(".YAG-current").find("img").stop(true).animate({opacity:"1"},q.options.thumbnailsFadeDuration)},function(){$(this).not(".YAG-current").find("img").animate({opacity:q.options.thumbnailsOpacity},q.options.thumbnailsFadeDuration)});n.find("li").click(function(){q.show(this);return false});n.find("div.YAG-button-backward").click(function(){q.slide(-5);return false});n.find("div.YAG-button-forward").click(function(){q.slide(+5);return false});n.find(".YAG-viewport").resize(function(){var r=$(this).find("img:last");q.slide(0);d(r);a(r)});n.find(".YAG-viewport").hover(function(){q.showInfoBox()},function(){q.showInfoBox("hide")});n.find(".YAG-infobox").hover(function(){q.showInfoBox("full")},function(){q.showInfoBox()});this._position=0;this._infoBoxEnabled=false;var g=function(){if(q._checkThumbnailsLoaded()){q._layoutThumbnails();q.show(0)}else{setTimeout(g,200)}};g()};YAG.prototype={next:function(f){var g=this.root.find("li.YAG-current").next();if(g.length==0){if(f){g=this.root.find("li:first")}else{return}}this.show(g)},previous:function(f){var g=this.root.find("li.YAG-current").prev();if(g.length==0){if(f){g=this.root.find("li:last")}else{return}}this.show(g)},slide:function(h){var f=this.root.find("li").length;var l=this.root.find(".YAG-thumbs").width();var m=this.root.find("li:last");var g=m.position().left+m.outerWidth();var k=this._position+h;if(k<0){k=0}else{if(k>=f){k=f-1}}this._position=k;var i=this.root.find("li").eq(k);var h=l/2-i.position().left-i.outerWidth()/2;if(h>0){h=0}else{if(h<l-g){h=l-g}}var n=(h<0)?1:0;var j=(h>l-g)?1:0;this._enableButtons(n,j);this.root.find(".YAG-thumbs ul").stop().animate({left:h},"slow")},slideTo:function(g){var f=(typeof g=="number")?g:$(g).prevAll().length;var h=f-this._position;this.slide(h)},show:function(k){if(typeof k=="number"){k=this.root.find("li").get(k)}var i=this;var g=this.root.children(".YAG-viewport");var f=$(g).children(".YAG-infobox");var l=$(k).find("a").attr("href");var m=$(k).find("img").attr("title");var h=$(k).find("img").attr("longdesc");if(g.children("img:last").attr("src")==l){return}$(k).siblings(".YAG-current").removeClass("YAG-current").find("img").animate({opacity:this.options.thumbnailsOpacity},this.options.thumbnailsFadeDuration);$(k).addClass("YAG-current").find("img").animate({opacity:"1"},"fast");this.slideTo(k);b(g,i.options.spinnersFade,i.options.spinnersFadeDuration);g.children("img").unbind("load");var j=$("<img />").css({opacity:0,position:"absolute",cursor:"pointer"}).appendTo(g);j.bind("load",function(){c(g,i.options.spinnersFade,i.options.spinnersFadeDuration);$(this).siblings("img").stop().animate({opacity:0},i.options.transitionDuration,"",function(){$(this).remove()});d(this);a(this);$(this).animate({opacity:1},i.options.transitionDuration);i._enableInfoBox(false);i.showInfoBox("hide",function(){f.find(".YAG-title").text(m);if((h!=null)&&(h.length!="")){$.get(h,function(n){f.find(".YAG-description").html(n);i._enableInfoBox(true);if(i.options.infoBoxAutoShow!="no"){i.showInfoBox(i.options.infoBoxAutoShow,function(){f.get(0).autoHide=setTimeout(function(){i.showInfoBox("hide")},i.options.infoBoxAutoHideDelay)})}})}else{setTimeout(function(){f.find(".YAG-description").html("");i._enableInfoBox(true);if(i.options.infoBoxAutoShow!="no"){i.showInfoBox(i.options.infoBoxAutoShow,function(){f.get(0).autoHide=setTimeout(function(){i.showInfoBox("hide")},i.options.infoBoxAutoHideDelay)})}},0)}})});j.attr("src",l);this.currentIndex=$(k).prevAll().length;j.click(function(){i.realSize()})},_checkThumbnailsLoaded:function(){var h=this.root.find(".YAG-thumbs img").get();var f=0;for(var g=0;g<h.length;g++){if(h[g].complete||h[g].readyState=="complete"){f++}}if(f==h.length){return true}else{return false}},_layoutThumbnails:function(){var g=0,n=0;var o=this.root.find(".YAG-thumbs img").get();for(var l=0;l<o.length;l++){var k=$(o[l]);var m=k.height();var j=k.width();if(m>g){g=m}if(j>n){n=j}}var f=this.root.find("li");f.height(g);if(this.options.squareThumbnails){f.width(n)}if(this.options.centerThumbnails){for(var l=0;l<o.length;l++){a(o[l])}}this.root.find(".YAG-thumbs ul").css("visibility","visible");c(this.root.find(".YAG-thumbs"),this.options.spinnersFade,this.options.spinnersFadeDuration)},realSize:function(){var g=this;var f=$("<div></div>").addClass("YAG-realsize").prependTo("body");var i=$("<div></div>").css({opacity:this.options.realSizeOverlayOpacity,height:$(document).height(),width:$(document).width(),position:"absolute",top:0,left:0,display:"none"}).addClass("YAG-overlay").appendTo(f);var k=$("<div></div>").css({position:"absolute",display:"none"}).addClass("YAG-frame").appendTo(f);var h=this.root.find(".YAG-viewport>img:last").clone().css({width:"auto",height:"auto",position:"static",opacity:1}).appendTo(k);var j=this.root.find(".YAG-title").clone().appendTo(k);e(k);h.click(function(){$(this).parent().fadeOut(g.options.realSizeFadeDuration/2).queue(function(){$(this).parent().fadeOut(g.options.realSizeFadeDuration/2).queue(function(){$(this).dequeue().remove()});$(this).dequeue()})});i.click(function(){$(this).parent().find("img").click()});i.fadeIn(g.options.realSizeFadeDuration/2).queue(function(){$(this).siblings().fadeIn(g.options.realSizeFadeDuration/2);$(this).dequeue()})},_enableInfoBox:function(f){this._infoBoxEnabled=f},showInfoBox:function(h,j){h=h||"normal";var f=this.root.find(".YAG-infobox");var g=this._infoBoxEnabled;var i=0;clearTimeout(f.get(0).autoHide);if((h=="full")&&(f.find(".YAG-description").html().length!=0)){if(!g){return}i=f.find(".YAG-title").outerHeight()+f.find(".YAG-description").outerHeight()}else{if((h!="hide")&&(f.find(".YAG-title").text().length!=0)){if(!g){return}i=f.find(".YAG-title").outerHeight()}}if(this.options.infoBoxPosition=="bottom"){f.stop(true).animate({top:f.parent().height()-i},"fast",null,j)}else{f.stop(true).animate({bottom:f.parent().height()-i},"fast",null,j)}},_enableButtons:function(g,f){if(this.options.buttonsFade){if(g){this.root.find(".YAG-button-backward").stop(true).css({display:"block"}).animate({opacity:1},this.options.buttonsFadeDuration)}else{this.root.find(".YAG-button-backward").stop(true).animate({opacity:0},this.options.buttonsFadeDuration,null,function(){$(this).css({display:"none"})})}if(f){this.root.find(".YAG-button-forward").stop(true).css({display:"block"}).animate({opacity:1},this.options.buttonsFadeDuration)}else{this.root.find(".YAG-button-forward").stop(true).animate({opacity:0},this.options.buttonsFadeDuration,null,function(){$(this).css({display:"none"})})}}else{this.root.find(".YAG-button-backward").css({display:g?"block":"none"});this.root.find(".YAG-button-forward").css({display:f?"block":"none"})}}};$.fn.YAG=function(g){var f=new Array();this.each(function(){f.push(new YAG(this,g))});return f};function a(g){var f=$(g);var h=f.parents(":not(a):first");f.css({left:h.width()/2-f.outerWidth(true)/2,top:h.height()/2-f.outerHeight(true)/2})}function e(h){var g=$(h);var f=$(document);g.css({left:getViewportSize().width/2-g.outerWidth()/2+f.scrollLeft(),top:getViewportSize().height/2-g.outerHeight()/2+f.scrollTop()})}function d(j,g){var n=$(j);var h=n.parents(":not(a):first");var k=parseFloat(0+n.css("margin-top"));var m=parseFloat(0+n.css("margin-bottom"));var o=parseFloat(0+n.css("margin-left"));var i=parseFloat(0+n.css("margin-right"));if(!(n.data("realHeight"))){n.data("realHeight",n.height()).data("realWidth",n.width())}var f=h.innerWidth()/n.data("realWidth");var l=h.innerHeight()/n.data("realHeight");var q=Math.min(f,l);if((q>1)&&!g){q=1}if(q==l){n.height(n.data("realHeight")*q-k-m)}else{n.width(n.data("realWidth")*q-o-i)}}getViewportSize=function(){if(typeof window.innerWidth!="undefined"){return{width:window.innerWidth,height:window.innerHeight}}else{if(typeof document.documentElement!="undefined"&&typeof document.documentElement.clientWidth!="undefined"&&document.documentElement.clientWidth!=0){return{width:document.documentElement.clientWidth,height:document.documentElement.clientHeight}}else{return{width:document.getElementsByTagName("body")[0].clientWidth,height:document.getElementsByTagName("body")[0].clientHeight}}}};function b(g,i,f){if($(g).children(".YAG-spinner").length!=0){return}var h=$("<div />").addClass("YAG-spinner");if(i){h.css({opacity:0})}$(g).prepend(h);if(i){h.stop(true).animate({opacity:1},f||"fast")}}function c(g,i,f){var h=$(g).children(".YAG-spinner");if(i){h.stop(true).animate({opacity:0},f||"fast",null,function(){$(this).remove()})}else{h.remove()}}})();
/* jQuery Mousewheel Extension
*
* Copyright (c) 2008 Brandon Aaron (http://brandonaaron.net)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
* Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
* Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
*
* Version: 3.0.1-pre
*
* Requires: 1.2.2+
*/
(function(a){a.event.special.mousewheel={setup:function(){var b=a.event.special.mousewheel.handler;if(a.browser.mozilla){a(this).bind("mousemove.mousewheel",function(c){a.data(this,"mwcursorposdata",{pageX:c.pageX,pageY:c.pageY,clientX:c.clientX,clientY:c.clientY})})}if(this.addEventListener){this.addEventListener((a.browser.mozilla?"DOMMouseScroll":"mousewheel"),b,false)}else{this.onmousewheel=b}},teardown:function(){var b=a.event.special.mousewheel.handler;a(this).unbind("mousemove.mousewheel");if(this.removeEventListener){this.removeEventListener((a.browser.mozilla?"DOMMouseScroll":"mousewheel"),b,false)}else{this.onmousewheel=function(){}}a.removeData(this,"mwcursorposdata")},handler:function(d){var b=Array.prototype.slice.call(arguments,1);d=a.event.fix(d||window.event);a.extend(d,a.data(this,"mwcursorposdata")||{});var e=0,c=true;if(d.wheelDelta){if(a.browser.msie){e=d.wheelDelta/=30}else{if(a.browser.safari){e=d.wheelDelta/=360}else{if(a.browser.opera){e=d.wheelDelta/=250}}}}else{if(d.detail){e=-d.detail/3}}d.data=d.data||{};d.type="mousewheel";b.unshift(e);b.unshift(d);return a.event.handle.apply(this,b)}};a.fn.extend({mousewheel:function(b){return b?this.bind("mousewheel",b):this.trigger("mousewheel")},unmousewheel:function(b){return this.unbind("mousewheel",b)}})})(jQuery);