
var oReview = null;

function initSite() {
	new Effect.Move('topbanner', {
  		delay: 1.0, duration: 1.6, x: 0, y: 105, mode: 'relative',
  		transition: Effect.Transitions.spring
		});
	initResultlistFilter();
	initDiashow();
	
	oReviewEditor = new cReviewEditor();
	oReviewEditor.init();
}

function initResultlistFilter() {
	var oFilter = $("ctrl_content").down(".ctrl_rl_filter");
	if( !Object.isUndefined(oFilter) ) {
		oFilter.observe("change", rl_activateFilter);
		
		var oFilter = $("ctrl_content").down(".ctrl_rl_filter", 1);
		if( !Object.isUndefined(oFilter) ) {
			oFilter.observe("change", rl_activateFilter);
		}
	}
}

function rl_activateFilter( oEvent ) {
	var oElement = oEvent.element();
	document.location.search = oElement.getValue();
}

var nDia = 0;

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

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

	aContainer[0].down(".dsforward").setOpacity(0.3);
	aContainer[0].down(".dsbackward").setOpacity(0.3);
	aContainer[0].down(".dstitlebackground").setOpacity(0.3);
	oEvent.stop();
}

function diashowShowControls( oEvent ) {
	var aContainer = $$(".dscontainer");
	
	aContainer[0].down(".dsforward").setOpacity(1);
	aContainer[0].down(".dsbackward").setOpacity(1);
	aContainer[0].down(".dstitlebackground").setOpacity(1);
	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.stopObserving(aContainer[0].down(".dsimage"), "mouseover");
		Event.observe(aContainer[0].down(".dsimage"), "mouseover", diashowHideControls);
		Event.stopObserving(aContainer[0].down(".dsimage"), "mouseout");
		Event.observe(aContainer[0].down(".dsimage"), "mouseout", diashowShowControls);
		
		Event.observe(
			  aContainer[0].down(".dsforward")
  			, "click"
  			, diashowForward
  			);
		
		Event.observe(
			  aContainer[0].down(".dsbackward")
  			, "click"
  			, diashowBackward
  			);

		$$(".dsimage")[0].writeAttribute(
			  "src"
			, aContainer[0].down(".dsimagecontainer").next('input', 2 * nDia).getValue()
			);
		$$(".dsinfo")[0].innerHTML = "Bild " + (nDia + 1) + ": "
			+ aContainer[0].down(".dsimagecontainer").next('input', 2 * nDia + 1).getValue();
	}
}

function enableSC() {
	new Ajax.Request("/ajax_helper.php"
		+ "?" + SESSION_PARAM + "=" + SESSION_ID
		+ "&ts=" + (new Date()).getTime()
		, {
			"parameters": {
				"action":	"SET_VALUE"
				, "key":	"fbenabled"
				, "value":	1
			}
			, "onSuccess": function() {
				window.location.reload();
			}
		});
}

