/*
 * Copyright (c) 2008-2009 Olle Törnström studiomediatech.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
(function(b){var a={};b.fn.Slides=function(d){var c={};b.fn.Slides.setup(c,b.fn.Slides.defaults,d);var e=this;b.fn.Slides.init(this,function(){return e.each(function(){b(e).Slides.execute()})})};b.fn.Slides.defaults={pause:6000,fade:1000};b.fn.Slides.setup=function(c,e,d){a=b.extend({},c||{},e||{},d||{})};b.fn.Slides.init=function(d,f){if(typeof a.images==="undefined"){throw Error('Image array is not optional must be passed in the call $("#id").Slides({images : ["img1.jpg", "img2.jpg"]})')}a.main=b(d);var e=false;var c=function(){e=true;a.toggle=a.main.wrap("<span></span>").parent().css({display:"block",overflow:"hidden",height:a.main.height()+"px",width:a.main.width()+"px"});b.fn.Slides.preloadNextImage()};a.main.load(function(){if(e){return}c();f.call()});if(a.main[0].complete&&!e){c();f.call()}};b.fn.Slides.preloadNextImage=function(){var c=b.fn.Slides.getNextImage();var d=new Image();d.src=c;a.nextImage=d};b.fn.Slides.getNextImage=function(){var c=a.images.shift();a.images.push(c);return c};b.fn.Slides.execute=function(){var c=false;setInterval(function(){if(c){a.main.attr("src",a.nextImage.src).animate({opacity:1},a.fade);c=false}else{a.toggle.css({background:"transparent url("+a.nextImage.src+") left top no-repeat"});a.main.animate({opacity:0},a.fade);c=true}b.fn.Slides.preloadNextImage()},a.pause)}})(jQuery);