$(document).ready(function(){
	
	show_trailer();
	$("#btnBooking").hide();
	$("#booking_button_left").hide();
	$("#booking_button_right").hide();
	
	$('.Open_Gallery_Button, .Gallery_Open_Button').click(function(e){
		e.preventDefault();
		$.post('php/ajax/gallery.php',{id:$('#details_id_field').html(),title:$('#details_title_field').html()},function(d){
			$('#Gallery_Fullscreen').html(d).show();
		});
	});
	
	$('#Gallery_Close').live('click',function(){
		$('#Gallery_Fullscreen').hide().html('');
	});
	
	$("#foot_newsletter").animate({
			height:'toggle',
		}, 0 );
		
	// Newsletter
	$('#newsletter_submit').click(function () { 
		var email = $('#input_email_footer').val();
		var lang = $('.foot_left_radio').val();
		$.post('php/ajax/email.php',{'type':'newsletter','email':email,'lang':lang},function(r){
			$('#newsletter_send').show();
			$('#footer_newsletter_left').hide();
		});
		return false;
	});
	
	// Quick Contakt
	$('#submit_button').click(function () { 
		var message = $('#input_message').val();
		var email = $('#input_email').val();
		$.post('php/ajax/email.php',{'type':'quick','email':email,'message':message},function(r){
			$('#head_done').show();
			$('#quick_contact').hide();
		});
		return false;
	});
	
	// Booking Quickmail
	$('#booking_submit').click(function () {
		var message = $('#booking_message').val();
		var email = $('#booking_email').val();
		if($('#booking_roompointer')){
			var room = $('#booking_roompointer').html();
		}else{
			var room = '';
		}
		$.post('php/ajax/email.php',{'type':'booking','email':email,'message':message,'object':$('#booking_titlepointer').html(),'room':room},function(r){
			$('#quickmail_send').show();
			$('#quickmail').hide();
		});
		return false;
	});	
	
	// Booking Hotmail
	$('#hotline_button').click(function () {
		var name = $('#hotmail_name').val();
		var phone = $('#hotmail_phone').val();
		$.post('php/ajax/email.php',{'type':'hotline','hotmail_name':name,'object':$('#booking_titlepointer').html(),'hotmail_phone':phone},function(r){
			$('#hotline_send').show();
			$('#hotline').hide();
		});
		return false;
	});

	// Booking Packages
	$('#booking_packages_submit').click(function () { 
		var capacity = $('#capacity').val();
		var timespan = $('#timespan').val();
		var fullname = $('#fullname').val();
		var persons = $('#persons').val();
		var email = $('#email').val();
		var address = $('#address').val();
		var housenr = $('#housenr').val();
		var zip = $('#zip').val();
		var city = $('#city').val();
		var phone = $('#phone').val();
		$.post('php/ajax/email.php',{'type':'package','capacity':capacity,'object':$('#hotelname').html(),'package':$('#booking_titlepointer').html(),'timespan':timespan,'fullname':fullname,'persons':persons,'email':email,'address':address,'housenr':housenr,'zip':zip,'city':city,'phone':phone},function(r){
			$('#booking_packages').hide();
			$('#packages_send').show();
		});
		return false;
	});
	
	$("a.jQueryBookmark").click(function(e){
		e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
		var bookmarkUrl = this.href;
		var bookmarkTitle = this.title;
	 
		if (window.sidebar) { // For Mozilla Firefox Bookmark
			window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
		} else if( window.external || document.all) { // For IE Favorite
			window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
		} else if(window.opera) { // For Opera Browsers
			$("a.jQueryBookmark").attr("href",bookmarkUrl);
			$("a.jQueryBookmark").attr("title",bookmarkTitle);
		} else { // for other browsers which does not support
			 alert('Your browser does not support this bookmark action');
			 return false;
		}
	});
	
	// Validate Forms
	function init_forms()
{
	$("#form_member").vucxForm(function(xml){
		var status = getXML(xml,"lStatus");
		$("div.leaflet").html(status);
		$("#form_member").hide();
		$("#frmLogout").show();
		$("#hl20").fadeOut();
	});
	var btn = $("#logout");
	if(btn.length)
	{
		btn.click(function(){
			do_logOut();
		});
	}
	
	$("#quick_contact_form").vucxForm(function(xml){
		var msg = getXML(xml,"msg");
		$("form",$(this)).hide();
		$("div.dStatus",$(this)).html(msg).show();
	});
	
	$("#footer_newsletter_form").vucxForm(function(xml){
		//var msg = getXML(xml,"msg");
		//$("form",$(this)).hide();
		//$("div.dStatus",$(this)).html(msg).show();
	});
	
	$("#quickmal").vucxForm(function(xml){
		//var msg = getXML(xml,"msg");
		//$("form",$(this)).hide();
		//$("div.dStatus",$(this)).html(msg).show();
	});

	$("#hotline").vucxForm(function(xml){
		//var msg = getXML(xml,"msg");
		//$("form",$(this)).hide();
		//$("div.dStatus",$(this)).html(msg).show();
	});

	$("#booking_packages").vucxForm(function(xml){
	//var msg = getXML(xml,"msg");
	//$("form",$(this)).hide();
	//$("div.dStatus",$(this)).html(msg).show();
	});	

}
	
	$('#input_message').focus(function() {
		if($(this).html()==$(this).attr('name')){
			$(this).html('');
		}
	});
	$('#input_email, #input_search').focus(function() {
		if($(this).val()==$(this).attr('name')){
			$(this).val('');
		}
	});
	$('#input_message').blur(function() {
		if($(this).html()==''){
			$(this).html($(this).attr('name'));
		}
	});
	$('#input_email, #input_search').blur(function(){
		if($(this).val()==''){
			$(this).val($(this).attr('name'));
		}
	});
	$('#input_search').keyup(function(){
		var href = $('.Search_Send').attr('href').split('search=');
		$('.Search_Send').attr('href',href[0]+'search='+$(this).val());
	});
	
	function constructSearchLinkHref(){
		var href=$('.Search_Send').attr('href');
		href = href.replace('/hotel/','/hotels/');
		var fields = ['lage','stil','erlebnis','inspiration','capacity','topic','timespan'];
		for(var i=0;i<fields.length;i++){
			if($('#search_'+fields[i]+' input[type=checkbox]:checked').length>0){
				var param='';
				$('#search_'+fields[i]+' input[type=checkbox]:checked').each(function(){
					param=param+$(this).attr('value')+'~';
				});
				href=href+'&'+fields[i]+'='+param;
			}
		}
		if($('#search_price input[type=checkbox]:checked').length>0){
			href=href+'&preis='+$('#search_price [type=checkbox]:checked').val();
		}
		if($('.Geo_Place_Active').length>0 && $('.Geo_Place_Active').val()!='0'){
			href=href+'&place='+$('.Geo_Place_Active').val();
		}else if($('.Geo_Region_Active').length>0 && $('.Geo_Region_Active').val()!='0'){
			href=href+'&region='+$('.Geo_Region_Active').val();
		}else if($('#search_geo_land').val()!='0' && $('#search_geo_land').length>0){
			href=href+'&land='+$('#search_geo_land').val();
		}
		return escape(href);
	}

	$('#search_price input').click(function(){
		if(!$(this).attr('checked')){
			$(this).attr('checked',false);
		}else{
			$('#search_price input[type=checkbox]').attr('checked',false);
			$(this).attr('checked',true);
		}
	});
	$('#search_capacity input').click(function(){
		if(!$(this).attr('checked')){
			$(this).attr('checked',false);
		}else{
			$('#search_capacity input[type=checkbox]').attr('checked',false);
			$(this).attr('checked',true);
		}
	});
	$('#search_timespan input').click(function(){
		if(!$(this).attr('checked')){
			$(this).attr('checked',false);
		}else{
			$('#search_timespan input[type=checkbox]').attr('checked',false);
			$(this).attr('checked',true);
		}
	});
	
	$('.Search_Send').click(function(){
		if($(this).hasClass('Offers')){
			$(window.location).attr('href',constructSearchLinkHref());
		}else{
			$(window.location).attr('href',$(this).attr('href'));
		}
		return false;
	});
	
	$('#results_prev,#results_next').click(function(e){
		e.preventDefault();
		$(window.location).attr('href',constructSearchLinkHref()+'&results='+$(this).attr('href'));
	});
	
	$('#search_geo_land').change(function(){
		$('.Search_Geo_Region').removeClass('Geo_Region_Active');
		$('.Search_Geo_Place').removeClass('Geo_Place_Active');
		if($(this).val()!='0'){
			$('.Search_Geo_Region#'+$(this).val().trim()).addClass('Geo_Region_Active');
		}
	});
	$('.Search_Geo_Region').change(function(){
		$('.Search_Geo_Place').removeClass('Geo_Place_Active');
		if($(this).val()!='0'){
			$('.Search_Geo_Place#'+$(this).val()).addClass('Geo_Place_Active');
		}
	});
	$('#search_delete').click(function(){
		$('#input_search').val('');
		var href = $('#search_send').attr('href').split('search=');
		$('#search_send').attr('href',href[0]+'search='+$('#input_search').val());
	});
	$('#search_deselect').click(function(){
		$('input[type=checkbox]').attr('checked',false);
	});
	$("#input_search").keypress(function(e) {
		if(e.keyCode == 13) {
			if($(this).hasClass('Offers')){
				$(window.location).attr('href',constructSearchLinkHref());
			}else{
				$(window.location).attr('href',$('.Search_Send').attr('href'));
			}
	//		$(window.location).attr('href',constructSearchLinkHref());
		}
	});
	$("#footer_newsletter").click(function(){
		$("#foot_newsletter").animate({
			height:'toggle',
		}, 500 );
	});
	$("#abort_newsletter").click(function(){
		$("#foot_newsletter").animate({
			height:'toggle',
		}, 500 );
	});
	$("#result_sort_asc").click(function(){
		$(window.location).attr('href',constructSearchLinkHref()+'&order=ASC');
	});
	$("#result_sort_desc").click(function(){
		$(window.location).attr('href',constructSearchLinkHref()+'&order=DESC');
	});
	$("#wrapper_search_hotels #results_left_bottom").hide();

	$(function() {                       //run when the DOM is ready
		$("#search_geo").click(function() {  //use a class, since your ID gets mangled
			$("#search_geo .Click_Feedback").toggleClass("active");      //add the class to the clicked element
		});
	});
	$(function() {                       //run when the DOM is ready
		$("#search_lage_handle").click(function() {  //use a class, since your ID gets mangled
			$("#search_lage_handle .Click_Feedback").toggleClass("active");      //add the class to the clicked element
		});
	});
	$(function() {                       //run when the DOM is ready
		$("#search_stil_handle").click(function() {  //use a class, since your ID gets mangled
			$("#search_stil_handle .Click_Feedback").toggleClass("active");      //add the class to the clicked element
		});
	});
	$(function() {                       //run when the DOM is ready
		$("#search_price_handle").click(function() {  //use a class, since your ID gets mangled
			$("#search_price_handle .Click_Feedback").toggleClass("active");      //add the class to the clicked element
		});
	});
	$(function() {                       //run when the DOM is ready
		$("#search_erlebnis_handle").click(function() {  //use a class, since your ID gets mangled
			$("#search_erlebnis_handle .Click_Feedback").toggleClass("active");      //add the class to the clicked element
		});
	});
	$(function() {                       //run when the DOM is ready
		$("#search_inspiration_handle").click(function() {  //use a class, since your ID gets mangled
			$("#search_inspiration_handle .Click_Feedback").toggleClass("active");      //add the class to the clicked element
		});
	});
});
	
