/* jQuery Clear-Input plugin  */

(function( $ ){
  // define the initialValue() function
  $.fn.initialValue = function(value) {
    if (value) {
      return this.attr('initial-value', value);
    } else {
      return this.attr('initial-value');
    }
  };
  
  $.fn.clearInput = function() {
    return this
      .focus(function(){
        if (this.value == $(this).initialValue()) {
          this.value = '';
        }
      })
      .blur(function(){
        if (this.value == '') {
          this.value = $(this).initialValue();
        }
      })
      .each(function(index, elt) {
        $(this).initialValue(this.value);
      });
  };

 
})( jQuery ); 


/* Redimenssion de la page A LA CARTE  */

(function($) {
 
    $.fn.AjusteSize = function() {
			$(window).load(function() { dotheresize(); });
      $(window).bind("resize",function() { dotheresize(); });
		};
		
function dotheresize() {
				
		$('.article-keycode').css("position","absolute");
 		var docheight = $('.container').outerHeight();
		 		
		if ( docheight < 680) {
			$('.article-keycode').css({'top':'-150px', 'padding':'0 0 150px 0', 'min-height':'650px'});
 				 $('body').css({'overflow':'auto'});
				 $('.container').css({'overflow':'visible'});
		}  else {
			
		$('.article-keycode').css({'top':'0', 'padding':'0', 'height':'100%'});
 				 $('body').css({'overflow':'hidden'});
				 $('.container').css({'overflow':'hidden'});
		}
  return this;
	 
}
	 
		
})(jQuery);

 









/* ******************************** */
/*  Initialisation des fonctions   */
/* ****************************** */

$(document).ready(function() {



/* ********************************** */
/*               GLOBAL              */
/* ******************************** */

/* clear input */
//$("input[type='text']").clearInput();
//$("input[type='email']").clearInput();
//$("input[type='password']").clearInput();
//$("textarea").clearInput();	

/* scrolling */
$('.block-overflow').jScrollPane({showArrows: true});

/* decoration */
if  ( $('.list-tabbox li:nth(0)').hasClass("active")) { $('.list-tabbox li a:nth(2)').css({'background-image':'none'}) }
if  ( $('.list-tabbox li:nth(1)').hasClass("active")) { $('.list-tabbox li a:nth(0)').css({'background-image':'none'}) ;  $('.list-tabbox li a:nth(2)').css({'background-image':'none'}) }
if  ( $('.list-tabbox li:nth(2)').hasClass("active")) { $('.list-tabbox li a:nth(0)').css({'background-image':'none'}) ;  $('.list-tabbox li a:nth(1)').css({'background-image':'none'}) }

$('.block-overflow ul li small:first').css({'background-image':'none', 'padding-top':'10px'});

var myeditorial = $('.editorial').height();
var myHeight = myeditorial - 60;
$('.aside-listrooms').css({'height':myHeight});

/* ASK PIERRE */
$("#ask-pierre").click(function(){
  if ($('.article-askpierre').hasClass("pierre-is-off")) {
    $('.article-askpierre').removeClass('pierre-is-off').addClass('pierre-is-on');
			$('#slide-2').slideDown();
  }
  else {
    $('.article-askpierre').addClass('pierre-is-off').removeClass('pierre-is-on');
				$('#slide-2').hide();
  }
});

/* Show/hide Why Book a specific room */
 $('.book-is-off #slide-1').css({'display':'none'});

 $("#book-room").click(function(){
  if ($('.article-booking').hasClass("book-is-off")) {
    $('.article-booking').removeClass('book-is-off').addClass('book-is-on');	
		$('#slide-1').slideDown();
  }
  else {
     $('.article-booking').addClass('book-is-off').removeClass('book-is-on');
		$('#slide-1').hide();
  }
});

/* formulaires */
$('.trans-form').jqTransform();

// Calendrier formulaires

$( "#arrival, #departure" ).datepicker({
  dateFormat: 'mm-dd-yy',
  defaultDate: "d",
  minDate: "d",
  firstDay: 1,
  changeMonth: true,
  numberOfMonths: 2,
  constrainInput: true,
  onSelect: function( selectedDate ) {
    var option = this.id == "arrival" ? "minDate" : "maxDate",
      instance = $( this ).data( "datepicker" ),
      date = $.datepicker.parseDate(
        instance.settings.dateFormat ||
        $.datepicker._defaults.dateFormat,
        selectedDate, instance.settings );
    dates.not( this ).datepicker( "option", option, date );
  }
});
		
/* light Box */
$('.lightbox').colorbox({inline:true});
$('a.gallery').colorbox({rel:'gal'});
 
/* ********************************** */
/*          PAGE HOME                */
/* ******************************** */

/* slider de la home */
 $('#carousel-home').slides({ 
 generateNextPrev: true,
 preload: true, 
 play: 5000,
 pause: 5500,
 slideSpeed: 600,
 hoverPause: false,
 currentClass: 'active' 
});

/* ********************************** */
/*          PAGE SEARCH              */
/* ******************************** */

/* show/hide options  */
$('#show-options').click(function() {
  var checkElement = $('.block-afine-content');
  if(  checkElement.is(':visible'))  {	
		checkElement.slideUp('normal').queue(function() {
		$('#show-options').removeClass('active');
		$(this).dequeue();
		});
		return false;
	}
  
  if( !checkElement.is(':visible'))  {
			checkElement.slideDown('normal')
		  $('#show-options').addClass('active');
	return false;
	}
 });

/* show/hide slider  */
$('#show-size').click(function() {
	$('.boxtype').slideUp(500);
		$('.block-afine-content .choice a').removeClass('active');
 
	$('.col2 .boxtype').hide();
	
  var checksize = $('.size-slider');
  
	if(  checksize.is(':visible'))  {			
		checksize.slideUp('normal').queue(function() {
		$('#show-size').removeClass('active');
		$(this).dequeue();
		});
		return false;
	}
  
  if( !checksize.is(':visible'))  {
			checksize.slideDown('normal')
		  $('#show-size').addClass('active');	
 
	return false;
	}
 });

 
 
// EFFET HOVER SUR LES VIGNETTES 
$('.article-selection .bookme').css({'display':'none'});
 
$(".article-selection figure").hover(function () {
     $(this).find('.bookme').stop().css({'display':'block'}); 
 },
   function () {
    $(this).find('.bookme').stop().css({'display':'none'});
});

$('.mode-vignette .bookhotel').css({'display':'none'});
  
$('.mode-vignette .vignette').hover(function () {
     $(this).find('.bookhotel').css({'display':'block'}); 
 },
   function () {
     $(this).find('.bookhotel').css({'display':'none'});		 
});

/* Show/hide Why Book with us */
$("#book-with-us").click(function(){

		var myPanelBook = $(this).parent().find('ul');
		 
		if ( myPanelBook.is(":hidden")) {
			$(this).parent().addClass('active');
			myPanelBook.slideDown(200);
			} else {
			myPanelBook.slideUp("Slow").queue(function() {
			 myPanelBook.parent().removeClass('active'); 
			$(this).dequeue();
		});
			}
		return false;
});

$("#contact-us").click(function(){

    var myPanelBook = $(this).parent().find('div');
     
    if ( myPanelBook.is(":hidden")) {
      $(this).parent().addClass('active');
      myPanelBook.slideDown(200);
      } else {
      myPanelBook.slideUp("Slow").queue(function() {
       myPanelBook.parent().removeClass('active'); 
      $(this).dequeue();
    });
      }
    return false;
});

$("#card-user-manage-information").click(function(){

    var myPanelBook = $(this).parent().find('form');
     
    if ( myPanelBook.is(":hidden")) {
      $(this).parent().addClass('active');
      myPanelBook.slideDown(200);
      } else {
      myPanelBook.slideUp("Slow").queue(function() {
        myPanelBook.parent().removeClass('active'); 
        $(this).dequeue();
      });
      }
    return false;
});


/* Sort me */
$('.search-bar ul li ul').hide();
$('.contact-us-container').hide();
$('#card-user-manage-information form').hide();
	 
$(".search-bar ul li a#sort-me").click(function(){
 		var mySlidePanel = $(this).parent().find('ul');
 		if ( mySlidePanel.is(":hidden")) {
			$(this).parent().addClass('active');
			mySlidePanel.slideDown(200);
			} else {
			mySlidePanel.slideUp("Slow").queue(function() {
			 mySlidePanel.parent().removeClass('active'); 
			$(this).dequeue();
		});
			}
		return false;
});

/* ferme en mouseleave */
$('ul li a#sort-me').parent().find('ul').mouseleave(function(){  
 $(this).slideUp("slow").queue(function() {
 $(this).parent().removeClass('active'); 
 $(this).dequeue();
 });		 
});

// ACTIVE LA PERSONNALISATION DES FORMULAIRES
$('.mode-liste').jqTransform();
$('.mode-vignette').jqTransform();
 
 
// PERMUTTE LE MODE VIGNETTE / LISTE
$('#mode-liste').click ( function() {
	$('.block-afine-content').slideUp("slow")
	$(this).addClass('active');
	$('#mode-vignette').removeClass('active');
	$('.mode-liste').show();
	$('.mode-vignette').hide()
 	return false
});
 
$('#mode-vignette').click ( function() {
	$('.block-afine-content').slideUp("slow")
	$(this).addClass('active');
	$('#mode-liste').removeClass('active');
	$('.mode-liste').hide();
	$('.mode-vignette').show()
 	return false
});




// AFFICHE LES BOITES DES CRITERES

$("#show-atmosphere").click(function(){
 	 	$('.boxtype').slideUp(500);
		$('.block-afine-content .choice a').removeClass('active');
		$('.size-slider').slideUp(200);		
		
 		if ( $('.atmosphere-boxtype').is(":hidden")) {
			$(this).addClass('active');
		$('.atmosphere-boxtype').slideDown(200);
 				
			} else {
	$('.atmosphere-boxtype').slideUp("Slow").queue(function() {
			 $('#show-atmosphere').removeClass('active'); 
			$(this).dequeue();
		});
			}
		return false;
});


$("#show-features").click(function(){
 	 
	  	 	$('.boxtype').slideUp(500);
		$('.block-afine-content .choice a').removeClass('active');
		$('.size-slider').slideUp(200);
		
		
 		if ( $('.features-boxtype').is(":hidden")) {
			$(this).addClass('active');
		$('.features-boxtype').slideDown(200);
			} else {
	$('.features-boxtype').slideUp("Slow").queue(function() {
			 $('#show-features').removeClass('active'); 
			$(this).dequeue();
		});
			}
		return false;
});
	
$("#show-property").click(function(){
 	 	$('.boxtype').slideUp(500);
		$('.block-afine-content .choice a').removeClass('active');
		$('.size-slider').slideUp(200);		
  		if ( $('.property-boxtype').is(":hidden")) {
			$(this).addClass('active');
			$('.property-boxtype').slideDown("Slow");	 
			} else {
	$('.property-boxtype').slideUp("Slow").queue(function() {
			 $('#show-property').removeClass('active'); 
			$(this).dequeue();
		});
			}
		return false;
});


$("#show-hotelfeatures").click(function(){
 	 	$('.boxtype').slideUp(500);
		$('.block-afine-content .choice a').removeClass('active');
		$('.size-slider').slideUp(200);
  		if ( $('.hotelfeatures-boxtype').is(":hidden")) {
			$(this).addClass('active');
			$('.hotelfeatures-boxtype').slideDown("Slow")
			} else {
	$('.hotelfeatures-boxtype').slideUp("Slow").queue(function() {
			 $('#show-hotelfeatures').removeClass('active'); 
			$(this).dequeue();
		});
			}
		return false;
});

$("#show-setting").click(function(){
 	 	$('.boxtype').slideUp(500);
		$('.block-afine-content .choice a').removeClass('active');
		$('.size-slider').slideUp(200);		
  		if ( $('.setting-boxtype').is(":hidden")) {
			$(this).addClass('active');
			 
 								$('.setting-boxtype').slideDown("Slow")
			} else {
	$('.setting-boxtype').slideUp("Slow").queue(function() {
			 $('#show-setting').removeClass('active'); 
			$(this).dequeue();
		});
			}
		return false;
});

 
 
 $("#show-getting").click(function(){
 	 	$('.boxtype').slideUp(500);
		$('.block-afine-content .choice a').removeClass('active');
		$('.size-slider').slideUp(200);
		
  		if ( $('.getting-boxtype').is(":hidden")) {
			$(this).addClass('active');
			 
 								$('.getting-boxtype').slideDown("Slow")
			} else {
	$('.getting-boxtype').slideUp("Slow").queue(function() {
			 $('#show-getting').removeClass('active'); 
			$(this).dequeue();
		});
			}
		return false;
});

/* ajoute les criteres */
function addCriteria() {
	
		 
		 
 
$(".boxtype p").each( function(){

 		var thenlabelinput = $(this).find('label').html();
		var reallabelinput =  thenlabelinput.replace(/ /g,'');
			 
			 $(this).find('input').addClass(reallabelinput);
			 $(this).find('a').addClass(reallabelinput);
			 
});
 
 		 
		 
// AJOUTE DES ITEMS
$(".boxtype p a").bind('click',function() {
				
	 		var thenlabel ="";
			$('ul.list-criteria').show();
			
			/* compte le nombre d'item */
			var nlisteitme = $(".list-criteria li ul li ").length;
		
			/* cherche le text du label */					 	
			 var thenlabel = $(this).parent().parent().find('label').html();
			 var reallabel =  thenlabel.replace(/ /g,'');
 	     var monnomclass = "." + reallabel;
 
 
			 if ( $(this).hasClass('jqTransformUnChecked') ) {
				 $('.list-criteria li').find(monnomclass).parent().remove();
					} else {
				 $('.list-criteria li ul').append('<li><a href="#" class="' + reallabel + '">' + thenlabel +'</a></li>');	
			 }
 
  			$('.list-criteria li a').bind('click', function () {
					
					var tnomclass = "";
					var tlabel = $(this).html();
					var treallabel =  tlabel.replace(/ /g,'');
    			var tnomclass = "." + treallabel;
 
		  
				$('.boxtype').find(tnomclass).addClass('jqTransformUnChecked ').removeClass('jqTransformChecked ');
				$('.boxtype').find(tnomclass).attr('checked',false);
			
  				if (  nlisteitme > 0 ||  nlisteitme == 0){
						$(this).parent().remove();			
 						}	else {
						$('ul.list-criteria').hide();
							return false
						}

					return false
				}); 	
 			return false
		 });
}

addCriteria();


  	 




		
/* ***************************** */
/*        DESTINATION           */
/* ***************************** */

/* carte map */
$('#europe').hover(function(){
		$('.image2').show();
		$('.image1').hide(); 
});

$('#europe2').mouseleave(function(){	
	 	if ($('.block-formdesination').is(":hidden")) {
   	$('.image2').hide();
		$('.image1').show(); 
      } else {
 	$('.image2').show();
		$('.image1').hide(); 
      }
	  return false;
}); 	

 	
$('#europe2').click(function() { 
	$('.block-formdesination').removeClass('hiddeme').addClass('showme');
	$('#dropmenu').jScrollPane({showArrows: false});
	return false
}); 
  
$('body').click(function(event){
       if($(event.target).parents().index($('.block-formdesination')) == -1) {
        if($('.block-formdesination').is(":visible")) {
            $('.block-formdesination').removeClass('showme').addClass('hiddeme')
        }
    } 
});

	
	
/* menu */
$('#dropmenu ul li ').find('ul').prepend('<li><a href="#" class="retour"><span>retour</span></a></li>');

$('#dropmenu ul > li > a').click(function() {  
	 heightpanel = " " ; 
	 var thispanel = $(this).parent().find('ul'); 
	 var nlenght = $(this).parent().find('ul > li').length;
	 
	 if ( nlenght > 0) {
		 var heightpanel = nlenght * 29 ;
		 
		 $('#dropmenu ul').css({ 'height': heightpanel });
 
		 thispanel.animate({ left: '0' }, 500);
		
		 $('.jspDrag').css({'top': '0'});
		 $('.jspPane').css({'top': '0'});
 }  
 return false
});
		
$('#dropmenu ul > li  > ul  >li > a.retour').click(function() {
 	$(this).parent().parent().animate({ left: '235px' }, 500);
	$('#dropmenu ul').css({'height':'auto'});
	 $('.jspDrag').css({'top': '0'});
	 $('.jspPane').css({'top': '0'});
	  return false
}); 

/* end document */
});
