var windowWidth = 0;
var windowHeight = 0;
var fadeWidth = 0;

$(document).ready(function(){
	$('#moveLeft').click(moveLeft);
	$('#moveRight').click(moveRight);

	resizeEvent();
	window.onresize = resizeEvent;
 	
	if(typeof hiddenNewsbar != "undefined") {
	  if(hiddenNewsbar) {
	    moveLeft(1);
	  }
	} else {
	  if($('#newswrap').length > 0) {
	    $('#newswrap').show();
	  }
	}

	$('.menu').click(menu);
	
	if($('#innercontent').html() == '') {
	  $('#innercontent').remove();	
	}
	
	$('.page').hover(
	  function(){
	    $(this).addClass('current');
	  },
	  function(){
	    $(this).removeClass('current');
	  }
	);
	
	$('.bookingsubmit').hover(
	  function() {
	    $('.bookingsubmit').css('background-position','right');
	  },
	  function() {
	    $('.bookingsubmit').css('background-position','left');
	  }
	);
	
	$('.calendarSubmit').hover(
	  function() {
	    $('.calendarSubmit').css('background-image','url(fileadmin/templates/images/button_weiter_aktiv.jpg)');
	  },
	  function() {
	    $('.calendarSubmit').css('background-image','url(fileadmin/templates/images/button_weiter_inaktiv.jpg)');
	  }
	);
	
	$('.lastbookingsubmit').hover(
	  function() {
	    $('.lastbookingsubmit').css('background-position','right');
	  },
	  function() {
	    $('.lastbookingsubmit').css('background-position','left');
	  }
	);
	
	$('#c29 a').hover(
	  function() {
	    $('#c29 a img').attr('src','fileadmin/templates/images/button_startseite_akiv.jpg');
	  },
	  function() {
	    $('#c29 a img').attr('src','fileadmin/templates/images/button_startseite_inakiv.jpg');
	  }
	);
	
	if($('.seating').length > 0) {
	  $('.seating').colorbox();
	}

	if($('.cateringinfo').length > 0) {
	  $('.cateringinfo').colorbox();
	}	
	
	if($('.video').length > 0) {
	  $('.video').colorbox();
	}
	
	if($('.agblink').length > 0) {
	  $('.agblink').colorbox();
	}
	
	$('.video a').hover(
		function() {
		  var sId = $('.video').has(this).attr('id');
		  $('#' + sId + ' .videodesc').addClass('activeVideo');
		},
		function() {
		  var sId = $('.video').has(this).attr('id');
		  $('#' + sId + ' .videodesc').removeClass('activeVideo');
		}
	);
	
	$('body').delegate('.refuselink', 'mouseenter', 
		function() {
			$('.refuselink img').attr('src','fileadmin/templates/images/button_tarif_meineauswahl_aktiv.jpg');
		});
		
	$('body').delegate('.refuselink', 'mouseleave', 
		function() {
			$('.refuselink img').attr('src','fileadmin/templates/images/button_tarif_meineauswahl_inaktiv.jpg');
		});
		
	$('body').delegate('.acceptlink', 'mouseenter', 
		function() {
			var sID = $(this).attr('id');
			$('#' + sID + ' img').attr('src','fileadmin/templates/images/button_tarif_vorschlag_aktiv.jpg');
		});
		
	$('body').delegate('.acceptlink', 'mouseleave', 
		function() {
			var sID = $(this).attr('id');
			$('#' + sID + ' img').attr('src','fileadmin/templates/images/button_tarif_vorschlag_inaktiv.jpg');
		});
});

function bodyLoaded(menuUid) {
	/* window.onresize = resizeEvent; */

	var sGetParameter = {'type': '2', 'width': screen.availWidth, 'menu': menuUid};
// alert('http://www.wasserturm-stromeyersdorf.de/index.php&type=2&width=' + screen.availWidth + '&menu=' + menuUid);
	$.get('http://www.wasserturm-stromeyersdorf.de/index.php', sGetParameter, function(data) { $('body').css("background-image","url(" + data + ")"); }, 'text');
}

function resizeEvent(){
	windowWidth = (window.innerWidth || document.body.offsetWidth || document.body.clientWidth);

	var oldBarWidth = parseInt($('#newswrap').css("width"));

	barWidth = Math.ceil((windowWidth - 1024)/2) + 1017;
	barWidth = Math.max(barWidth,1017);

	$('#newswrap').css("width",barWidth);

	if(!isNaN(oldBarWidth)) {
		var marginLeftBar = barWidth - oldBarWidth;
		if(parseInt($('#newswrap').css("margin-left")) != 0 && oldBarWidth != 0) {
			fadeWidth = parseInt($('#newswrap').css("width")) - 2 * parseInt($('#newswrap').css("width")) + 25;
			fadeWidth += "px";

			$('#newswrap').animate({ marginLeft: fadeWidth}, 1020);
		}
	}

	barTopMargin = document.documentElement.clientHeight - 112;
	barTopMargin = Math.max(barTopMargin,500);

	$('#newswrap').css("top",barTopMargin);
}

function moveLeft(bNoBlur) {
	if(typeof bNoBlur == "undefined" || (parseInt(bNoBlur) != NaN && bNoBlur == 0)) {	
		$(this).blur();
	}
	fadeWidth = parseInt($('#newswrap').css("width")) - 2 * parseInt($('#newswrap').css("width")) + 25;
	fadeWidth += "px";

	$('#newswrap').animate({ marginLeft: fadeWidth}, 1020, '', backgroundSmall);
	return false;
}

function moveRight() {
	$(this).blur();
	$('#newswrap').animate({ marginLeft: 0}, 1020, '', backgroundBig);
	return false;
}

function backgroundSmall() {
	$('#moveLeft').hide();
	$('#moveRight').show();
	$('#newswrap').toggleClass('shown');
	$('#newswrap').toggleClass('hidden');
	$('#newswrap').show();	
}

function backgroundBig() {
	$('#moveRight').hide();
	$('#moveLeft').show();
	$('#newswrap').toggleClass('shown');
	$('#newswrap').toggleClass('hidden');
}

function menu(){
	$.get($(this).attr('href'), '', function(data) { $('#content').replaceWith('<div id="content">' + data + "</div>"); }, 'html');

	return false;
}
