gWidth = function() {
	var w = 0;
	if (typeof(window.innerWidth) == 'number') {
		w = window.innerWidth;
	}
	else {
		if (document.documentElement && document.documentElement.clientWidth) {
			w = document.documentElement.clientWidth;
		}
		else {
			if (document.body && document.body.clientWidth) {
				w = document.body.clientWidth;
			}
		}
	}
	return w;
}

$(document).ready(function() {	

	/*$('nav a[href!="/Kontakt"]').click(function(ev) {
		$('section.panelinfo').load($(this).attr('href')+' section.panelinfo,script',function(e) {
			
			$('.event').hide();	
	
			if(window.location.hash === '' || window.location.hash === undefined || window.location.hash === null) {
				$('.event:first').show();
				current = '#'+$('.event:first').attr('id');
			} else {
				$(window.location.hash).show();
				current = window.location.hash;
			}
			
			$("a.grouped_elements").fancybox({
				'transitionIn'	:	'elastic',
				'transitionOut'	:	'elastic',
				'speedIn'		:	600, 
				'speedOut'		:	200, 
				'overlayShow'	:	false
			});
			
		});
		$(this).blur();
		ev.preventDefault();
	});
	*/
	$(".btn-slide").click(function(){
		$("#upcoming-events").slideToggle("slow");
		$(this).toggleClass("active"); return false;
	});
	$('nav#top').lavaLamp({ fx: "backout", speed: 700 });

	$('a[rel=external],a.external').live('click',function(ev) {
		var a = window.open($(this).attr('href'),$(this).attr('title'));
		ev.preventDefault();
	});
		
	var moving = false;
	var current = null;
	var form = false;
	
	$('.event').hide();	
	
	if(window.location.hash === '' || window.location.hash === undefined || window.location.hash === null) {
		$('.event:first').show();
		current = '#'+$('.event:first').attr('id');
	} else {
		$(window.location.hash).show();
		current = window.location.hash;
	}		
	
	
	
	$('h3.btn-event a').live('click',function(ev) {	

		if('#'+$(this).parent().next('.event').attr('id') != current && moving == false) {
			var t = $(this);
			moving = true;
			var old = current;
			current = '#'+$(this).parent().next('.event').attr('id');
			$(old).slideUp('fast',function() {
				t.parent().next('.event').slideDown('fast',function() {  moving = false; });
			});
		}
	});
	
	$('a.btn-sub-content').live('click',function() {
		if($(this).prev('div.sub-content').css('display') == 'none') {
			$(this).text('Schliessen');
		} else {
			$(this).text('Mehr lesen');
		}
		$(this).prev('div.sub-content').slideToggle('fast');
	});
	
	$("a.grouped_elements").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
	
	$('form#reservierungen').live('submit',function(ev) {	 		
	 		if(form==false) {
	 			$('div#messages').empty();
	 			$('input,textarea,select').attr('disabled','disabled');
		 		form=true;
		 		$.post($(this).attr('action'), { "name": $('input[name=name]').val(), 'email': $('input[name=email]').val(), 'termin':$('select[name=termin]').val(),'telefon':$('input[name=telefon]').val(),'message':$('textarea[name=message]').val(),'copy':$('input:checkbox[name=copy]:checked').val(),'geburtstagspaket':$('input:checkbox[name=geburtstagspaket]:checked').val(),'geburtstag_extra':$('input:checkbox[name=geburtstag_extra]:checked').val() },
		 	function(data){

	 				switch(data.type) {
	 					case 'ERROR':	$('<div class="error"><p>'+data.msg+'</p></div>').appendTo('div#messages').hide().fadeIn('fast');
	 									break;
	 					case 'SUCCESS':	$('<div class="success"><p>'+data.msg+'</p></div>').appendTo('div#messages').hide().fadeIn('fast');
	 									$('form#reservierungen').fadeOut('fast');
	 									break;
	 									
	 					default:		// alert(data.fehlertext);
	 									break;
	 				}	
					$('input,textarea,select').removeAttr('disabled');;
   					form=false;
	   				}, "json");
   			}   		
	 	ev.preventDefault();
	 });
	 
	 /*$(window).resize(function() {
	 	$('#crossslide img').width(gWidth()*1.10).height('');
	 });
	$('#crossslide img').width(gWidth()*1.10);*/
});
VideoJS.setupAllWhenReady();
