var pmrReservations = {
	dates: []
};

$(function() {
		$('#additional-areas').clone().addClass('hover-smallstates').appendTo('#map-content').hide();
		$('#california-area').click(function() { 
			$('#california-areas').slideToggle();
			return false;
		});
		$('#small-states').click(function() { 
			$('.hover-smallstates').slideToggle();
			return false;
		});

		$("#rent-start").datepicker({ 
			numberOfMonths: [1,3], 
			minDate: 0, 
			showAnim: 'fadeIn'
		});
		
		$("#rent-end").datepicker({ 
			numberOfMonths: [1,3], 
			minDate: +2, 
			showAnim: 'fadeIn' 
		});

		jQuery.extend({
			getValues: function(url) {
				pmrReservations.dates = null;
				$.ajax({
					url: url,
					type: 'get',
					dataType: 'json',
					async: false,
					success: function(data) {
						pmrReservations.dates = data;
					}
				});
				return pmrReservations.dates;
			}
		});
		if ($.url.param('vid') !== undefined) {
			$.getValues('/content/available/'+$.url.param('vid'));
		}
		
		$("#vehicle-rent-start").datepicker({ 
			numberOfMonths: [1,3], 
			minDate: 0, 
			showAnim: 'fadeIn',
			beforeShowDay: function(date) {
				date = date.getTime();
				for (i in pmrReservations.dates) {
					if (date >= pmrReservations.dates[i].startDate && date <= pmrReservations.dates[i].endDate) {
						return [false, ''];
					}
				}
				return [true, ''];
			}
		});
		
		$("#vehicle-rent-end").datepicker({ 
			numberOfMonths: [1,3], 
			minDate: +2, 
			showAnim: 'fadeIn',
			beforeShowDay: function(date) {
				timestamp = date.getTime();
				for (i in pmrReservations.dates) {
					if (($("#vehicle-rent-start").val() !== undefined && $("#vehicle-rent-start").val() >= date.format("mm/dd/yyyy")) || 
							(timestamp >= pmrReservations.dates[i].startDate && timestamp <= pmrReservations.dates[i].endDate)) {
						return [false, ''];
					}
				}
				return [true, ''];
			}
		});
		
		
		
		
		
		$('#main-nav li').hover(function(){
			$(this).find('ul').slideDown('medium');		
		},function(){
			$(this).find('ul').fadeOut('fast');
		});
	
		$('#quick-search h3 a').click(function(){
			$('#quick-search-content').slideToggle();
			return false;
		});


		$('#vehicle-type span').hover(function(){
			$(this).find('.img').fadeIn('medium');		
		},function(){
			$(this).find('.img').fadeOut('fast');
		});

		$('#owner-signin #owner-login').click(function(){
			$('#owner-signin div').slideToggle();
			return false;
		});
		
		// domain = location.href;
		// 		domain = domain.replace(/http[s]?:\/\//, "");
		// 		domain = domain.replace(location.pathname, "");
		// 		domain = domain.replace(location.search, "");
		// 
		// 		$('a').each(function() {
		// 				var link = $(this).attr("href");
		// 				if ((link.indexOf('http') == 0) && (link.indexOf(domain) == -1)) {
		// 					$(this).click(function() {
		// 						window.open(this.href);
		// 						return false;
		// 					});
		// 				}
		// 		});

	$('.rollup dt').addClass('trigger').each( function(n) {
		$(this).click( function() {
			$(this).next().toggle();
		}).click();
	});

	$('a.fill-in-address').click(function() {
			$('#shipping_street_1').val($('#billing_street_1').val());
			$('#shipping_street_2').val($('#billing_street_2').val());
			$('#shipping_city').val($('#billing_city').val());
			$('#shipping_state').val($('#billing_state').val());
			$('#shipping_zip').val($('#billing_zip').val());
			$('#shipping_country').val($('#billing_country').val());
	});

	$('div#canada-content').hide();

	$("#canada").click(function() {
			$('div#map-content').toggle();
			$('div#canada-content').toggle();
			return false;
	});
	$("#usa").click(function() {
			$('div#canada-content').toggle();
			$('div#map-content').toggle();
			return false;
	});
	$(".thumb-gallery").jCarouselLite({
		btnNext: ".next",
		btnPrev: ".prev",
		height: 100,
		visible: 1
	});

	$("a[rel=lightbox]").lightbox({
			fitToScreen: true,
			imageClickClose: false
	});

	// $("a.contact-owner").click(function () {
	// 			vid = $("#vehicle-id").html()
	// 			$("#owner-contact-info").load('/owner/contact-info', "vid="+vid).fadeIn()
	// 			return false;
	// 	});
		
});


