// Fix for IE6 background image hover flicker
try {
 document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

// JQuery 
$(document).ready(function() {
	// Date picker for the Vacation Planner module:
	$("#planner_arrival").datepicker({
	changeMonth: true,
	changeYear: true,
	numberOfMonths: 2,
	altField: '#planner_departure',
	minDate: 0,
	buttonText: "calendar",
	showOn: 'both', buttonImage: '/images/icon_calendar.gif', buttonImageOnly: true
	});

	$("#planner_departure").datepicker({
	changeMonth: true,
	changeYear: true,
	numberOfMonths: 2,
	minDate: 0,
	buttonText: "calendar",
	showOn: 'both', buttonImage: '/images/icon_calendar.gif', buttonImageOnly: true
	});

	$(".add_to_cart_datepicker_arrival").datepicker({
	changeMonth: true,
	changeYear: true,
	numberOfMonths: 2,
	altField: '#res_end_date',
	minDate: 0,
	buttonText: "calendar",
	showOn: 'both', buttonImage: '/images/icon_calendar.gif', buttonImageOnly: true
	});

	$(".add_to_cart_datepicker_departure").datepicker({
	changeMonth: true,
	changeYear: true,
	numberOfMonths: 2,
	minDate: 0,
	buttonText: "calendar",
	showOn: 'both', buttonImage: '/images/icon_calendar.gif', buttonImageOnly: true
	});

	$(".contact_datepicker_arrival").datepicker({
	changeMonth: true,
	changeYear: true,
	numberOfMonths: 2,
	altField: '#contact_end_date',
	minDate: 0,
	buttonText: "calendar",
	showOn: 'both', buttonImage: '/images/icon_calendar.gif', buttonImageOnly: true
	});

	$(".contact_datepicker_departure").datepicker({
	changeMonth: true,
	changeYear: true,
	numberOfMonths: 2,
	minDate: 0,
	buttonText: "calendar",
	showOn: 'both', buttonImage: '/images/icon_calendar.gif', buttonImageOnly: true
	});

	// A more universal method of using datepicker than the above
	$("input.datepicker").datepicker({ 
	changeMonth: true,
	changeYear: true,
	numberOfMonths: 2,
//	altField: '#res_end_date',
	minDate: 0,
	buttonText: "calendar",
	showOn: 'both', buttonImage: '/images/icon_calendar.gif', buttonImageOnly: true
	});

	$("input.unit_datepicker").datepicker({ 
	changeMonth: true,
	changeYear: true,
	numberOfMonths: 2,
	altField: '#unit_quote_departure',
	minDate: 0,
	buttonText: "calendar",
	showOn: 'both', buttonImage: '/images/icon_calendar.gif', buttonImageOnly: true
	});

	// A more universal method of using datepicker than the above
	$("input.datepicker_no_icon").datepicker({ 
	changeMonth: true,
	changeYear: true,
	numberOfMonths: 2,
//	altField: '#res_end_date',
	minDate: 0,
	buttonText: "calendar",
	showOn: 'focus'
	});
	
	
	// Home page effects for island maps
	$("#islands_map dl").each(function(){
		$(this).children('dd.summary').css({
			opacity: 0
		});
	}).hoverIntent(function(){
		$(this).children('dd.summary').animate({
			opacity: 1
		})
	}, function(){
		$(this).children('dd.summary').animate({
			opacity: 0
		})
	});
	
	// Embed video in tour
	
	
	$("div.tour div.video").each(function(){
		path = $(this).children('a.src').attr('rel');
		$(this).flashembed({
			src: '/FlowPlayerLight.swf',
			width: 313,
			height: 255
		}, {
		config:	{
			autoPlay: false,
			initialScale: 'scale',
			videoFile: path
		}});
	})
	
	$("div.tour div.slideshow").flashembed({
		src: $("div.tour div.slideshow a.src").attr("rel"),
		width: 313,
		height: 235,
		wmode: 'opaque'
	}, {
		autoPlay: true
	});
	
	$("#slideshow-gallery .show").click(function(){
		path = $(this).children('.slideshow').children('a.src').attr('rel')
		$(this).flashembed({
			src: path,
			width: 313,
			height: 235,
			base: path.replace(/([^/]+).swf/,'')
		}, {
			autoPlay: false
		});
	});
	
	$("#photo-gallery div.room img").click(function(){
		$("#photo-gallery div.viewer img").attr('src', $(this).attr("src").replace('icon', 'small'))
		$("#photo-gallery div.viewer p.caption").html("").html($(this).attr("alt"))
	});
	
	$("#photo-gallery div.room").click(function(){
		$("#photo-gallery div.room").attr("class", "room")
		$(this).attr("class", "room active") 
	});
	
	
	// Unobtrusive RJS
	$("a.rjs").click( function() {
		$.ajax({
			url: this.href,
			dataType: "script",
			beforeSend: function(xhr) {xhr.setRequestHeader("Accept", "text/javascript");}
		});
		return false;
	});
	

	
});


// Static Functions that can be called from RJS templates to spawn specific actions:
function loadSlideshow(path) {
	$("#slideshow-gallery .show").flashembed({
		src: path,
		width: 475,
		height: 356,
		base: path.replace(/([^/]+).swf/,'')
	}, {
		autoPlay: false
	});
}

