/**
 * ngSlideShow - jQuery Plugin
 * Copyright (c) 2009 by Danilo Kühn
 * Version: 1.0
 * Require: jQuery 1.2 or above
 * MIT licenses: http://www.opensource.org/licenses/mit-license.php
 */
$(document).ready(function () {
	$('#slideshow1').slideshow({
		speed: 6,
		height: 300,
		width: 740,
		images: [
			{src: 'uploads/startseite_winter_1.jpg', link: ' http://www.uhrenwarenhaus.de/herrenuhren-traser-h3-militaeruhren-c12312 ',  title: 'Traser H3 Militäruhren - Robust und langlebig - Mit H3 Tritium-Beleuchtungselemente'},
			{src: 'uploads/startseite_winter_2.jpg', link: ' http://www.uhrenwarenhaus.de/herrenuhren-luminox-einsatzuhren-c12272 ',  title: 'Luminox H3 Militäruhren - Swiss Made Qualität mit sehr gutem Preis-Leistungsverhältnis'},
                        {src: 'uploads/sonderangebote_traser.jpg', link: ' http://www.uhrenwarenhaus.de/p/183814076/traser-h3-militaeruhr-p6507-commander-100-pro-titanuhr-mit-titanband ',  title: 'Traser P6507 Commander Titan - Super leicht und dennoch robust'}
 			]
	});
});
 
(function($) {
	$.fn.slideshow = function (o) {
		o = $.extend({images: null, height: 300, width: 740, speed: 4}, o || {});
		return this.each(function() {
			var position = 0;
			var div = $(this);
			div.css({position: 'relative', height: o.height, widht: o.width})
			div.append('<a href="#" title="" style="border: none"></a>');
			var a = $('a', div);
			a.css({position: 'relative', height: o.height, widht: o.width});
			preloadImage();
			loadImage(true);
			
			function preloadImage() {
				if (!o.images[position].obj) {
					o.images[position].obj = $("<img>").attr("src", o.images[position].src).css({position: 'absolute', display: 'none', border: 'none', height: o.height, widht: o.width, top: 0, left: 0});
					a.append(o.images[position].obj);
				}
			}	
			
			function loadImage(first) {
				a.attr('href', o.images[position].link);
				a.attr('title', o.images[position].title);
				if (first) {
					o.images[position].obj.fadeIn('slow');
				} else {
					var preImg = (position-1<0) ? o.images.length-1 : position-1; 
					o.images[preImg].obj.fadeOut('slow');
					o.images[position].obj.fadeIn('slow');					
				}
				position = (position + 1 >= o.images.length) ? 0 : position + 1;
				preloadImage();
			}
			
			var handle = window.setInterval(function () {
				loadImage(false);
			}, o.speed * 1000);
		});
	};
})(jQuery);
