// plugin jquery.slide
// (c)2008-2009 Olle Toernstroem
// http://www.studiomediatech.com/slides/

/*
 * The MIT License   	
 *
 * 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 slideshow;
	var controllers = '<span id="toggle" style="position: absolute; top: 10px; left: 10px; z-index: 10000;"><a id="pause" href="#"><img src="beeld/control_pause.png" alt=""></a><a id="resume" style="display: none;" href="#"><img src="beeld/control_play.png" alt=""></a></span>';
	
	var settings = {};

	$.fn.Slides = function(options) {
		var finals = {};
		$.fn.Slides.setup(finals, $.fn.Slides.defaults, options);
		var that = this;
		$.fn.Slides.init(this, function() {
			return that.each(function() {
				$(that).Slides.execute();
			});
		});
	};

	$.fn.Slides.defaults = {
		pause : 6000,
		fade : 1000
	};	

	$.fn.Slides.setup = function(finals, defaults, options) {
		settings = $.extend({}, finals || {}, defaults || {}, options || {});
	};		
	
	$.fn.Slides.init = function(target, callback) {		
		if (typeof settings.images === 'undefined')
			return false;
		settings.main = $(target);
		var isInit = false;
		var initWrapper = function() {
			isInit = true;
			settings.toggle = settings.main.wrap('<span></span>')
					.parent()
					.css({ position : 'relative', display : 'inline-block', overflow : 'hidden', height : settings.main.height() + 'px', width : settings.main.width() + 'px'})
					.append(controllers);
			$.fn.Slides.preloadNextImage();
		};
		settings.main.load(function() {
			if (isInit)
				return;
			initWrapper();
			callback.call();
		});		
		if (settings.main[0].complete && !isInit) {
			initWrapper();
			callback.call();
		}
	};
	
	$.fn.Slides.preloadNextImage = function() {
		var nextImage = $.fn.Slides.getNextImage();
		var image = new Image();
		image.src = nextImage;
		settings.nextImage = image;
	};

	$.fn.Slides.getNextImage = function() {
		var nextImage = settings.images.shift();
		settings.images.push(nextImage);
		return nextImage;	
	};
	
	$.fn.Slides.execute = function() {
		var isToggle = false;
		slideshow = setInterval(function() {
			if (isToggle) {
				settings.main.attr('src', settings.nextImage.src).animate({opacity : 1}, settings.fade);
				isToggle = false;
			} else {
				settings.toggle.css({background : 'transparent url(' + settings.nextImage.src + ') left top no-repeat'});
				settings.main.animate({opacity : 0}, settings.fade);				
				isToggle = true;
			}
			$.fn.Slides.preloadNextImage();
		}, settings.pause);
	};
	
	$.fn.Slides.onhold = function() {
		clearInterval(slideshow);
	};
	
	$.fn.Slides.resume = function() {
		$.fn.Slides.execute();
	};

})(jQuery);

(function($) {
		    $('#slideshow').Slides({
				 images : [
	                 'home_pics/02.jpg'
	                ,'home_pics/03.jpg'
	                ,'home_pics/04.jpg'
	                ,'home_pics/05.jpg'
	                ,'home_pics/06.jpg'
	                ,'home_pics/07.jpg'
	                ,'home_pics/08.jpg'
	                ,'home_pics/09.jpg'
	                ,'home_pics/10.jpg'
	                ,'home_pics/11.jpg'
	                ,'home_pics/12.jpg'
	                ,'home_pics/13.jpg'
	                ,'home_pics/14.jpg'
	                ,'home_pics/10.jpg'
	                ,'home_pics/15.jpg'
	                ,'home_pics/16.jpg'
	                ,'home_pics/17.jpg'
	                ,'home_pics/18.jpg'
	                ,'home_pics/19.jpg'
	                ,'home_pics/20.jpg'
	                ,'home_pics/21.jpg'
	                ,'home_pics/22.jpg'
	                ,'home_pics/01.jpg'
			     ]
			    ,pause : 4000
			    ,fade : 1500
			});
			
			$("#toggle a").live("click", function(){
				var id = $(this).attr("id");
				
				if(id == "pause") {
					$.fn.Slides.onhold();
				} else if(id == "resume") {
					$.fn.Slides.resume();
				}
				
				$("#toggle a").toggle();
			});
			
		})(jQuery);
