/**
 * 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 () {
	$('#slideshow').slideshow({
		speed: 6,
		height: 289,
		width: 740,
		images: [
			{src: 'uploads/sonderangebote_1881.jpg', link: ' http://www.uhrenwarenhaus.de/p/341138316/luminox-h3-militaeruhr-field-chrono-alarm-serie-1881-blackout-chronograph ',  title: 'Luminox 1881 Blackout H3 Militäruhr - Robust und langlebig - Schwarz wie die Nacht'},
			{src: 'uploads/sonderangebote_hanowa.jpg', link: ' http://www.uhrenwarenhaus.de/p/480073991/swiss-military-hanowa-legend-herrenuhr-chronograph-6-5134-04-007 ',  title: 'Swiss Military Hanowa Legend - Robuster Chronograph 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: 289, width: 740, speed: 6}, 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);
