	
if (typeof(lpUnit)=='undefined')	var lpUnit='islandroutes';	


var month=new Array(12);
month[0]="January";
month[1]="February";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";

var currentTime = new Date();
var qqMonth = month[currentTime.getMonth()];
var qqDay = currentTime.getDate() + 7;
var qqYear = currentTime.getFullYear();
var referralID = "";

var bookBox;
var bookNowID = '';

function refreshCart(){
	$('#cart-items').empty();
	$('.cart_empty').hide();
	$('#cart-items').html(loadingAjax());
	$.get(
		'/ajax/getCart.cfm?t='+Math.random(),
		function(arrCart){
			if(arrCart.length>0) {
				$('#cart-items').empty();
				$('#checkout').show();
				$('.cart_empty').hide('fast');
			} else {
				$('#cart-items').empty();
				$('#checkout').hide();
				$('.cart_empty').show('fast');
			}
			var cTotal = 0;
			$.each(arrCart,function(i,v){
				var cSubtotal = (v.adults*v.adultsPrice)+(v.kids*v.kidsPrice);
				cTotal += cSubtotal;
				var oCartItem = $('#shopping-cart-item').clone();
				oCartItem.attr('id','shopping-cart-item-'+v.tourLocationID).addClass('shopping-cart-item');
				oCartItem.find('.tour-name-col').text(v.tourName);
				oCartItem.find('.tour-date-col').text(v.date);
				oCartItem.find('.tour-time-col').text(v.time);
				oCartItem.find('.tour-adults-col').text(v.adults);
				oCartItem.find('.tour-kids-col').text(v.kids);
				oCartItem.find('.tour-price-col').text('$'+getDecimalNum(cSubtotal,2));
				oCartItem.find('.remove').attr('id','remove-'+v.itemID);
				oCartItem.find('.remove').attr('resmark_id',v.resmarkID);
				$('#cart-items').append(oCartItem.show());
			});
			$('#subtotal-amount').text('$'+getDecimalNum(cTotal,2));
			$('#cart-item-count').text(arrCart.length);
		},
		'json'
	);
}

$(document).ready(function(){

	refreshCart();

	$('.pickupLoc').hover(
		function(){
			var tipID = this.id;
			$("#"+tipID).show();
		},
		function(){
			var tipID = this.id;
			$("#"+tipID).hide();
		}
	);
	
	$('.book-now').live('click',function(){		
		if($(this).attr('id') != bookNowID){
			$('#book-date').val('');
			$('#book-time-row').hide();
			$('#book-adults-row').hide();
			$('#book-children-row').hide();
			$('#book-submit-row').hide();
			$('#book-loading-row').hide();
			$('#book-msg-display').hide();
			$('#no-book-row').hide();
			$('#no-time-row').hide();
			
			// Reset Box
			$('#book-add-row').hide();
			$('#book_msg_added').hide();
			$('#book-date-row').show();
			
			bookBox = $('#book-box').detach();
			var lstTmpDays = $(this).next().text().split(',');
			var lstTmpDayInt = [];
			$.each(lstTmpDays, function(index, value){
				if(value == 'sun'){
					lstTmpDayInt.push(0);
				} else if(value == 'mon'){
					lstTmpDayInt.push(1);
				} else if(value == 'tue'){
					lstTmpDayInt.push(2);
				} else if(value == 'wed'){
					lstTmpDayInt.push(3);
				} else if(value == 'thu'){
					lstTmpDayInt.push(4);
				} else if(value == 'fri'){
					lstTmpDayInt.push(5);
				} else {
					lstTmpDayInt.push(6);
				}
			});
			lstDaysOfWeek = lstTmpDayInt;
			$(this).parent().prepend(bookBox);
			$('#book-box').show();
			bookNowID = $(this).attr('id');
			if($(this).parent().parent().attr('id')=='contNowPrice'){clearTimeout(timer);playSlideShow = false;}
		} else {
			$('#book-box').toggle();
		}
	});
	
	$('#book-date').datepicker({
		dateFormat: 'mm/dd/yy',
		defaultDate:+2,
		minDate:+2,
		showOn: 'both',
		buttonImage: '/images-site/img_calendar-icon.gif',
		buttonImageOnly: true,
		beforeShowDay: function(thisDate){
			var thisDayOfWeek = thisDate.getDay();
			var dayIsEligible = 0;
			$.each(lstDaysOfWeek, function(index, value){
				if(value == thisDayOfWeek){
					dayIsEligible = 1;
				}
			});
			return [dayIsEligible,''];
		},
		onSelect:function(dateText){
			$('#book-time-row').hide();
			$('#book-adults-row').hide();
			$('#book-children-row').hide();
			$('#book-submit-row').hide();
			$('#book-loading-row').show();
			resmarkId = bookNowID.substr(5);
			$.get(
				'/ajax/jsonAvailability.cfm?date='+dateText+'&resmarkID='+resmarkId,
				function(oAvail){
					tourLocationID = oAvail.tourLocationID;
					tourName = oAvail.tourName;
					$.each(oAvail.rates, function(i,v){
						if(v.rateTypeID == 1){
							adultsPrice = v.rate;
						}else if(v.rateTypeID == 2){
							childrenPrice = v.rate;
						}
					});
					var timeslotOptions = '';
					if(oAvail.schedule.length){
						$('#no-book-row').fadeOut('slow');
						$('#no-time-row').fadeOut('slow');
						$('#book-msg-display').fadeOut('slow');
						timeslotOptions += '<option value="">Select one</option>';
						$.each(oAvail.schedule, function(i,v){
							timeslotOptions += '<option value="'+v.startTime+'">'+v.startTime+'</option>';
						});
						$('#book-timeslot').html(timeslotOptions);
						$('#book-time-row').show();
					}else{
						$('#no-book-row').fadeOut('slow');
						$('#book-msg-display').fadeIn('slow');
						$('#no-time-row').fadeIn('slow');
					}
					$('#book-loading-row').hide();
				},
				'json'
			);
		}
	});
	
	$('#book-timeslot').change(function(){
	 	$.get(
	 		'/ajax/jsonSpots.cfm?tourLocationID='+tourLocationID+'&date='+$('#book-date').val()+'&time='+$('#book-timeslot').val()+':00',
			function(arrSpots){
				if(arrSpots.status != 'closed' && arrSpots.spotsAvailable>0){
					$('#book-adults-price').text('$'+adultsPrice);
					$('#book-children-price').text('$'+childrenPrice);
					$('#book-adults-row').show();
					if(childrenPrice>0){$('#book-children-row').show();}
					$('#book-submit-row').show();
				}else{
					$('#no-book-row').fadeIn('slow');
					$('#no-time-row').hide();
					$('#book-msg-display').fadeIn('slow');
				}
			},
			'json'
		);
	});
	
	$('#book-box .closeBook').live('click',function() {
		$('#book-box').hide('fade',function() {
			$('#book-add-row').hide();
			$('#book_msg_added').hide();
			$('#book-date-row').show();
		});
	});
	
	$('#book-add').live('click',function(){
		$.post('/ajax/addItem.cfm',
			{
				cartID : cartID,
				tourName : tourName,
				tourLocationID : tourLocationID,
				date : $('#book-date').val(),
				time : $('#book-timeslot').val()+':00',
				adults : $('#book-adults').val(),
				children : $('#book-kids').val(),
				adultsPrice : adultsPrice,
				kidsPrice : childrenPrice,
				resmarkID : resmarkId
			},
			function(){
				changeBookNowButton(bookNowID);
				refreshCart();
				$('#book-date').val('');
				$('#book-date-row').hide();
				$('#book-time-row').hide();
				$('#book-adults-row').hide();
				$('#book-children-row').hide();
				$('#book-submit-row').hide();
				$('#book_msg_added').show('fade');
			}
		);
	});
	
	//toggle view cart
	$('#btn-view-cart').click(function(){
		$('#shopping-cart').slideToggle();
		$(this).toggleClass('selected');
	});
	
	//also close shopping cart if clicking outside of it
	$('body').click(function(){
		if($('#shopping-cart').is(':visible')){$('#btn-view-cart').click();}
	});
	$('#header').click(function(e){
		e.stopPropagation(); 
	});
	
	if($('#cobrand-bar').length > 0) {
		referralID = '&referral='+$('#cobrand-bar').attr('referralid');
	}
	
	$('#btn-checkout,.goCheckout').click(function() {
		$.cookie('ITEMSADDED',null);
		document.location = obeURL+'?cartID='+cartID+referralID;
	});
	
	$('#cart-items').delegate('.remove', 'click', function(){
		var itemTID = $(this).attr('id').substr(7),
			resmarkID = $(this).attr('resmark_id');

		$.post('/ajax/removeItem.cfm',
			{
				itemID: itemTID,
				resmarkID: resmarkID
			},
			function(){
				refreshCart();
				changeBookNowButton('book-'+resmarkID);
			}
		);
	});

});

function changeBookNowButton(id) {
	var imgPath1 = '/images/msg_incart.gif',
		imgPath2 = '/images-specials/btn_booknow.gif',
		imgElem = $('#'+id+',.'+id);
	
	if(imgElem.hasClass('book-now')) {
		imgElem.attr('class','book-now-added '+id);
		imgElem.attr('src',imgPath1);
	} else if(imgElem.hasClass('book-now-added')) {
		imgElem.attr('class','book-now '+id);
		imgElem.attr('src',imgPath2);
	}
}

function setURL(d){
	$("#myTmpDateSelected").val(d);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function submitQuickQuote(){
	if($("#jump_tours").val() == ""){
		$("#qqMessage").show();
	} else {
		$("#qqMessage").hide();
		$("#quickQuoteForm").submit();
	}
}

function toggleDiv(id){
	$("#"+id).slideToggle();
}

function loadingAjax() {
	return '<div class="cart_loader"><img src="/images/cart_loader.gif" /></div>';
}

function getDecimalNum(sVal,nDec){var n=parseFloat(sVal);var s;n=Math.round(n*Math.pow(10,nDec))/Math.pow(10,nDec);s=String(n)+"."+String(Math.pow(10,nDec)).substr(1);s=s.substr(0,s.indexOf(".")+nDec+1);return s;}
