Cufon.replace("h2", {
	fontFamily: "Univers Light Condensed"
});

// Slideshow-Pics vorausladen
function simplePreload() {
	var imageDir = "img/slideshow/";
	var images = ["pic1.jpg", "pic2.jpg", "pic3.jpg", "pic4.jpg", "pic5.jpg", "pic6.jpg", "pic7.jpg"];
	document.imageArray = new Array(images.length);
	for (var i=0; i < images.length; i++) {
		document.imageArray[i] = new Image;
		document.imageArray[i].src = imageDir + images[i];
	}
}
simplePreload();

$(document).ready(function() {

	/* Suchfeld-Value zuruecksetzen*/
	var $searchField = $("input#suchfeld");
	$searchField.focus(function() { if (this.value == this.defaultValue) this.value = ""; });
	$searchField.blur(function() { if (this.value == "") this.value = this.defaultValue; });


	/* Slideshow */
	var items = $("ul#slideshowItems li");
	var allButtons = items.length;
	var counter = 0;
	items.eq(0).addClass("active");

	function showItem(i) {
	
		if (items.eq(i).hasClass("active")) {
			return false;
		} 
		if (items.is(":animated")) {
			return false;
		}
		
		items.eq(i).css("z-index", 49);

		items.filter(".active").removeClass("active").fadeOut("slow", function() {
			$(this).css("z-index", 40).show();
			items.eq(i).css("z-index", 50).addClass("active");
		});
	}
	

	$(".playbutton").each(function(i, el) {
		$(el).bind("mouseover", function() {
			if (typeof interval != "undefined") { clearInterval(interval); }
		});
		$(el).bind("mouseleave", function() {
			start(counter);
		});
		
		$(el).bind("click", function() {
			counter < allButtons - 1 ? counter++ : counter = 0;
			showItem(counter);
		});

	});

	function start(i) {
		if (typeof i != "undefined") {
			counter = i;
		}
		interval = setInterval(function() {
			counter < allButtons - 1 ? counter++ : counter = 0;
			showItem(counter);
		}, 5000);
	}
	
	start();

});
