/*
 * 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($){var settings={};$.fn.TeaserSlides=function(options){var finals={};$.fn.TeaserSlides.setup(finals,$.fn.TeaserSlides.defaults,options);var that=this;$.fn.TeaserSlides.init(this,function(){return that.each(function(){$(that).TeaserSlides.execute();});});};$.fn.TeaserSlides.defaults={pause:6000,fade:1000};$.fn.TeaserSlides.setup=function(finals,defaults,options){settings=$.extend({},finals||{},defaults||{},options||{});};$.fn.TeaserSlides.init=function(target,callback){if(typeof settings.images==='undefined')
throw Error('Image array is not optional must be passed in the call $("#id").TeaserSlides({images : ["img1.jpg", "img2.jpg"]})');settings.main=$(target);settings.loaded=new Object();settings.loaded.firstImage=true;settings.isToggle=true;var isInit=false;var initWrapper=function(){isInit=true;settings.toggle=settings.main.wrap('<span></span>').parent().css({display:'inline-block',overflow:'hidden',height:'248px',width:'658px'});settings.nextImageTimeout=0;$.fn.TeaserSlides.preloadNextImage($.fn.TeaserSlides.onLoadCallback);};settings.main.load(function(){if(isInit)
return;initWrapper();callback.call();});if(settings.main[0].complete&&!isInit){initWrapper();callback.call();}};$.fn.TeaserSlides.preloadNextImage=function(callbackOnLoad){var nextImage=$.fn.TeaserSlides.getNextImage();if('undefined'==typeof settings.loaded[nextImage]){settings.loaded[nextImage]=new Image();settings.loaded[nextImage].isLoaded=false;settings.loaded[nextImage].onload=function(){this.isLoaded=true;if(callbackOnLoad)callbackOnLoad(!settings.loaded.firstImage);settings.loaded.firstImage=false;};settings.nextImage=settings.loaded[nextImage];settings.loaded[nextImage].src=nextImage;}else{settings.nextImage=settings.loaded[nextImage];callbackOnLoad();}};$.fn.TeaserSlides.getNextImage=function(){var nextImage=settings.images.shift();settings.images.push(nextImage);return nextImage;};$.fn.TeaserSlides.onLoadCallback=function(doTransition){var d=new Date();var time=d.getTime();var doTransition='undefined'==typeof doTransition?true:doTransition;if(time>=settings.nextImageTimeout)$.fn.TeaserSlides.toggle(doTransition);else window.setTimeout(function(){$.fn.TeaserSlides.toggle(doTransition);},settings.nextImageTimeout-time);};$.fn.TeaserSlides.toggle=function(doTransition){var doTransition='undefined'==typeof doTransition?true:doTransition;var d=new Date();var time=d.getTime();var src='/templates/images/clear.gif';if(settings&&settings.nextImage&&settings.nextImage.src){src=settings.nextImage.src;}
if(settings.isToggle){settings.main.attr('src',src).animate({opacity:0.99},(doTransition?settings.fade:1),'linear',function(){settings.isToggle=false;var d=new Date();settings.nextImageTimeout=d.getTime()+settings.pause;$.fn.TeaserSlides.preloadNextImage($.fn.TeaserSlides.onLoadCallback);});}else{settings.toggle.css({background:'transparent url('+src+') left top no-repeat'});settings.main.animate({opacity:0.01},(doTransition?settings.fade:1),'linear',function(){settings.isToggle=true;var d=new Date();settings.nextImageTimeout=d.getTime()+settings.pause;$.fn.TeaserSlides.preloadNextImage($.fn.TeaserSlides.onLoadCallback);});}};$.fn.TeaserSlides.execute=function(){};})(jQuery);