$(window).load(function() {
	/*
	 * Slide show
	 */
	$.slideShow = $.slideShow || {
		$slideShow: null,
		$items: null,
		isPlaying: false,
		_timer: null,
		_interval: 6000,
		_speed: "slow",
		_curr: 0,

		init: function() {
			this.$slideShow = $("#slides");
			if (!this.$slideShow.length) return;

			this.$items = $(".slide", this.$slideShow);

			this.$secondSlide = $("#s2");
			var twoSlides = (this.$secondSlide.length) ? true : false;

			this.$items.each(function(idx) {
				var $this = $(this);
				var $buttons = (twoSlides) ? $("#print-1, #print-2, #pause-1, #pause-2, #play-1, #play-2, #close-1, #close-2") : $("#close-1");

				$buttons.mouseover(function() {
					$(this).addClass("over");
				}).mouseout(function() {
					$(this).removeClass("over");
				});
				
				if (twoSlides) {
					$("#print-1, #print-2").click(function() {
						var printWin = window.open("slide-" + this.id.split("-")[1] + ".htm", "printWin", "width=780, height=420, location=no, menubar=no, resizable=yes, scrollbars=yes, status=no, toolbar=no");
					});
					
					$("#pause-1, #pause-2").click(function() {
						$.slideShow.stop();
					});
					
					$("#play-1, #play-2").click(function() {
						$.slideShow.play();
					});
				}
								
				$buttons = (twoSlides) ? $("#close-1, #close-2", $this) : $("#close-1", $this);
				$buttons.click(function() {
					$.slideShow.destroy();
				});
				
				
				/* teiltransparenten Layers zeigen (nur startseite), md */
				//$(".homepagelayer #slides-soft").show();
				//$(".homepagelayer #close-1").show();
				
				/* schliessen des info layers und des teiltransparenten Layers auf der Startseite bei click irgendwohin (nur startseite), md */
				$(".homepagelayer").click(function() {
					//$.slideShow.destroy();
					//$("#slides-soft").hide();
				});
			});
			
			//$(this.$items[this._curr]).fadeIn(this._speed);

			if (twoSlides) {
				this.play();
			} else {
				$(this.$items[0]).fadeIn(this._speed);
			}
		},
		
		destroy: function() {
			this.stop();
			this.$slideShow.fadeOut();
		},

		fade: function() {
			$(this.$items[this._curr]).fadeOut(this._speed);
			this._curr = (this._curr) ? 0 : 1;
			$(this.$items[this._curr]).fadeIn(this._speed);
		},

		play: function() {
			if (this.isPlaying) {
				return;
			}
			
			this.stop();
			this.fade();
			this._timer = window.setInterval("$.slideShow.fade()", this._interval);
			
			this.isPlaying = true;
		},

		stop: function() {
			if (this._timer) {
				clearTimeout(this._timer);
			}
			
			this.isPlaying = false;
		}
	};

	$.slideShow.init();
});

