
var $_GET = {};

document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
    function decode(s) {
        return decodeURIComponent(s.split("+").join(" "));
    }

    $_GET[decode(arguments[1])] = decode(arguments[2]);
});


function GetRandom( min, max ) {
	if( min > max ) {
		return( -1 );
	}
	if( min == max ) {
		return( min );
	}
 
        return( min + parseInt( Math.random() * ( max-min+1 ) ) );
}

var currentIndex;

var BildInfoTexte = new Array();
BildInfoTexte.push("Detail, Waldkirchen. 2006");
BildInfoTexte.push("Detail, Waldruhestetten. 2005");
BildInfoTexte.push("Detail, Freiburg. 2008");
BildInfoTexte.push("Detail, Waldruhestetten. 2007");
BildInfoTexte.push("View, Waldruhestetten. 2007");

$(window).load(function() {
			this.currentIndex = GetRandom( 0, ($('#bilder > *').length-1));
			$('#bilder').cycle({
					timeout: 0,
					speed:   600,
					startingSlide: currentIndex
				})
			setTexte(currentIndex);
			$('#bilder').fadeIn("slow", function() {$('#bilderSteuerung').fadeIn("slow");});
			$('#next').bind("mouseup", nextImage);
			$('#back').bind("mouseup", backImage);
			$('#bsShowText').bind("mouseup", showContent);
			$('#headline').bind("mouseup", hideContent);
			$('#next').css("cursor", "pointer");
			$('#back').css("cursor", "pointer");
			$('#bsShowText').css("cursor", "pointer");
			$('#headline').css("cursor", "pointer");
			if ($_GET['open'] == "true") {
				showContent();			
			}
			 
})


function showContent() {
		$("#contentouterbox2").animate({height: ($("#content").height()+100)+'px'}, 500);
	}

function hideContent() {
		$("#contentouterbox2").animate({height:'0px'}, 500);
	}

function nextImage() {
	currentIndex++;
	if (currentIndex > ($('#bilder > *').length-1)) {
		currentIndex = 0;
	}
		$('#bilder').cycle(currentIndex);
	setTexte(currentIndex);
}

function backImage() {
	currentIndex--;
	if (currentIndex < 0) {
		currentIndex = $('#bilder > *').length-1;
	}
	$('#bilder').cycle(currentIndex);
	setTexte(currentIndex);
}

function setTexte(currentIndex) {
		this.currentIndex = currentIndex;
		$("#bsInfoText").text(BildInfoTexte[currentIndex])
		$("#back").text((currentIndex+1));
		$("#next").text($('#bilder > *').length);
	}
