/*
##
##	swooshGallery
##	
##  Author: Liam Potter
##	Email:	liam@designedbyevo.com
##
##	Version:		0.8
##	Created:		27/05/09
##	Updated:		13/07/09
##
##
##	Change List:
##	0.1 - First Version (rewrite of old gallery script)
##	0.2 - Fixed pause to pause as soon as clicked
##	0.3 - Automatically insert fist large image, no need for markup
##	0.4 - Fixed auto-scroll to scroll when the last thumbnail had finished it's time
##		  Removed some useless code which put the thumbnails into groups using classes
##	0.5 - Fixed problem with finding correct offset for the hover image to appear
##	0.6 - Remembered about nth-child, got rid of now useless code
##	0.7 - a few fixes, scrolling the thumbnails now pauses
##		  Clicking a thumbnail honors the current state, if paused, it will be paused, if playing, it will play through
##	0.8 - fixed math for finding needed pages
##
##	
##	Copyright © 2009 Liam Potter
##	
##	This file is part of swooshGallery.
##
##  swooshGallery 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 3 of the License, or
##  (at your option) any later version.
##
##  swooshGallery 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 swooshGallery.  If not, see <http://www.gnu.org/licenses/>.
##	
*/
(function(a){a.fn.swoosh=function(b){var e={delay:5000,autoPlay:true,hover:true,arrow:"/assets/images/swoosh/arrow.gif",thumbs:"/assets/images/content/thumbs/",thumbsHover:"/assets/images/content/thumbs/hover/",largeImg:"/assets/images/content/"};var d=a.extend(e,b);var c=d.autoPlay;this.each(function(){var o=a(this).find("div.slider");var j=o.children("img").size();var s=o.children("img").width();var l=a(this).find("div.slider").width();var n=(Math.round(l/s)-1);if(a.browser.msie&&a.browser.version.substr(0,1)<7){var r=((s+8)*j)}else{var r=((s+6)*j)}var v=((s+6)*n);var h=((s*j)/(s*n));var h=Math.ceil(h);o.children("img").wrapAll('<div class="container" style="position:absolute;width:'+r+'px"></div>');var f=a(this).index(this);o.find("img:nth-child(7n)").next().addClass("multiple");o.find("img:last").addClass("lastImage");countIndex=0;a(this).find("div#count").html('<span id="updateThisCount">1</span>/'+j);var q=a("div#thumbnails").find("img:first").attr("src");var p=q;var p=p.replace(d.thumbs,d.largeImg);a(this).prepend('<div id="viewport"><img src="'+p+'" width="639" height="322" alt="" style="z-index:2; position:absolute;" /></div>');i();function i(){if(c==true){a("div#controls a#play").addClass("active");o.find("img").eq(countIndex).css({opacity:0.5}).animate({opacity:0.5},d.delay,function(){a(this).animate({opacity:1},500).next().animate({opacity:0.5},500,function(){countIndex++;a(this).parents("div#controls").find("span#updateThisCount").html(countIndex+1);var x=a(this).attr("src");var w=x;var w=w.replace(d.thumbs,d.largeImg);a(this).parents("div#controls").prev("div#viewport").append('<img src="'+w+'" width="639" height="322" alt="" style="display:none;position:absolute;left:0;z-index:1;top:0;">').find("img:eq(0)").animate({opacity:0},500,function(){a(this).remove()});a(this).parents("div#controls").prev("div#viewport").children("img").css({zIndex:2,display:"block",opacity:0}).animate({opacity:1},500);if(a(this).hasClass("multiple")){if(!a(this).hasClass("lastImage")){g()}else{a(this).animate({opacity:0.5},d.delay).animate({opacity:1},500,function(){m();countIndex=0;t=1;i()})}}if(a(this).hasClass("lastImage")){a(this).animate({opacity:0.5},d.delay).animate({opacity:1},500,function(){m();countIndex=0;t=1;i()})}i()})})}}function u(){if(c==false){o.find("img").eq(countIndex).stop()}}var t=1;function g(){if(t<h){o.find("div.container").animate({left:"-="+(v)+"px"},800);t++}}function k(){if(t>1){o.find("div.container").animate({left:"+="+(v)+"px"},800);t--}}function m(){o.find("div.container").animate({left:"0px"},800);a("div#count").html('<span id="updateThisCount">1</span>/'+j);t=1}a("div#controls a").click(function(){return false});a("div#controls a#pause").click(function(){c=false;u();a(this).addClass("active");a("div#controls a#play").removeClass("active")});a("div#controls a#play").click(function(){c=true;i();a(this).addClass("active");a("div#controls a#pause").removeClass("active")});a("div#controls div#thumbnails a.left").click(function(){k();c=false;u();a("div#controls a#pause").addClass("active");a("div#controls a#play").removeClass("active")});a("div#controls div#thumbnails a.right").click(function(){g();c=false;u();a("div#controls a#pause").addClass("active");a("div#controls a#play").removeClass("active")});if(d.hover==true){a("div#controls div#thumbnails div.slider div.container").find("img").each(function(){a(this).attr("id",countIndex++);a(this).hover(function(){var y=a(this).parents("div#swoosh").offset().left;var z=((a(this).offset().left-y)-47);var x=a(this).attr("src");var w=x;var w=w.replace(d.thumbs,d.thumbsHover);a(this).parents("div#swoosh").append('<div class="hover" style="left:'+z+'px"><img src="'+w+'" width="158" height="76" alt="" class="hoverImg"><img src="'+d.arrow+'" class="arrow" width="29" height="15" alt="" /></div>')},function(){a("div.hover").fadeOut(200,function(){a(this).remove()})})})}a("div#controls div#thumbnails div.slider div.container").find("img").click(function(){var w=a(this).attr("id");var w=parseFloat(w);countIndex=w;a(this).parents("div.container").find("img").each(function(){a(this).stop().css({opacity:1})});a(this).css({opacity:0.5});var y=a(this).attr("src");var x=y;var x=x.replace(d.thumbs,d.largeImg);a(this).parents("div#controls").prev("div#viewport").append('<img src="'+x+'" width="639" height="322" alt="" style="display:none;position:absolute;left:0;z-index:1;top:0;">').find("img:eq(0)").animate({opacity:0},500,function(){a(this).remove()});a(this).parents("div#controls").prev("div#viewport").children("img").css({zIndex:2,display:"block",opacity:0}).animate({opacity:1},500);a(this).parents("div#controls").find("span#updateThisCount").html(countIndex+1);i()});countIndex=0});return this}})(jQuery);
