var name_360 = "holzerhof_";
var startPanorama_360 = "5517";
var vrHeight = 650;
var vrWidth = 950;
var vrLeft = ((screen.availWidth - vrWidth)/2);
var vrTop = ((screen.availHeight - vrHeight)/2);

function startVR(name, startPanorama, vrHeight, vrWidth, vrTop, vrLeft) {
	window.open('http://www.holzerhof.com/fileadmin/ext/rundgang/html/de/' + name + startPanorama + '.html', '360_degree_vrtour', 'width=' + vrWidth + ',height=' + vrHeight + ',top=' + vrTop + ',left=' + vrLeft + ',menubar=no,resizable=no, scrollbars=no, toolbar=no');
}

player = false;

function musikbox(adress) {
	if(player && !player.closed) {
		player.close();
	} else {
		player = window.open(adress, 'Musikbox', 'dependent=yes, width=260, height=150, location=no, menubar=no, resizable=no, scrollbars=no, status=no, toolbar=no');
	}
	return false;
}

function makeScrollbar(content,scrollbar,handle,horizontal,ignoreMouse){
	var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y))
	if(steps >	0) {
		var slider = new Slider(scrollbar, handle, {
			steps: steps,
			mode: (horizontal?'horizontal':'vertical'),
			onChange: function(step){
				// Scrolls the content element in x or y direction.
				var x = (horizontal?step:0);
				var y = (horizontal?0:step);
				content.scrollTo(x,y);
			}
		}).set(0);
		if( !(ignoreMouse) ){
			// Scroll the content element when the mousewheel is used within the 
			// content or the scrollbar element.
			$$(content, scrollbar).addEvent('mousewheel', function(e){
				e = new Event(e).stop();
				var step = slider.step - e.wheel * 30;
				slider.set(step);
			});
		}
		// Stops the handle dragging process when the mouse leaves the document body.
		$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
	} else {
		scrollbar.style.display = 'none';
		var width = (horizontal?content.getSize().x-20:content.getSize().x+15);
		var height = (horizontal?content.getSize().y-5:content.getSize().y-4);
		content.style.width = width + 'px';
		content.style.height = height + 'px';
	}
}

window.addEvent('domready', function() {
	//Morphing the main Content
	
	//Init Vars
	var mc = $('pbody');
	var oc = $('open_content');
	mc.set('morph', {duration: 2500, transition: 'linear'});
	//$('open_content').set('fade', {duration: 2500, transition: 'linear'});

	//Init State of Transition at beginning
	
	$('open_content').fade(0); //Button is away
	$('open_content').style.display = 'none';
	
	//$('pbody').style.padding = '1000px 0 0 0'; //Content is away
	
	$('pbody').morph('.mcOpen'); // Morphstus shown
	
	$('bigbgimg').style.visibility = 'hidden'; //hide BG Image to get fadet in later
	
	/* 1. String mit Bildnamen (Ressourcen) splitten und als Array speichern
	 * 2. Zählvariable für das Array auf Null setzen
	 * 3. erstes Bild als Hintergrund nehmen
	 */
	var bgimg_arr = bgimages.split(',');
	var imgcount = 0;
	$('bigbgimg').style.backgroundImage = 'url(uploads/media/' + bgimg_arr[imgcount] + ')';
		
	//Fade des Hintergrundbildes 01.01.2010 Sev
	var hintergrund = $('bigbgimg');
	// Effekt-Objekt erstellen
	var hintergrundfade = new Fx.Tween(hintergrund, {
	'duration': 2000
	});
	// Effekt starten!
	hintergrundfade.start('opacity', 0, 1);
	if (window.no){
		no();
	}
	// Generate Events for morphing Content
	$('close_content').addEvent('click', function(e) {
		e.stop();
		$('open_content').style.display = 'block';
		// Changes the element's style to .myClass defined in the CSS
		mc.morph('.mcHidden');
		$('open_content').fade(1);
		//$('open_content').style.visibility = 'visible';
		//$('pbody').style.display = 'none';
	});
	$('open_content').addEvent('click', function(e) {
		e.stop();
		// Changes the element's style to .myClass defined in the CSS
		$('pbody').style.display = 'block';
		mc.morph('.mcOpen');
		$('open_content').fade(0);
		//$('open_content').style.visibility = 'hidden';
	});
	
	//Fade in and out romm infos
	
	var infos = $$('.zimmer');
	var toggler = $$('.room');
	toggler.each(function(item, index){
		//alert(index + " = " + item);
		item.addEvent('mouseenter', function(e) {
			e.stop();
			$('noroom').style.display = 'none';
			infos[index].style.display = 'block';
		});
		item.addEvent('mouseleave', function(e) {
			e.stop();
			$('noroom').style.display = 'block';
			infos[index].style.display = 'none';
		});
	});
	
	
	
	$('prev_bgimg').addEvent('click', function(e) {
		e.stop();
		$('bigbgimg').fade(0);
		imgcount = ((imgcount == 0) ? (bgimg_arr.length - 1) : (imgcount - 1));
		(function() {
			$('bigbgimg').style.backgroundImage = 'url(uploads/media/' + bgimg_arr[imgcount] + ')';
		}).delay(500);
		(function() {
			$('bigbgimg').fade(1);
		}).delay(1500);
	});
	
	$('next_bgimg').addEvent('click', function(e) {
		e.stop();
		$('bigbgimg').fade(0);
		imgcount = (imgcount + 1) % bgimg_arr.length;
		(function() {
			$('bigbgimg').style.backgroundImage = 'url(uploads/media/' + bgimg_arr[imgcount] + ')';
		}).delay(500);
		(function() {
			$('bigbgimg').fade(1);
		}).delay(1500);
	});
	
	
	// Test von Sev:
	if($('colgroup') != null) {
		makeScrollbar( $('colgroup'), $('scrollbar4'), $('handle4') );
	} else {
		makeScrollbar( $('midcol'), $('scrollbar2'), $('handle2') );
	}
	
});