$(function() {
	
	$('input').each(function() { $(this).addClass(this.type); });
	$('.rollover').simpleImageRollover();
	
	setTimeout(function() {
	    $('#top-teaser, #newsletter-signup').animate({opacity: 0});
	}, 3000);
	
	$('#banner').hover(function() {
	    $('#top-teaser, #newsletter-signup').stop().animate({opacity: 0.8});
	}, function() {
	    $('#top-teaser, #newsletter-signup').stop().animate({opacity: 0});
	})
	
	if (window.BANNERS) {
		window.BANNERS.push(window.BANNERS.shift());
		setInterval(function() {
			var nextImage = window.BANNERS.shift();
			$('<img class="banner"/>').attr('src', nextImage).prependTo('#banner');
			window.BANNERS.push(nextImage);
			setTimeout(function() {
				$('#banner .banner:last').animate({opacity: 0}, function() {
					$(this).remove();
				});
			}, 4000);
		}, 5000);
	}
	
	$(window).load(function() {
		var selected = $('#footer-nav .selected');
		if (selected.length) {
			var arrow = $('<img src="/sites/1/static/images/footer-nav-selected.gif" id="arrow" />');
			function arrowPositionFor(ele) {
				return ele.offsetLeft + (ele.offsetWidth - 13) / 2;
			}
			function animateArrowTo(ele) {
				arrow.stop().animate({left: arrowPositionFor(ele)});
			}
			arrow.css({left: arrowPositionFor(selected[0])});
			$('#footer .footer-inner').append(arrow);
			$('#footer-nav li:not(.selected)').hover(function() {
				animateArrowTo(this);
			}, function() {
				animateArrowTo(selected[0]);
			});
		}
	});
	
	// if (GBrowserIsCompatible()) {
	// 	$('.map').each(function() {
	// 		var map = new GMap2(this);
	// 		map.setCenter(new GLatLng(37.4419, -122.1419), 13);
	// 	});
	// }
	
	$('.content').each(function() {
		$(this).find(':first').addClass('first');
	});
	
	$('.sidebar-images a, .accommodation-gallery a, .image-box a, .inline-gallery a').lightBox();
	
	var movieSeq = 0;
	$('a[rel=movie]').each(function() {
		var movie = this.href,
			s = new SWFObject('/sites/1/static/images/video/player.swf', 'the-movie', '640', '480', '9', '#ffffff');
		s.addParam('allowfullscreen', true);
		s.addVariable('file', this.href);
		s.addVariable('autostart', true);
		// s.addVariable('stretching', 'fill');
		
		var c = $('<div class="movie-container" />').appendTo(document.body);
		s.write(c[0]);
		
		$(this).click(function() {
			new Boxy(c, {title: this.title, modal: true});
			return false;
		});
	});
	
	var cloudWidth = 1540,
		screenWidth = $(window).width(),
		cloudLeft = (screenWidth - cloudWidth) / 2;
		
	$('#banner-wrapper').css('backgroundPosition', cloudLeft + 'px 18px');
	
	setInterval(function() {
		cloudLeft += 1;
		$('#banner-wrapper').css('backgroundPosition', cloudLeft + 'px 18px');
	}, 700);
	
	$('.add-to-suitcase').boxy({modal: true, title: "Add to my selection"});
	
	$('.droppy').droppy();
	
	$('img.lightbox').each(function() {
		var href = this.src.replace(/(&|\?)p=[^&\?]+(&|\?|$)/, '$1p=default$2');
		$(this).wrap($('<a/>').attr({href: href, rel: 'lightbox', title: this.getAttribute('alt') }));
	});
	
	$('a[rel=lightbox]').lightBox();
	$('a[rel=boxy]').boxy();
	
});
