var nDia = 0;

function diashowForward( oEvent ) {
	var aContainer = $$(".dscontainer");
	
	nDia++;
	if( Object.isUndefined(aContainer[0].down(".dsimage").next('input', 2 * nDia)) ) {
		nDia = 0;
	}
	
	$$(".dsimage")[0].writeAttribute(
		  "src"
		, aContainer[0].down(".dsimage").next('input', 2 * nDia).getValue()
		);
	$$(".dsinfo")[0].innerHTML = "Bild " + (nDia + 1) + ": "
		+ aContainer[0].down(".dsimage").next('input', 2 * nDia + 1).getValue();
	oEvent.stop();
}

function diashowBackward( oEvent ) {
	var aContainer = $$(".dscontainer");

	nDia--;
	if( nDia == -1 ) {
		nDia = 0;
		while( !Object.isUndefined(aContainer[0].down(".dsimage").next('input', 2 * nDia + 1)) ) {
			nDia++;
		}
		nDia --;		
	}
	
	$$(".dsimage")[0].writeAttribute(
		  "src"
		, aContainer[0].down(".dsimage").next('input', 2 * nDia).getValue()
		);
	$$(".dsinfo")[0].innerHTML = "Bild " + (nDia + 1) + ": "
		+ aContainer[0].down(".dsimage").next('input', 2 * nDia + 1).getValue();
	oEvent.stop();
}

function initDiashow() {
	var aContainer = $$(".dscontainer");
	
	if( aContainer.length > 0 ) {
		
		Event.stopObserving(aContainer[0].down(".dsimage"), "click");
		Event.observe(aContainer[0].down(".dsimage"), "click", diashowForward);
		
		Event.observe(
			  aContainer[0].down(".dsforward")
  			, "click"
  			, diashowForward
  			);
		aContainer[0].down(".dsforward").setOpacity(0.6);
		Event.observe(
			  aContainer[0].down(".dsbackward")
  			, "click"
  			, diashowBackward
  			);
		aContainer[0].down(".dsbackward").setOpacity(0.6);
		
		$$(".dsimage")[0].writeAttribute(
			  "src"
			, aContainer[0].down(".dsimage").next('input', 2 * nDia).getValue()
			);
		$$(".dsinfo")[0].innerHTML = "Bild " + (nDia + 1) + ": "
			+ aContainer[0].down(".dsimage").next('input', 2 * nDia + 1).getValue();
	}
}

function initSite() {
	oReview = new cReview();
	oReview.init();
	
	initDiashow();
}

function initPage() {
	var aShineThrough = $$(".shinethrough");
	for(var i = 0; i < aShineThrough.length; i++) {
		aShineThrough[i].setOpacity(0.8);
		/*
		var aChildren = aShineThrough[i].descendants();
		for(var j = 0; j < aChildren.length; j++) {
			aChildren[j].setOpacity(1.0);
		}
		*/
	}
}
