window.addEvent('domready', function() {		

	if(document.location.hash.substr(1))
	{
		window.location.href = "index.php?"+document.location.hash.substr(1);
	}

	var myVerticalSlide = new Fx.Slide('mainContent');
	
	ronnyButtonsFunc = function(e) {
	
		
	
		e.preventDefault();
		var matches = this.get('href').match(/.*page=([a-zA-Z]*)(&id=(\d+))?/);
		var page = matches[1];
		var id = matches[3];		
		var url = 'pages/'+page+'.php';
		if (id)
		{
			url += '?id='+id;
			$$('body').tween('background-color',  '#181818');
		}
		else
		{
			$$('body').tween('background-color',  '#ffffff');
		}
		//fade
		$('mainContent').fade('hide');
		//location
		var loc = "#page="+page;
		if(id)
			loc += "&id="+id;
			
		window.location.href = loc;
		window.scrollTo(0, 0);

		
		
		//request
		//var req = new Request.HTML({
		var req = new Request({
			url:url,
			//evalScripts:true,
			// evalResponse:false,
			
			/*
			onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript) {
				$('mainContent').set('html',responseHTML); //Inject the new DOM elements into the results div.
				$exec(responseJavaScript); // process javascript manually AFTER element is loaded
			},*/
			
			//
			onSuccess: function(html) {
				$('mainContent').set('html', '');
				//$('mainContent').adopt(html);
				$('mainContent').innerHTML = html;
				$('mainContent').getElements('.ronnyButtons').addEvent('click', ronnyButtonsFunc);
				//fade
				$('mainContent').fade('1');
							
				/*var testData = $('data').getElement('#testVar').get('value');
				console.log(testData);*/
				
				var count = 1;
				$each($$('.movie'),function(item) {
						var matches = item.get('value').split(',');
						//if(window.console)
						// console.log("videoUrl: "+matches[0]);
						// console.log("picUrl: "+matches[1]);
						// console.log("videoHeight: "+matches[2]);
						//
						// flashvars 
						var flashvars = {};
						flashvars.videoUrl = '../'+matches[0];
						flashvars.picUrl = '../'+matches[1];
						flashvars.videoHeight = matches[2];
						// console.log("flashvars.picUrl: "+flashvars.picUrl);
						// console.log("flashvars.videoUrl: "+flashvars.videoUrl);
						var params = {};
						params.bgolor = "bba75f";
						var attributes = {};
						// flashfilm in dom schreiben
						var videoHeight =  (parseFloat(matches[2])+29);
						swfobject.embedSWF("flash/videoPlayer.swf", "flashContent"+count, "678", videoHeight, "9", "js/lib/expressInstall.swf", flashvars, params, attributes);
						count++;
				});
				
				
				
				
				
				
				
				//myVerticalSlide.show();
			},//
			onFailure: function() {
				$('mainContent').set('text', 'The request failed.');
			}
		});
		req.send();
	}
	$$('.ronnyButtons').addEvent('click', ronnyButtonsFunc);
});