/**
 * jQuery.timers - Timer abstractions for jQuery
 * Written by Blair Mitchelmore (blair DOT mitchelmore AT gmail DOT com)
 * Licensed under the WTFPL (http://sam.zoy.org/wtfpl/).
 * Date: 2009/02/08
 *
 * @author Blair Mitchelmore
 * @version 1.1.2
 *
 **/

/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

/*
 *
 * TERMS OF USE - EASING EQUATIONS
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2001 Robert Penner
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
 */

/*

	GalleryView - jQuery Content Gallery Plugin
	Author: 		Jack Anderson
	Version:		1.1 (April 5, 2009)
	Documentation: 	http://www.spaceforaname.com/jquery/galleryview/
	
	Please use this development script if you intend to make changes to the
	plugin code.  For production sites, please use jquery.galleryview-1.0.1-pack.js.
	
*/

jQuery.fn.extend({everyTime:function(b,c,d,e,a){return this.each(function(){jQuery.timer.add(this,b,c,d,e,a)})},oneTime:function(a,b,c){return this.each(function(){jQuery.timer.add(this,a,b,c,1)})},stopTime:function(a,b){return this.each(function(){jQuery.timer.remove(this,a,b)})}});jQuery.event.special;jQuery.extend({timer:{global:[],guid:1,dataKey:"jQuery.timer",regex:/^([0-9]+(?:\.[0-9]*)?)\s*(.*s)?$/,powers:{ms:1,cs:10,ds:100,s:1000,das:10000,hs:100000,ks:1000000},timeParse:function(c){if(c==undefined||c==null){return null}var a=this.regex.exec(jQuery.trim(c.toString()));if(a[2]){var b=parseFloat(a[1]);var d=this.powers[a[2]]||1;return b*d}else{return c}},add:function(e,c,h,g,b,f){var a=0;if(jQuery.isFunction(h)){if(!b){b=g}g=h;h=c}c=jQuery.timer.timeParse(c);if(typeof c!="number"||isNaN(c)||c<=0){return}if(b&&b.constructor!=Number){f=!!b;b=0}b=b||0;f=f||false;var d=jQuery.data(e,this.dataKey)||jQuery.data(e,this.dataKey,{});if(!d[h]){d[h]={}}g.timerID=g.timerID||this.guid++;var i=function(){if(f&&this.inProgress){return}this.inProgress=true;if((++a>b&&b!==0)||g.call(e,a)===false){jQuery.timer.remove(e,h,g)}this.inProgress=false};i.timerID=g.timerID;if(!d[h][g.timerID]){d[h][g.timerID]=window.setInterval(i,c)}this.global.push(e)},remove:function(c,b,d){var e=jQuery.data(c,this.dataKey),a;if(e){if(!b){for(b in e){this.remove(c,b,d)}}else{if(e[b]){if(d){if(d.timerID){window.clearInterval(e[b][d.timerID]);delete e[b][d.timerID]}}else{for(var d in e[b]){window.clearInterval(e[b][d]);delete e[b][d]}}for(a in e[b]){break}if(!a){a=null;delete e[b]}}}for(a in e){break}if(!a){jQuery.removeData(c,this.dataKey)}}}}});jQuery(window).bind("unload",function(){jQuery.each(jQuery.timer.global,function(a,b){jQuery.timer.remove(b)})});jQuery.easing.jswing=jQuery.easing.swing;jQuery.extend(jQuery.easing,{def:"easeOutQuad",swing:function(e,f,a,h,g){return jQuery.easing[jQuery.easing.def](e,f,a,h,g)},easeInQuad:function(e,f,a,h,g){return h*(f/=g)*f+a},easeOutQuad:function(e,f,a,h,g){return -h*(f/=g)*(f-2)+a},easeInOutQuad:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f+a}return -h/2*((--f)*(f-2)-1)+a},easeInCubic:function(e,f,a,h,g){return h*(f/=g)*f*f+a},easeOutCubic:function(e,f,a,h,g){return h*((f=f/g-1)*f*f+1)+a},easeInOutCubic:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f+a}return h/2*((f-=2)*f*f+2)+a},easeInQuart:function(e,f,a,h,g){return h*(f/=g)*f*f*f+a},easeOutQuart:function(e,f,a,h,g){return -h*((f=f/g-1)*f*f*f-1)+a},easeInOutQuart:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f*f+a}return -h/2*((f-=2)*f*f*f-2)+a},easeInQuint:function(e,f,a,h,g){return h*(f/=g)*f*f*f*f+a},easeOutQuint:function(e,f,a,h,g){return h*((f=f/g-1)*f*f*f*f+1)+a},easeInOutQuint:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f*f*f+a}return h/2*((f-=2)*f*f*f*f+2)+a},easeInSine:function(e,f,a,h,g){return -h*Math.cos(f/g*(Math.PI/2))+h+a},easeOutSine:function(e,f,a,h,g){return h*Math.sin(f/g*(Math.PI/2))+a},easeInOutSine:function(e,f,a,h,g){return -h/2*(Math.cos(Math.PI*f/g)-1)+a},easeInExpo:function(e,f,a,h,g){return(f==0)?a:h*Math.pow(2,10*(f/g-1))+a},easeOutExpo:function(e,f,a,h,g){return(f==g)?a+h:h*(-Math.pow(2,-10*f/g)+1)+a},easeInOutExpo:function(e,f,a,h,g){if(f==0){return a}if(f==g){return a+h}if((f/=g/2)<1){return h/2*Math.pow(2,10*(f-1))+a}return h/2*(-Math.pow(2,-10*--f)+2)+a},easeInCirc:function(e,f,a,h,g){return -h*(Math.sqrt(1-(f/=g)*f)-1)+a},easeOutCirc:function(e,f,a,h,g){return h*Math.sqrt(1-(f=f/g-1)*f)+a},easeInOutCirc:function(e,f,a,h,g){if((f/=g/2)<1){return -h/2*(Math.sqrt(1-f*f)-1)+a}return h/2*(Math.sqrt(1-(f-=2)*f)+1)+a},easeInElastic:function(f,h,e,l,k){var i=1.70158;var j=0;var g=l;if(h==0){return e}if((h/=k)==1){return e+l}if(!j){j=k*0.3}if(g<Math.abs(l)){g=l;var i=j/4}else{var i=j/(2*Math.PI)*Math.asin(l/g)}return -(g*Math.pow(2,10*(h-=1))*Math.sin((h*k-i)*(2*Math.PI)/j))+e},easeOutElastic:function(f,h,e,l,k){var i=1.70158;var j=0;var g=l;if(h==0){return e}if((h/=k)==1){return e+l}if(!j){j=k*0.3}if(g<Math.abs(l)){g=l;var i=j/4}else{var i=j/(2*Math.PI)*Math.asin(l/g)}return g*Math.pow(2,-10*h)*Math.sin((h*k-i)*(2*Math.PI)/j)+l+e},easeInOutElastic:function(f,h,e,l,k){var i=1.70158;var j=0;var g=l;if(h==0){return e}if((h/=k/2)==2){return e+l}if(!j){j=k*(0.3*1.5)}if(g<Math.abs(l)){g=l;var i=j/4}else{var i=j/(2*Math.PI)*Math.asin(l/g)}if(h<1){return -0.5*(g*Math.pow(2,10*(h-=1))*Math.sin((h*k-i)*(2*Math.PI)/j))+e}return g*Math.pow(2,-10*(h-=1))*Math.sin((h*k-i)*(2*Math.PI)/j)*0.5+l+e},easeInBack:function(e,f,a,i,h,g){if(g==undefined){g=1.70158}return i*(f/=h)*f*((g+1)*f-g)+a},easeOutBack:function(e,f,a,i,h,g){if(g==undefined){g=1.70158}return i*((f=f/h-1)*f*((g+1)*f+g)+1)+a},easeInOutBack:function(e,f,a,i,h,g){if(g==undefined){g=1.70158}if((f/=h/2)<1){return i/2*(f*f*(((g*=(1.525))+1)*f-g))+a}return i/2*((f-=2)*f*(((g*=(1.525))+1)*f+g)+2)+a},easeInBounce:function(e,f,a,h,g){return h-jQuery.easing.easeOutBounce(e,g-f,0,h,g)+a},easeOutBounce:function(e,f,a,h,g){if((f/=g)<(1/2.75)){return h*(7.5625*f*f)+a}else{if(f<(2/2.75)){return h*(7.5625*(f-=(1.5/2.75))*f+0.75)+a}else{if(f<(2.5/2.75)){return h*(7.5625*(f-=(2.25/2.75))*f+0.9375)+a}else{return h*(7.5625*(f-=(2.625/2.75))*f+0.984375)+a}}}},easeInOutBounce:function(e,f,a,h,g){if(f<g/2){return jQuery.easing.easeInBounce(e,f*2,0,h,g)*0.5+a}return jQuery.easing.easeOutBounce(e,f*2-g,0,h,g)*0.5+h*0.5+a}});(function(a){a.fn.galleryView=function(d){var o=a.extend(a.fn.galleryView.defaults,d);var s;var r=0;var i;var u;var k=10;var f;var B;var n=0;var D;var v;var A=false;var z=20;var p=5;var e=2;var C;var w;var y;var l;var q;function j(E){a("img.nav-next").unbind("click");a("img.nav-prev").unbind("click");y.unbind("click");if(has_panels){if(o.fade_panels){l.fadeOut(o.transition_speed).eq(E%n).fadeIn(o.transition_speed,function(){if(!has_filmstrip){a("img.nav-prev").click(c);a("img.nav-next").click(t)}})}}if(has_filmstrip){if(D=="strip"){w.stop();var H=x(y[E]).left-(x(q[0]).left+2);var F=(H>=0?"-=":"+=")+Math.abs(H)+"px";w.animate({left:F},o.transition_speed,o.easing,function(){if(E>n){E=E%n;r=E;w.css("left","-"+((o.frame_width+k)*E)+"px")}else{if(E<=(n-strip_size)){E=(E%n)+n;r=E;w.css("left","-"+((o.frame_width+k)*E)+"px")}}if(!o.fade_panels){l.hide().eq(E%n).show()}a("img.nav-prev").click(c);a("img.nav-next").click(t);m()})}else{if(D=="pointer"){q.stop();var G=x(y[E]);q.animate({left:(G.left-2+"px")},o.transition_speed,o.easing,function(){if(!o.fade_panels){l.hide().eq(E%n).show()}a("img.nav-prev").click(c);a("img.nav-next").click(t);m()})}}if(a("a",y[E])[0]){q.unbind("click").click(function(){var I=a("a",y[E]).eq(0);if(I.attr("target")=="_blank"){window.open(I.attr("href"))}else{location.href=I.attr("href")}})}}}function t(){a(document).stopTime("transition");if(++r==y.length){r=0}j(r);a(document).everyTime(o.transition_interval,"transition",function(){t()})}function c(){a(document).stopTime("transition");if(--r<0){r=n-1}j(r);a(document).everyTime(o.transition_interval,"transition",function(){t()})}function x(H){var K=0,J=0;var E=H.id;if(H.offsetParent){do{K+=H.offsetLeft;J+=H.offsetTop}while(H=H.offsetParent)}if(E==s){return{left:K,top:J}}else{var G=x(C[0]);var I=G.left;var F=G.top;return{left:K-I,top:J-F}}}function m(){y.each(function(E){if(a("a",this).length==0){a(this).click(function(){a(document).stopTime("transition");j(E);r=E;a(document).everyTime(o.transition_interval,"transition",function(){t()})})}})}function h(){if(a(".panel-overlay").length>0){l.append('<div class="overlay"></div>')}if(!has_filmstrip){a("<img />").addClass("nav-next").attr("src","/images/next.png").appendTo(C).css({position:"absolute",zIndex:"1100",cursor:"pointer",top:((o.panel_height-22)/2)+"px",right:"10px",display:"none"}).click(t);a("<img />").addClass("nav-prev").attr("src","/images/prev.png").appendTo(C).css({position:"absolute",zIndex:"1100",cursor:"pointer",top:((o.panel_height-22)/2)+"px",left:"10px",display:"none"}).click(c);a("<img />").addClass("nav-overlay").attr("src","/images/panel-nav-next.png").appendTo(C).css({position:"absolute",zIndex:"1099",top:((o.panel_height-22)/2)-10+"px",right:"0",display:"none"});a("<img />").addClass("nav-overlay").attr("src","/images/panel-nav-prev.png").appendTo(C).css({position:"absolute",zIndex:"1099",top:((o.panel_height-22)/2)-10+"px",left:"0",display:"none"})}l.css({width:(o.panel_width-parseInt(l.css("paddingLeft").split("px")[0],10)-parseInt(l.css("paddingRight").split("px")[0],10))+"px",height:(o.panel_height-parseInt(l.css("paddingTop").split("px")[0],10)-parseInt(l.css("paddingBottom").split("px")[0],10))+"px",position:"absolute",top:(o.filmstrip_position=="top"?(o.frame_height+p+(o.show_captions?z:p))+"px":"0px"),left:"0px",overflow:"hidden",background:"white",display:"none"});a(".panel-overlay",l).css({position:"absolute",zIndex:"999",width:(o.panel_width-20)+"px",height:o.overlay_height+"px",top:(o.overlay_position=="top"?"0":o.panel_height-o.overlay_height+"px"),left:"0",padding:"0 10px",color:o.overlay_text_color,fontSize:o.overlay_font_size});a(".panel-overlay a",l).css({color:o.overlay_text_color,textDecoration:"underline",fontWeight:"bold"});a(".overlay",l).css({position:"absolute",zIndex:"998",width:o.panel_width+"px",height:o.overlay_height+"px",top:(o.overlay_position=="top"?"0":o.panel_height-o.overlay_height+"px"),left:"0",background:o.overlay_color,opacity:o.overlay_opacity});a(".panel iframe",l).css({width:o.panel_width+"px",height:(o.panel_height-o.overlay_height)+"px",border:"0"})}function g(){w.wrap('<div class="strip_wrapper"></div>');if(D=="strip"){y.clone().appendTo(w);y.clone().appendTo(w);y=a("li",w)}if(o.show_captions){y.append('<div class="caption"></div>').each(function(G){a(this).find(".caption").html(a(this).find("img").attr("title"))})}w.css({listStyle:"none",margin:"0",padding:"0",width:f+"px",position:"absolute",zIndex:"900",top:"0",left:"0",height:(o.frame_height+10)+"px",background:o.background_color});y.css({"float":"left",position:"relative",height:o.frame_height+"px",zIndex:"901",marginTop:p+"px",marginBottom:"0px",marginRight:k+"px",padding:"0",cursor:"pointer"});a("img",y).css({border:"none"});a(".strip_wrapper",C).css({position:"absolute",top:(o.filmstrip_position=="top"?"0px":o.panel_height+"px"),left:((i-B)/2)+"px",width:B+"px",height:(o.frame_height+p+(o.show_captions?z:p))+"px",overflow:"hidden"});a(".caption",C).css({position:"absolute",top:o.frame_height+"px",left:"0",margin:"0",width:o.frame_width+"px",padding:"0",color:o.caption_text_color,textAlign:"center",fontSize:"10px",height:z+"px",lineHeight:z+"px"});var F=a("<div></div>");F.attr("id","pointer").appendTo(C).css({position:"absolute",zIndex:"1000",cursor:"pointer",top:x(y[0]).top-(e/2)+"px",left:x(y[0]).left-(e/2)+"px",height:o.frame_height-e+"px",width:o.frame_width-e+"px",border:(has_panels?e+"px solid "+(o.nav_theme=="dark"?"black":"white"):"none")});q=a("#pointer",C);if(has_panels){var E=a("<img />");E.attr("src","/images/pointer"+(o.filmstrip_position=="top"?"-down":"")+".png").appendTo(a("#pointer")).css({position:"absolute",zIndex:"1001",top:(o.filmstrip_position=="bottom"?"-"+(10+e)+"px":o.frame_height+"px"),left:((o.frame_width/2)-10)+"px"})}if(D=="strip"){w.css("left","-"+((o.frame_width+k)*n)+"px");r=n}if(a("a",y[r])[0]){q.click(function(){var G=a("a",y[r]).eq(0);if(G.attr("target")=="_blank"){window.open(G.attr("href"))}else{location.href=G.attr("href")}})}a("<img />").addClass("nav-next").attr("src","/images/next.png").appendTo(C).css({position:"absolute",cursor:"pointer",top:(o.filmstrip_position=="top"?0:o.panel_height)+p+((o.frame_height-22)/2)+"px",right:(i/2)-(B/2)-10-22+"px"}).click(t);a("<img />").addClass("nav-prev").attr("src","/images/prev.png").appendTo(C).css({position:"absolute",cursor:"pointer",top:(o.filmstrip_position=="top"?0:o.panel_height)+p+((o.frame_height-22)/2)+"px",left:(i/2)-(B/2)-10-22+"px"}).click(c)}function b(E,I){var H=x(C[0]);var G=H.top;var F=H.left;return E>F&&E<F+o.panel_width&&I>G&&I<G+o.panel_height}return this.each(function(){C=a(this);a("script").each(function(E){var F=a(this);if(F.attr("src")&&F.attr("src").match(/jquery\.galleryview/)){v=F.attr("src").split("jquery.galleryview")[0]+"themes/"}});C.css("visibility","hidden");w=a(".filmstrip",C);y=a("li",w);l=a(".panel",C);s=C.attr("id");has_panels=l.length>0;has_filmstrip=y.length>0;if(!has_panels){o.panel_height=0}n=has_panels?l.length:y.length;strip_size=has_panels?Math.floor((o.panel_width-64)/(o.frame_width+k)):Math.min(n,o.filmstrip_size);if(strip_size>=n){D="pointer";strip_size=n}else{D="strip"}i=has_panels?o.panel_width:(strip_size*(o.frame_width+k))-k+64;u=(has_panels?o.panel_height:0)+(has_filmstrip?o.frame_height+p+(o.show_captions?z:p):0);if(D=="pointer"){f=(o.frame_width*n)+(k*(n))}else{f=(o.frame_width*n*3)+(k*(n*3))}B=((strip_size*o.frame_width)+((strip_size-1)*k));C.css({position:"relative",margin:"0",background:o.background_color,border:o.border,width:i+"px",height:u+"px"});if(has_filmstrip){g()}if(has_panels){h()}if(has_filmstrip){m()}a().mousemove(function(E){if(b(E.pageX,E.pageY)){if(o.pause_on_hover){a(document).oneTime(500,"animation_pause",function(){a(document).stopTime("transition");A=true})}if(has_panels&&!has_filmstrip){a(".nav-overlay").fadeIn("fast");a(".nav-next").fadeIn("fast");a(".nav-prev").fadeIn("fast")}}else{if(o.pause_on_hover){a(document).stopTime("animation_pause");if(A){a(document).everyTime(o.transition_interval,"transition",function(){t()});A=false}}if(has_panels&&!has_filmstrip){a(".nav-overlay").fadeOut("fast");a(".nav-next").fadeOut("fast");a(".nav-prev").fadeOut("fast")}}});l.eq(0).show();if(n>1){a(document).everyTime(o.transition_interval,"transition",function(){t()})}C.css("visibility","visible")})};a.fn.galleryView.defaults={panel_width:400,panel_height:300,frame_width:80,frame_height:80,filmstrip_size:3,overlay_height:55,overlay_font_size:"1em",transition_speed:400,transition_interval:6000,overlay_opacity:0.6,overlay_color:"black",background_color:"black",overlay_text_color:"white",caption_text_color:"white",border:"1px solid black",nav_theme:"light",easing:"swing",filmstrip_position:"bottom",overlay_position:"bottom",show_captions:false,fade_panels:true,pause_on_hover:false}})(jQuery);
