$(document).ready(function() {

	// Forms
        	
    	// Update Value
	    $('input').each(function() {
		    var default_value = this.value;
		    $(this).focus(function() {
		        if(this.value == default_value) {
		            this.value = '';
		        }
		    });
		    $(this).blur(function() {
		        if(this.value == '') {
		            this.value = default_value;
		        }
		    });
		});
		
		$('textarea').each(function() {
		    var default_value = this.value;
		    $(this).focus(function() {
		        if(this.value == default_value) {
		            this.value = '';
		        }
		    });
		    $(this).blur(function() {
		        if(this.value == '') {
		            this.value = default_value;
		        }  
		    });
		});

		// Custom Elements 
		$('.selectbox select option:first-child').attr('selected', 'selected');
		
		$('.selectbox span').each(function() {
			var s = $(this).parents('.selectbox');
			$(this).html($(this).parents('.selectbox').find('select option:eq(0)').html());
		});
		
		$('.selectbox').change(function() {
			$(this).addClass('selectbox-changed');
			$('span', this).html($(this).find(':selected').text());
			var selected_val = $(this).find(':selected').val();
			$('select option', this).removeAttr('selected');
			$('select option[value="'+selected_val+'"]', this).attr('selected', 'selected');
		});
		
		$('select').focus(function() {
		    $(this).closest('.selectbox').addClass('selectbox-focus');
		});
		
	    $('select').blur(function() {
		    $(this).closest('.selectbox').removeClass('selectbox-focus');
		});
		
		$('.check-list input').click(function() {
			$(this).siblings('.checkbox').toggleClass('checkbox-checked');
			$(this).siblings('label').toggleClass('label-checked');
		});
		
		// Textarea Auto-Grow
	    $.fn.autogrow = function(options) {
	        
	        this.filter('textarea').each(function() {
	            
	            var $this       = $(this),
	                minHeight   = $this.height(),
	                lineHeight  = $this.css('lineHeight');
	            
	            var shadow = $('<div></div>').css({
	                position:   'absolute',
	                top:        -10000,
	                left:       -10000,
	                width:      $(this).width() - parseInt($this.css('paddingLeft')) - parseInt($this.css('paddingRight')),
	                fontSize:   $this.css('fontSize'),
	                fontFamily: $this.css('fontFamily'),
	                lineHeight: $this.css('lineHeight'),
	                resize:     'none'
	            }).appendTo(document.body);
	            
	            var update = function() {
	    
	                var times = function(string, number) {
	                    for (var i = 0, r = ''; i < number; i ++) r += string;
	                    return r;
	                };
	                
	                var val = this.value.replace(/</g, '&lt;')
	                                    .replace(/>/g, '&gt;')
	                                    .replace(/&/g, '&amp;')
	                                    .replace(/\n$/, '<br/>&nbsp;')
	                                    .replace(/\n/g, '<br/>')
	                                    .replace(/ {2,}/g, function(space) { return times('&nbsp;', space.length -1) + ' ' });
	                
	                shadow.html(val);
	                $(this).css('height', Math.max(shadow.height() + 20, minHeight));
	            
	            }
	            
	            $(this).change(update).keyup(update).keydown(update);
	            
	            update.apply(this);
	            
	        });
	        
	        return this;  
	    };
	    
	    $('textarea').autogrow();
		

	// Navigation
	$('#subnav li:last').css('border-right', '0 none');
	$('#nav-tour li:last').css('border-right', '0 none');

	// Footer
	// $('#footer-nav li:first').css('text-align', 'left');
	// $('#footer-nav li:last').css('text-align', 'right');
    
    // Special Offers Tab
    var msie6 = $.browser == 'msie' && $.browser.version < 7;
      
    if (!msie6) {
    
        var top = $('.side-tab').offset().top - parseFloat($('.side-tab').css('margin-top').replace(/auto/, 0));
        $(window).scroll(function (event) {
          var y = $(this).scrollTop();
          
          if (y >= top) {
            $('.side-tab').addClass('fixed');
          } else {
            $('.side-tab').removeClass('fixed');
          }
        });
    
    }        
    
    // Grids
    
    	// See More
    	$('.grid-multiple').each(function() {
    		var grid = $(this);
    		var gridlets = $(this).children('.grid-item');
    		var moar = $(this).children('a.see-more-grid');
    	
    		$(gridlets).slice(3).hide();
		    
		    $(moar).toggle(function (e) {
		    	e.preventDefault();
		       	$(gridlets).slice(3).slideDown();
				$(moar).children('span.more-less').text('See Fewer');
		    }, function (e) {
		      	e.preventDefault();
		      	$(gridlets).slice(3).slideUp();
		      	$(moar).children('span.more-less').text('See More');
		      	$('html,body').animate({scrollTop: $(grid).offset().top}, 200);
		    }); 
    	});
    	
    	// Unique Events
    	$('#see-more-uniques').toggle(function (e) {
    		e.preventDefault();
    		$('#grid-unique-venues .grid-item').slice(3).slideDown();
    		$('#yachting-wrapper').slideDown();
    		$('#see-more-uniques').children('span.more-less').text('See Fewer');
    	}, function (e) {
    		e.preventDefault();
    		$('#grid-unique-venues .grid-item').slice(3).slideUp();
    		$('#yachting-wrapper').slideUp();
    		$('#see-more-uniques').children('span.more-less').text('See More');
    		$('html,body').animate({scrollTop: $('#unique-venues-wrapper').offset().top}, 200);
    	});
    	
    	// Tour Lists
    	$('.tour-list').each(function() {
    		var tourlist = $(this);
    		var touritems = $(this).children('.tour-item');
    		var moartour = $(this).children('a.see-more-tours');
    	
    		$(touritems).slice(2).hide();
		    
		    $(moartour).toggle(function (e) {
		    	e.preventDefault();
		       	$(touritems).slice(2).slideDown();
				$(moartour).children('span.more-less').text('See Fewer');
		    }, function (e) {
		      	e.preventDefault();
		      	$(touritems).slice(2).slideUp();
		      	$(moartour).children('span.more-less').text('See More');
		      	$('html,body').animate({scrollTop: $(tourlist).offset().top}, 200);
		    }); 
    	});
    	
    	// Golf 
    	
    	$('#see-more-golf').toggle(function (e) {
    		e.preventDefault();
    		$('#grid-golf').slideDown();
    		$('#see-more-golf').children('span.see-hide').text('Hide');
    	}, function (e) {
    		e.preventDefault();
			$('#grid-golf').slideUp();
			$('#see-more-golf').children('span.see-hide').text('See');
    	});
    	
    	// Room Tour
    	
    	$('#room-slideshow .room-slide:first').addClass('show');
    	
    	$('#image-map a').each(function() {
    
	    	var samesies = $(this).attr('id');
	    	
	    	$(this).hover(function () {
	    		$('#room-slideshow .room-slide:first').removeClass('show');
			    $('#room-slideshow').find('.' + samesies).addClass('show');
			  },
			  function () {
			    $('#room-slideshow').find('.' + samesies).removeClass('show');
			    $('#room-slideshow .room-slide:first').addClass('show');
			});
			
		});
		
	// Meeting Space
	$('#image-map a').tooltips();

});
