function checkURL() {
	//var query=document.URL.split("#")[1];
	return document.URL.split("#")[1];
}

function siteActions() {
	resizein();
	if(!nojsed) {
	$('text').fade('out').get('tween').chain(function(){
	  $('ajxcontent').fade('out');
		$('text').setStyle("display","block");
		readysteadygo();
		//$('logo2').fade('out').get('tween').chain(function(){
		//$('logo2').setStyle("display","block");
		
	//});
		
	});
	}
	else { readysteadygo(); /* makenavgrey();  $('logo').fade('out').get('tween').chain(function(){
		$('logo').setStyle("display","block");
	}); */}
}

	
	
	
	function readysteadygo() {
			$('conclose').addEvent("click",function(e) {
																																									  e.preventDefault();
		moveContentOut();
	});
		blankimg = "images/blank.gif";
	//xMask = new Mask($(document.body),{'id': 'xmask'});
	//$('xmask').setStyle('display','none');
	var startV = true;
	//$('xmask').fade('out').get('tween').chain(function() {$('fadebg').setStyle('display','block');});;
	
	$$('#ajxcontent .cboxcon').set('id','cboxcon');
	
	$$('a.tojump').each(function(el,i) {
	 if(!el.get('href').match(/mailto/i)) {
		el.set('href','#'+el.get('href').replace(/(.*)\.php/,"$1"));
		//el.addClass("jump");
		}
	});	
	
	$$('a.tojump').each(function(el,i) {							   
		el.addEvent("click",function(event) {
			//event.stop();
			//urlparts= url.split('?'); 
			if(el.get('href').match(/#index/i)) {
    moveContentOut(); }
			else {
					$$('a.tojump').removeClass("stand");
				el.addClass("stand");
				$('loadingmessage').addClass("show");
				if($('text').getStyle('visibility')=="hidden") {
						//$('logo2').fade('in');
						//$('logo').fade('out');
						$('text').fade('in').get('tween').chain(function(){
							loadContent(el.get('href').replace(/(.*)#/,"$1"));
						});
						
				}
				else {
						$('ajxcontent').fade('out').get('tween').chain(function(){
							loadContent(el.get('href').replace(/(.*)#/,"$1"));
																						  });
					}

			}
		});
		
		var checkedURL=checkURL();
	
	if((checkedURL=="index" || typeof(checkedURL) == 'undefined') && (document.URL.match(/index\.php/i) || document.URL.replace(/.*\.de\/(.*)/,"$1")=="")) {
		
		
		
	}
	else
	{
	 
		$$('a.tojump').each(function(el,i) {
		var chlink = el.get('href').replace(/(.*)#/,"$1");
		  if(checkedURL==chlink) {
        el.fireEvent("click",[el,i]);
      }
		});
	}
	
	
	
	
	
	
	$$('.bgthumb').each(function(el,i) {
	 	el.addEvent("click",function() {
			$('loadingmessage').addClass("show");
			$('mbOverlay').setStyles({ 'top': -$(window).getScroll().y,'height':$(window).getScrollSize().y+$(window).getScroll().y });
			$('mbOverlay').fade(0.8).get('tween').chain(function() {
		
				var xcimg = el.get('src').replace(/(.*)-thumb\.jpg/,"$1.jpg");
				var xxx = new Asset.image(xcimg, {onload: function() {
						
						$('fadebg').setStyle('background-image','url('+xcimg+')');
						$('fadebg').fade('in').get('tween').chain(function() {
						$(document.body).setStyle('background-image','url('+xcimg+')');
						$('fadebg').fade('out');
						$('mbOverlay').fade('out');
						$('loadingmessage').removeClass("show");
					});
					
				}}); 
			
			});
			
			
		});
	});	
		
		});	
	}
	
	
	




function loadContent(varlink) {
		new Request.HTML({  
			method: 'get',
			data: { 'q' : 'quax' },
			url: varlink+'.php',
			onRequest: function() { $('cboxcon').set('html','Lade...') },
			update: $('cboxcon'),
			//onComplete: moveContent(),
			onFailure: function() { loadContent("404"); },
			onSuccess: function() { moveContent();Shadowbox.init({ skipSetup: true }); Shadowbox.setup(); noSpam(); $('conclose').addEvent("click",function(e) {
																																									  e.preventDefault();
		moveContentOut();
	}); }
		}).send();	
}

function makenavgrey() {
	$('navi').addClass('active');$$('.fade').addClass('stand');
	$$('.fade').each(function(el){
									  
									  new Fx.Morph(el, {duration: 200}).start({'opacity':activeTransparency});
									  });
	
	}

function moveContent() {
	makeScrollbar( $("innerc"), $('scrollbar'), $('scrollh') );
	//new Fx.Morph($('ajxcontent'), { 'duration': 1000 }).start({'top': '0px'}).chain(function(){
	//	$('loadingmessage').removeClass("show");
	//});
	$('ajxcontent').fade('in').get('tween').chain(function(){
		//makenavgrey();						 
		$('loadingmessage').removeClass("show");
	});
}

function moveContentOut() {
	//$('logo').fade('in');
	//$('logo2').fade('out');
	$('text').fade('out').get('tween').chain(function(){
		$('ajxcontent').fade('out');
		$('loadingmessage').removeClass("show");$$('.fade').removeClass('stand');
		$$('.fade').each(function(el){
									  new Fx.Morph(el, {duration: 200}).start({'opacity':normTransparency});
									  });
		$('navi').removeClass('active');
	});
}

window.addEvent('domready', siteActions);



 function makeScrollbar(content,scrollbar,handle,horizontal,ignoreMouse){
	var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y))
	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);
	
		// 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()});
	
}


window.addEvent("resize",function() {
resizein();
});


function resizein() {
	if ($(window).getSize().y<740) {
		$('footer').addClass('smallWindow');	
	}
	else {
		$('footer').removeClass('smallWindow');	
	}
	
	if ($(window).getSize().x<1255) {
		$('footerevent').addClass('smallWindow');
	}
	else {
		$('footerevent').removeClass('smallWindow');
	}
}




