$(document).ready(function(){
	
		//Logo Drop Down Menu
	  $('#logo-menu').click(function() {
	    $(this).next().toggle();
	    $(this).toggleClass('open');
	    return false;
	  });
	
	  //Language dropdown
	  $('#cur-lang').click(function() {
	    $(this).next().toggle();
	    $(this).toggleClass('open');
	    return false;
	  });
	
	  //start - change this to 2 seperate functions - added by Annie
	  //date picker in booking boxes
	  $('#check_in').datepicker({
	        dateFormat: "dd-mm-yy",
		    minDate: 0,
		    maxDate: 357,
				defaultDate: 0,
		    speed: "fast",    
		    showOn: "focus",
		    changeMonth: false, 
		    changeYear: false,
		    closeAtTop: false,
		    		firstDay: 1,
		    numberOfMonths: 2
	  });
	   $('#check_out').datepicker({
	        dateFormat: "dd-mm-yy",
		    minDate: 1,
		    maxDate: 357,
				defaultDate: +1,
		    speed: "fast",    
		    showOn: "focus",
		    changeMonth: false, 
		    changeYear: false,
		    closeAtTop: false,
		    		firstDay: 1,
		    numberOfMonths: 2
	  });
	
	//end	
		
		
		//Additional date picker
	  $('#points-check-in,#points-check-out').datepicker({
		dateFormat: "dd-mm-yy",
	    minDate: 0,
	    maxDate: 500,
	    speed: "fast",    
	    showOn: "focus", 
	    changeMonth: false, 
	    changeYear: false,
	    closeAtTop: false,
	    numberOfMonths: 2
	  });
		
		//Selects range for date picker
		// function customRange(input) { 
		//     return {
		//       minDate: (input.id == "check-out" ? $("#check-in").datepicker("getDate") : null), 
		//       maxDate: (input.id == "check-in" ? $("#check-out").datepicker("getDate") : null)
		//     }; 
		// }
	
	  //Flex room detail price slider
	  var priceSize_flex = $('.room-slider-flex:first li').size();
	  if ($('.table-top-flex').hasClass('mult-room')) {
	    var priceRemainder_flex = priceSize_flex-5;
	  } else {
	    var priceRemainder_flex = priceSize_flex-7;    
	  }
	  var firstSlider_flex = $('.room-slider-flex:first');
	  $('#room-back-flex').hide();
	  firstSlider_flex.attr('rel', priceSize_flex);  
	  $('#room-forward-flex').click(function() {
	    $('#room-back-flex').show();      
	    curRel_flex = firstSlider_flex.attr('rel')-1;
	    firstSlider_flex.attr('rel', curRel_flex);
	    $('.room-slider-flex').animate({ left: '-=58px' }, 350);      
	    if(firstSlider_flex.attr('rel') == priceSize_flex-priceRemainder_flex) {
	      $(this).hide();
	    }
	    return false;
	  });
	  $('#room-back-flex').click(function() {
	    $('#room-forward-flex').show();
	    curRel_flex = firstSlider_flex.attr('rel');
	    curRel_flex++;
	    firstSlider_flex.attr('rel', curRel_flex);
	    $('.room-slider-flex').animate({ left: '+=58px' }, 350);      
	    if(firstSlider_flex.attr('rel') == priceSize_flex) {
	      $(this).hide();
	    }    
	    return false;
	  });

	  //Prepaid room detail price slider
	  var priceSize_prepaid = $('.room-slider-prepaid:first li').size();
	  if ($('.table-top-prepaid').hasClass('mult-room')) {
	    var priceRemainder_prepaid = priceSize_prepaid-5;
	  } else {
	    var priceRemainder_prepaid = priceSize_prepaid-7;    
	  }
	  var firstSlider_prepaid = $('.room-slider-prepaid:first');
	  $('#room-back-prepaid').hide();
	  firstSlider_prepaid.attr('rel', priceSize_prepaid);  
	  $('#room-forward-prepaid').click(function() {
	    $('#room-back-prepaid').show();      
	    curRel_prepaid = firstSlider_prepaid.attr('rel')-1;
	    firstSlider_prepaid.attr('rel', curRel_prepaid);
	    $('.room-slider-prepaid').animate({ left: '-=58px' }, 350);      
	    if(firstSlider_prepaid.attr('rel') == priceSize_prepaid-priceRemainder_prepaid) {
	      $(this).hide();
	    }
	    return false;
	  });
	  $('#room-back-prepaid').click(function() {
	    $('#room-forward-prepaid').show();
	    curRel_prepaid = firstSlider_prepaid.attr('rel');
	    curRel_prepaid++;
	    firstSlider_prepaid.attr('rel', curRel_prepaid);
	    $('.room-slider-prepaid').animate({ left: '+=58px' }, 350);      
	    if(firstSlider_prepaid.attr('rel') == priceSize_prepaid) {
	      $(this).hide();
	    }    
	    return false;
	  });
	
	  //sorting actions for hotel listing pages
	  var sortSlideSpeed = 500;
	  $('#sorting p.right a').click(function() {
	    if ($('#sorting p.right').children().hasClass('sort-open')) {
	      if ($(this).hasClass('sort-open')) {
	        $('#sort-map,#sort-names').slideUp(sortSlideSpeed%2);
	        $('.sort-open').removeClass('sort-open');
	      } else {
	        $('#sort-map,#sort-names').slideUp(300);
	        $('.sort-open').removeClass('sort-open');
	        $('#'+$(this).attr('rel')).show().hide().css({margin: 0}).slideDown(sortSlideSpeed);
	        $(this).addClass('sort-open');
	      }
	    } else {
	      $('#'+$(this).attr('rel')).show().hide().css({margin: 0}).slideDown(sortSlideSpeed);
	      $(this).addClass('sort-open');      
	    }
	    return false;
	  });

	
		// Add utility first/last/alt classes to LIs.
		$("ul li:first-child").addClass("first");
		$("ul li:last-child").addClass("last");
		$("ul li:nth-child(even)").addClass("alt");
		$("table tr:nth-child(even)").addClass("alt");
		
		// Replace HRs with Divs in IE
	  	if (jQuery.browser.msie) {
			$("hr").wrap("<div class='hr'></div>");
		}
		
		//Input focus and blur
		function switchText()
		{
			if ($(this).val() == $(this).attr('title')){
				$(this).val('').removeClass('blur');
			}
			else if ($.trim($(this).val()) == ''){
				$(this).addClass('blur').val($(this).attr('title'));
				if ($(this).attr('value') == 'dd/mm/yyyy'){
					$(this).removeClass('blur');
				}
			}
		}
		$('input[@type=text][title!=""]').each(function() {
			if ($.trim($(this).val()) == '') $(this).val($(this).attr('title'));
			if ($(this).val() == $(this).attr('title')) $(this).addClass('blur');
		}).focus(switchText).blur(switchText);
		
		//Questions/Input toggle
		$("a.showInput").click(function(){
			$(this).toggleClass("hide").next().toggleClass("hide");		
			return false; 
		});
		$("a.hideInput").click(function(){
			$(this).parent().parent().toggleClass("hide").prev().toggleClass("hide");
			return false; 
		});
		

		// Tab_options and Tabs: Two DIVs that interact using Rels and IDs
		$(".tabs li:first-child a").each(function(){
			$(this).addClass("current");
		});
		$(".tab-content").each(function(){
			$(this).children(":not(:first)").hide();	
		});
		$(".tabs a").click(function(){
			if ($(this).hasClass("current") == false)
				{
					var thisTarget = $(this).attr("href");
					$(this).parents(".tabs").find('a.current').removeClass('current');
					$(this).addClass('current');
					$(this).parents(".tabs").next().children(":visible").fadeOut(1, function() {
						$(thisTarget).fadeIn("fast", function(){
							//added by Simon
							if (thisTarget == "#tab-map-guide"){
								drawMap();
							}			
						});
					});
			}
			if(jQuery.browser.msie && jQuery.browser.version == '6.0') {
    		$(this).blur();
			}
			return false; 
		});
		
		$(".tab-controller").click(function(){
					var thisTarget = $(this).attr("href");
					if ($(".tabs a[href='"+ thisTarget +"']").hasClass("current") == false) 
						{
							$(".tabs a[href='"+ thisTarget +"']").parents(".tabs").find('a.current').removeClass('current');
							$(".tabs a[href='"+ thisTarget +"']").addClass('current');
							
							$(".tab-content").children(":visible").fadeOut(1, function() {
								$(thisTarget).fadeIn("fast", function(){
							//added by Simon
							if (thisTarget == "#tab-map-guide"){
								drawMap();
							}
						});
					});
				}
					return false;
		});
				
});






