jQuery(document).ready(function(){
	pullWeatherFeed();

	jQuery(function() {	
 		jQuery(".hotelleft h5 a").click(function () { 
 			jQuery(this).parents('.hotelleft').find(".hoteloptions").animate({"height":"toggle"}, {duration:600,easing:"easeOutBounce"});				
		});
	});
	
	jQuery(function() {
		jQuery('.footerthumb a').css({'opacity':'0.7'})
	});
	
	jQuery(function() {
	
		jQuery('.footerthumb a').hover(function(){	
				jQuery(this).stop();	
				jQuery(this).stop().css({'opacity':'1'});
				
			}, function(){
				jQuery(this).stop();	
				jQuery(this).stop().css({'opacity':'0.7'});
		});
		
	});
	
	
	jQuery(function() {
		jQuery('.pricingtablerow:even').css({'background-color':'#192736'})
	});
	
	
	
	
	jQuery(function() {
		var result;
		pageDepth = $(document).height();
		jQuery('#docheightvalue').html(pageDepth);
		switch (true) {
			case (pageDepth > 2400):
				result = 'url(/image/needle_7.png)';
				break;
			case ((pageDepth >= 2000) && (pageDepth <= 2399)):
				result = 'url(/image/needle_6.png)';
				break;
			case ((pageDepth >= 1800) && (pageDepth <= 1999)):
				result = 'url(/image/needle_5.png)';
				break;
			case ((pageDepth >= 1600) && (pageDepth <= 1799)):
				result = 'url(/image/needle_4.png)';
				break;
			case ((pageDepth >= 1400) && (pageDepth <= 1599)):
				result = 'url(/image/needle_3.png)';
				break;
			case ((pageDepth >= 1200) && (pageDepth <= 1399)):
				result = 'url(/image/needle_2.png)';
				break;
			default:
				result = 'url(/image/needle_1.png)';
				break;
		}
		jQuery('#needlelayer').stop().css({'background-image':result});
	});
	
	jQuery(function() {
		jQuery('a.divesitethumb').lightBox(); 
	});
	
	jQuery(function() {
		jQuery('a.rightcolumnthumb').lightBox(); 
	});

	jQuery(function() {
		jQuery('.productlistcontainer').hover(function(){	
			jQuery('.productlistcontainer').not(this).stop(true,true).fadeTo(400, 0.4);
		}, function(){
			jQuery('.productlistcontainer').delay(500).stop(false,true).fadeTo(200, 1.0);	
		});
	});
		
	
	jQuery('.sizelabel, .colorlabel').qtip({
	   show: 'mouseover',
	   hide: 'mouseout',
	   style: { 
	      width: 80,
	      padding: 2,
	      background: '#8cb0dd',
	      color: 'black',
	      textAlign: 'center',
	      border: {
	         width: 7,
	         radius: 5,
	         color: '#8cb0dd'
	      },
	      tip: { 
	         corner: 'bottomMiddle', 
	         size: {
	            x: 16,
	            y : 6
	         }
          },
	      name: 'dark'
	   },
	   position: {
		      corner: {
		         target: 'topMiddle',
		         tooltip: 'bottomMiddle'
		      }
		   }
	});
	
	
	jQuery(".sizelabel").click(function () {
		var _selectedSize = jQuery(this).attr('rel');
		jQuery("#sizeselector").find('.sizelabel').each(function(i) {
			if (jQuery(this).attr('rel')==_selectedSize) {
				jQuery(this).css({'border-color':'#fff'});
				jQuery(this).css({'opacity':'1'});
			} else {
				jQuery(this).css({'opacity':'0.3'});
				jQuery(this).css({'border-color':'#415871'});
			}
		});
	});
	
	jQuery(".colorlabel").click(function () {
		var _selectedColor = jQuery(this).attr('rel');
		jQuery("#colorselector").find('.colorlabel').each(function(i) {
			if (jQuery(this).attr('rel')==_selectedColor) {
				jQuery(this).css({'border-color':'#fff'});
				jQuery(this).css({'opacity':'1'});
			} else {
				jQuery(this).css({'opacity':'0.3'});
				jQuery(this).css({'border-color':'#415871'});
			}
		});
	});
	
	// function to show and hide the drop cart :
	jQuery(function() {
 		jQuery("#hccsummary").click(function () { 
				jQuery("#hccbody").animate({"height":"toggle","width":"toggle"}, {queue:false,duration:600,easing:"easeOutExpo"}); 
		});
	});
	
	// alt row colors in dropcart
	jQuery(function() {
		jQuery('.hccheaderdatarow:odd').css({'background-color':'#eee'})
	});
	
	jQuery(function() {
		jQuery(".scrollable").click(function () { 
			
			var _scrollto = jQuery(this).attr('rel');
			
			$.scrollTo(_scrollto,2000);
		});
	});
	

	
	jQuery(function() {
		jQuery(".reservation_loc2").click(function () { 
			
			var _element = this;
			
			if (jQuery('#selector').length>0) {
				jQuery('#selector').fadeOut('fast', function() {
        			jQuery('#selector').remove();
        			showSelector(_element);
      			});
			} else {
				showSelector(_element);
			}
  			//jQuery("#selector").animate({"height":"toggle","opacity":"toggle"}, {queue:false,duration:200}); 
			
		});
	});
	
	

	$(function() {
		$('#firstdive').datepicker({
			//minDate: new Date(+1),
			minDate: '+1d',
			hideIfNoPrevNext: true,
			onSelect: function(dateText) {		
				var _element = dateText;
				//jQuery("#chartercontainer").fadeTo(400, 0.01, function() {
					jQuery('#chartercontainer').html('');
					showLoader('loadingcharters'); 
					getCharterList(_element);
				//});
			}
		});
	});
	
	$(function() {
		$('#hcheckin').datepicker({
			//minDate: new Date(+1),
			minDate: '+1d',
			hideIfNoPrevNext: true
		});
	});
	
	$(function() {
		$('#hcheckout').datepicker({
			//minDate: new Date(+1),
			minDate: '+1d',
			hideIfNoPrevNext: true
		});
	});
	
	$(function() {
		$('#instructdate').datepicker({
			//minDate: new Date(+1),
			minDate: '+1d',
			hideIfNoPrevNext: true
		});
	});
	
	
	jQuery('.coursedesript').qtip({
	   show: 'mouseover',
	   hide: 'mouseout',
	   style: { 
	      width: 400,
	      padding: 2,
	      background: '#8cb0dd',
	      color: 'black',
	      textAlign: 'center',
	      border: {
	         width: 7,
	         radius: 5,
	         color: '#8cb0dd'
	      },
	      tip: { 
	         corner: 'bottomMiddle', 
	         size: {
	            x: 16,
	            y : 6
	         }
          },
	      name: 'dark'
	   },
	   position: {
		      corner: {
		         target: 'topMiddle',
		         tooltip: 'bottomMiddle'
		      }
		   }
	});


	

	jQuery(function() {
		jQuery('.selectcharter').hover(function(){	
			jQuery(this).text('Remove Charter');
		}, function(){
			jQuery(this).text('Charter Selected');	
		});
	});


	
});


/* non load functions */

sortDiveTable = function() {
	var th = jQuery('th:first'),
        inverse = false;
	var header = $(th),
        index = header.index();
        header
            .closest('table')
            .find('td')
            .filter(function(){
                return $(this).index() === index;
            })
            .sortElements(function(a, b){                      
                a = $(a).text();
                b = $(b).text();
                return (
                    isNaN(a) || isNaN(b) ?
                        a > b : +a > +b
                    ) ?
                        inverse ? -1 : 1 :
                        inverse ? 1 : -1;
            }, function(){
                return this.parentNode;
            });
        inverse = !inverse;
}


postDiving = function() {
	sortDiveTable();
	jQuery("#diving").val(jQuery("#divetablebuild").html());
}

currentConditions = function() {

	jQuery.getJSON("http://weather.scuba-do.com/weatherfeeds/json_current?format=json&jsoncallback=?",
		function(json){

	       	jQuery.each(json.current,function(i,noaa){
	       		jQuery("#w_airtemp").html(noaa.AirTemp);
	       		jQuery("#w_watertemp").html(noaa.WaterTemp);
	       		jQuery("#w_windtext").html(noaa.WindDirectionText);
	       		jQuery("#w_winddir").html(noaa.WindDirection);
	       		jQuery("#w_windspeed").html(noaa.WindSpeed);
	       		jQuery("#w_watergust").html(noaa.WindGust);
	       	}); 	
	       		
			jQuery.each(json.wchannel,function(i,channel){
	       		jQuery("#w_feelslike").html(channel.temp_f);
	       		//jQuery("#w_dew").html(channel.dewpoint_f);
	       		//jQuery("#w_uv").html(channel.wUvIndex +' ' +channel.wUvText); 		
	       		jQuery("#w_humidity").html(channel.relative_humidity);
	       		jQuery("#w_sunrise").html(channel.sunrise_hour+':'+channel.sunrise_minute+' AM');
	       		jQuery("#w_sunset").html((channel.sunset_hour-12)+':'+channel.sunset_minute+' PM');
	       		jQuery("#w_vis").html(channel.visibility_mi);
	       	}); 
	
	
	
	});

}

pullWeatherFeed = function() {

	//if (location.protocol === 'https:') {
   	//	_getUrl = "https://weather.scuba-do.com/weatherfeeds/json_current?format=json&jsoncallback=?";
	//} else {
		_getUrl = "http://weather.scuba-do.com/weatherfeeds/json_current?format=json&jsoncallback=?";
	//}

	jQuery.getJSON(_getUrl,
		function(json){

	       	jQuery.each(json.current,function(i,noaa){
	       		jQuery("#fw_airtemp").html(noaa.AirTemp);
	       		jQuery("#fw_watertemp").html(noaa.WaterTemp);
	       		jQuery("#fw_windtext").html(noaa.WindDirectionText);
	       		jQuery("#fw_winddir").html(noaa.WindDirection);
	       		jQuery("#fw_windspeed").html(noaa.WindSpeed);
	       		//jQuery("#fw_watertemp").html(day.WindGust);
	       	}); 	
	       		

	});

}


getCharterList = function(xDate) {
	jQuery.getJSON("http://cianciulli.net/public/getcharters.cfm?format=json&jsoncallback=?", {Date:xDate},
		function(json){
			var _rowCount = 0;
	       	jQuery.each(json.charters,function(i,day){
	       		jQuery("#chartercontainer").append('<div class="reservationday" id="day'+i+'"/>');
				jQuery("#day"+i+"").append('<h6>'+day.date+'</h6>');
				jQuery.each(day.trips,function(x,trip){
					_rowCount++;
					jQuery("#day"+i+"").append('<div class="reservationrow" id="day'+i+'row'+x+'" rel="'+_rowCount+'" />');
						jQuery("#day"+i+"row"+x+"").append('<div class="reservation_date">'+trip.status+'<input type="hidden" name="day_'+i+'_trip_selected_'+x+'" id="day_'+i+'_trip_selected_'+x+'" value="" rel="'+day.date+'" /></div>');
						
						if (trip.time=='Night'&&trip.hascharter==0){_addDateClass=' _hide';} else {_addDateClass='';}
						
						jQuery("#day"+i+"row"+x+"").append('<div class="reservation_time'+_addDateClass+'"><span>'+trip.time+'</span><input type="hidden" name="day_'+i+'_trip_time_'+x+'" id="day_'+i+'_trip_time_'+x+'" value="" rel="'+trip.time+'" /></div>');
						jQuery("#day"+i+"row"+x+"").append('<div class="reservation_type'+_addDateClass+'"><span>'+trip.type+'</span><input type="hidden" name="day_'+i+'_trip_type_'+x+'" id="day_'+i+'_trip_type_'+x+'" value="" rel="'+trip.type+'" /></div>');
						jQuery("#day"+i+"row"+x+"").append('<div class="reservation_loc1'+_addDateClass+'"><span>'+trip.loc1+'</span><input type="hidden" name="day_'+i+'_trip_loc1_'+x+'" id="day_'+i+'_trip_loc1_'+x+'" value="" rel="'+trip.loc1+'" /></div>');
						jQuery("#day"+i+"row"+x+"").append('<div class="reservation_loc2'+_addDateClass+'"><span>'+trip.loc2+'</span><input type="hidden" name="day_'+i+'_trip_loc2_'+x+'" id="day_'+i+'_trip_loc2_'+x+'" value="" rel="'+trip.loc2+'" /></div>');
	
						if (trip.status=='Departed') {
							jQuery("#day"+i+"row"+x+"").find(".reservation_date").css({"color":"lime","text-transform":"uppercase"});
						}
						if (trip.status=='Boarding') {
							jQuery("#day"+i+"row"+x+"").find(".reservation_date").css({"color":"yellow"});
						}	
						
					jQuery("#day"+i+"row"+x+"").append('<div class="charterinforow" id="charterinfo_day'+i+'row'+x+'"/>');
						jQuery("#charterinfo_day"+i+"row"+x+"").append('<div class="charter_line"><img src="/image/charterline.gif" alt="" /></div>');
						jQuery("#charterinfo_day"+i+"row"+x+"").append('<div class="charter_divers">Number of Divers:</div>');
						jQuery("#charterinfo_day"+i+"row"+x+"").append('<div class="charter_field"><input type="text" name="charter_day_'+i+'_trip_'+x+'_divers" class="charterspecs" value="" title="Enter Number of Divers" /></div>');
						jQuery("#charterinfo_day"+i+"row"+x+"").append('<div class="charter_label">Number of Snorkelers:</div>');
						jQuery("#charterinfo_day"+i+"row"+x+"").append('<div class="charter_field"><input type="text" name="charter_day_'+i+'_trip_'+x+'_snorks" class="charterspecs" value="" title="Enter Number of Snorkelers" /></div>');
						
				});
			}); 
			jQuery('.reservationday').find('.reservationrow:odd').css({'background-color':'#1d2d3e'});  
			//jQuery("#chartercontainer").fadeTo(800, 1.0);  
			
			jQuery('.charterspecs').qtip({
			   show: 'focus',
			   hide: 'blur',
			   style: { 
			      width: 100,
			      padding: 2,
			      background: '#8cb0dd',
			      color: 'black',
			      textAlign: 'center',
			      border: {
			         width: 7,
			         radius: 5,
			         color: '#8cb0dd'
			      },
			      tip: { 
			         corner: 'bottomMiddle', 
			         size: {
			            x: 16,
			            y : 6
			         }
		          },
			      name: 'dark'
			   },
			   position: {
				      corner: {
				         target: 'topMiddle',
				         tooltip: 'bottomMiddle'
				      }
				   }
			});
			
			jQuery(".charter_field").find('input').keyup(function () { 
				
				var _selectedValue = jQuery(this).val();
				//alert(jQuery(this).attr('name'));
				
				var _tdID = jQuery(this).attr('name');
				
				jQuery('#td_'+_tdID).html(_selectedValue);
			
			});
			
			jQuery('.addnite').bind('click', function() {
				showAddNite($(this));
			});
			
			jQuery('.selectcharter').bind('click', function() {
				showCharterSelect($(this));
			});
			
			hideLoader('loadingcharters'); 
	});   

}

showAddNite = function(xElement) {

	jQuery(xElement).unbind('click');

	if (jQuery('#selector').length>0) {
		jQuery('#selector').fadeOut('fast', function() {
			jQuery('#selector').remove();
		});
	}
	
	jQuery(xElement).text('Remove Charter');
	jQuery(xElement).addClass('selected');
	
	jQuery(function() {
		jQuery(xElement).hover(function(){	
			jQuery(this).text('Remove Charter');
		}, function(){
			jQuery(this).text('Charter Selected');	
		});
	});
	
	var _rowCountID = jQuery(xElement).parents('.reservationrow').attr('rel');
	var _charterRow = '<tr id="tr_'+parseInt(_rowCountID)+'"><td>'+parseInt(_rowCountID)+'</td>';
	jQuery(xElement).parents('.reservationrow').find('div').each(function(index){		
		jQuery(this).find('input[type=hidden]').val(jQuery(this).find('input[type=hidden]').attr('rel'));
		jQuery(this).val(jQuery(this).attr('rel'));
	});
	jQuery(xElement).parents('.reservationrow').find('input[type=hidden]').each(function(index){
		jQuery(this).val(jQuery(this).attr('rel'));
		_charterRow += '<td id="td_'+jQuery(this).attr('id')+'">'+jQuery(this).attr("rel")+'</td>';
	});
	
	jQuery(xElement).parents('.reservationrow').find(".charterinforow").find('input').each(function(index){
		_charterRow += '<td id="td_'+jQuery(this).attr('name')+'">0</td>';		
	});
	jQuery(xElement).parents('.reservationrow').find("div:not(:first)").fadeIn('slow', function(){
		jQuery(xElement).parents('.reservationrow').find(".charterinforow").find("input:first").focus();
		
		//showSelectorLinks(xElement);
		
		jQuery(xElement).bind('click', function() {
			hideAddNite(xElement);
		});
	});
	jQuery("#divetable > tbody:last").append(_charterRow);
	
	
}

hideAddNite = function(xElement) {
	jQuery(xElement).unbind('click');
	
	if (jQuery('#selector').length>0) {
		jQuery('#selector').fadeOut('fast', function() {
			jQuery('#selector').remove();
		});
	}

	jQuery(xElement).text(String.fromCharCode(187)+' Add A Night Dive');
	jQuery(xElement).removeClass('selected');
	
	jQuery(function() {
		jQuery(xElement).hover(function(){	
			jQuery(this).text(String.fromCharCode(187)+' Add A Night Dive');
		}, function(){
			jQuery(this).text(String.fromCharCode(187)+' Add A Night Dive');	
		});
	});
	
	jQuery(xElement).parents('.reservationrow').find('div').each(function(index){		
		jQuery(this).find('input[type=hidden]').val('');
	});
	
	jQuery(xElement).parents('.reservationrow').find("div:not(:first)").fadeOut('slow', function(){
		jQuery(xElement).bind('click', function() {
			showAddNite(xElement);
		});
	});
	jQuery(xElement).parents('.reservationrow').find('.charterinforow').each(function(){
		jQuery(this).find("input").val('');
	});
	
	_removeTableRowID = jQuery(xElement).parents('.reservationrow').attr('rel');
	
	$('#tr_'+_removeTableRowID).remove();
	
	
}

showCharterSelect = function(xElement) {
	jQuery(xElement).unbind('click');
	
	if (jQuery('#selector').length>0) {
		jQuery('#selector').fadeOut('fast', function() {
			jQuery('#selector').remove();
		});
	}
	
	jQuery(xElement).text('Charter Selected');
	jQuery(xElement).addClass('selected');
	
	jQuery(function() {
		jQuery(xElement).hover(function(){	
			jQuery(this).text('Remove Charter');
		}, function(){
			jQuery(this).text('Charter Selected');	
		});
	});
	
	var _rowCountID = jQuery(xElement).parents('.reservationrow').attr('rel');
	var _charterRow = '<tr id="tr_'+parseInt(_rowCountID)+'"><td>'+parseInt(_rowCountID)+'</td>';
	
	jQuery(xElement).siblings('input[type=hidden]').val(jQuery(xElement).siblings('input[type=hidden]').attr('rel'));
	
	jQuery(xElement).parents('.reservationrow').find('input[type=hidden]').each(function(index){
		jQuery(this).val(jQuery(this).attr('rel'));
		
		_charterRow += '<td id="td_'+jQuery(this).attr('id')+'">'+jQuery(this).attr("rel")+'</td>';
		
	});

	jQuery(xElement).parents('.reservationrow').find('.charterinforow').fadeIn('slow', function(){

		jQuery(this).find('input').each(function(index){
			_charterRow += '<td id="td_'+jQuery(this).attr('name')+'">0</td>';		
		});
		
		showSelectorLinks(xElement);

		jQuery("#divetable > tbody:last").append(_charterRow);
	
		jQuery(xElement).bind('click', function() {
			removeCharter(xElement);	
		});
	});
}

removeCharter = function(xElement) {
	jQuery(xElement).unbind('click');
	
	if (jQuery('#selector').length>0) {
		jQuery('#selector').fadeOut('fast', function() {
			jQuery('#selector').remove();
		});
	}
	
	jQuery(xElement).text(String.fromCharCode(187)+' Select Charter');
	jQuery(xElement).removeClass('selected');
	
	jQuery(function() {
		jQuery(xElement).hover(function(){	
			jQuery(this).text(String.fromCharCode(187)+' Select Charter');
		}, function(){
			jQuery(this).text(String.fromCharCode(187)+' Select Charter');	
		});
	});
	
	jQuery(xElement).siblings('input[type=hidden]').val('');
	removeSelectorLinks(xElement);
	jQuery(xElement).parents('.reservationrow').find('input[type=hidden]').each(function(index){
		jQuery(this).val('');
	});
	jQuery(xElement).parents('.reservationrow').find('.charterinforow').fadeOut('slow', function(){
		jQuery(this).find("input").val('');
		jQuery(xElement).bind('click', function() {
			showCharterSelect(xElement);
		});
	});
	
	_removeTableRowID = jQuery(xElement).parents('.reservationrow').attr('rel');
	
	$('#tr_'+_removeTableRowID).remove();

}




showSelectorLinks = function(xElement) {
	jQuery(xElement).parents('.reservationrow').find('.reservation_type span').each(function(index){
		var _currentType = jQuery(this).html();

		if (_currentType=='TBD') {
		
			jQuery(this).html('<a class="selecttype">TBD</a>'); 
			
			showTripTypeSelector(jQuery(this));
				
			jQuery('.selecttype').bind('click', function() {
				var _element = this; 
				
				if (jQuery('#selector').length>0) {
					jQuery('#selector').fadeOut('fast', function() {
	        			jQuery('#selector').remove();
	        			showTripTypeSelector(_element);
	      			});
				} else {
					showTripTypeSelector(_element);
				}
			});
			
	
		} else {
		
			jQuery(xElement).parents('.reservationrow').find('.reservation_loc1 span').each(function(index){
				var _currentLocal_1 = jQuery(this).html();
				
				if (_currentLocal_1=='TBD') {
					
					jQuery(this).html('<a class="selectlocal1">TBD</a>');
					
					showSelector(jQuery(this).find('.selectlocal1'));
					
					jQuery('.selectlocal1').bind('click', function() {
						var _element = this;
						if (jQuery('#selector').length>0) {
							jQuery('#selector').fadeOut('fast', function() {
			        			jQuery('#selector').remove();
			        			
			        			showSelector(_element);
			      			});
						} else {
							showSelector(_element);
						}
					});
					
					
					
				} else {
					
					jQuery(xElement).parents('.reservationrow').find('.reservation_loc2 span').each(function(index){
						var _currentLocal_2 = jQuery(this).html();
				
						if (_currentLocal_2=='TBD') {
							jQuery(this).html('<a class="selectlocal2">TBD</a>');
							
							showSelector(jQuery(this).find('.selectlocal2'));
							
							jQuery('.selectlocal2').bind('click', function() {
								var _element = this;
								if (jQuery('#selector').length>0) {
									jQuery('#selector').fadeOut('fast', function() {
					        			jQuery('#selector').remove();
					        			showSelector(_element);
					      			});
								} else {
									showSelector(_element);
								}
							});
						}
					});
					
					
				}
			
			});
		
		
		}
		
	
		
	});

}

removeSelectorLinks = function(xElement) {
	jQuery(xElement).parents('.reservationrow').find('span').each(function(index){			
		jQuery(this).html(jQuery(this).siblings('input[type=hidden]').attr('rel'));
	});
}

relayDiverCounts = function() {
	//alert(this)
	var _tdID = jQuery(this).attr('name');
	jQuery('#td_'+_tdID).html(_selectedValue);
}

showTripTypeSelector = function(xPos) {
	jQuery('body').prepend('<div id="selector"><div id="checkinner"></div><div id="checkinner2"><a id="closeselector">CLOSE</a></div></div>');
	
	_list = jQuery("#typelist").html();
	jQuery("#checkinner").html(_list);
	
	var elementHeight = jQuery("#selector").height();
	
	var pos = jQuery(xPos).offset();  
	var width = jQuery(xPos).width();
	var height = jQuery(xPos).height();
	
	jQuery('._type_select').bind('click', function(index) {
    	var _selectedValue = $(this).attr("rel");
    	jQuery(xPos).parents('.reservationrow').find('.reservation_type span').each(function(index){
    	
			jQuery(this).html('<a class="selecttype">'+_selectedValue+'</a>');
			jQuery('.selecttype').bind('click', function() {
  				var _element = this;
				if (jQuery('#selector').length>0) {
					jQuery('#selector').fadeOut('fast', function() {
	        			jQuery('#selector').remove();
	        			showTripTypeSelector(_element);
	      			});
				} else {
					showTripTypeSelector(_element);
				}
			});
			
			
			jQuery(this).siblings('input[type=hidden]').val(_selectedValue);
			
			var _tdID = jQuery(this).siblings('input[type=hidden]').attr('id');
			jQuery('#td_'+_tdID).html(_selectedValue);
			
			jQuery(this).parents('.reservationrow').find('.reservation_loc1 span').html('TBD');
			jQuery(this).parents('.reservationrow').find('.reservation_loc1 span').siblings('input[type=hidden]').val('TBD');
			jQuery(this).parents('.reservationrow').find('.reservation_loc2 span').html('TBD');
			jQuery(this).parents('.reservationrow').find('.reservation_loc2 span').siblings('input[type=hidden]').val('TBD');
			
			var _thisIs = $(this);
			jQuery('#selector').fadeOut('fast', function() {
				jQuery('#selector').remove();
				showSelectorLinks(_thisIs);
			});

			
		});
	});

	jQuery('#closeselector').bind('click', function() {
		jQuery('#selector').fadeOut('fast', function() {
			jQuery('#selector').remove();
		});
	});
		
	jQuery("#selector").css( { "left": (pos.left - 67) + "px", "top":(pos.top - (elementHeight+4)) + "px" } );
	jQuery("#selector").fadeIn();
}

showSelector = function(xPos) {
	jQuery('body').prepend('<div id="selector"><div id="checkinner"></div><div id="checkinner2"><a id="closeselector">CLOSE</a></div></div>');
	
	var _SelectorIs = jQuery(xPos).attr('class');
	var _currentTime = jQuery(xPos).parents('.reservationrow').find('.reservation_time span').html();
	
	_list = $("#locationlist").html();
	jQuery("#checkinner").html(_list);
	
	
	jQuery(xPos).parents('.reservationrow').find('.reservation_type span').each(function(index){
		
		if (_SelectorIs=='selectlocal1'){
		
		var _currentTypeIs = jQuery(this).siblings('input[type=hidden]').val();

			if (_currentTypeIs=='Wreck') {
				jQuery("#checkinner").find('._loc_list_Reef').each(function(index){
					jQuery(this).css({'display':'none'});
				});
			}
			if (_currentTypeIs=='Reef') {
				jQuery("#checkinner").find('._loc_list_Wreck').each(function(index){
					jQuery(this).css({'display':'none'});
				});
				jQuery("#checkinner").find('._loc_list_Reef').each(function(index){
					if (_currentTime=='AM' && jQuery(this).attr('am')==0) {
						jQuery(this).css({'display':'none'});
					}
				});
			}
			if (_currentTypeIs=='Private') {
				jQuery("#checkinner").find('._loc_list_Wreck').each(function(index){
					jQuery(this).css({'display':'block'});
				});
				jQuery("#checkinner").find('._loc_list_Reef').each(function(index){
					jQuery(this).css({'display':'block'});
				});
			}
		}
		
		if (_SelectorIs=='selectlocal2'){
		
			_SiteSelectedIs = jQuery(xPos).parents('.reservationrow').find('.reservation_loc1 span').siblings('input[type=hidden]').val();
			
			jQuery("#checkinner ul").find('li').each(function(index){
				if (jQuery(this).attr('rel')==_SiteSelectedIs) {
					jQuery(this).css({'display':'block'});
				} else {
					jQuery(this).css({'display':'none'});
				}
			});
			
			jQuery("#checkinner ul").find('.sublist').each(function(index){
				if (jQuery(this).attr('rel')==_SiteSelectedIs) {
					jQuery(this).css({'display':'block'});
					
					jQuery(this).find('li').each(function(index){
						jQuery(this).css({'display':'block'});
					});
					
				} else {
					jQuery(this).css({'display':'none'});
				}
			});
		}
		
	});
	
	var elementHeight = jQuery("#selector").height();
	
	var pos = jQuery(xPos).offset();  
	var width = jQuery(xPos).width();
	var height = jQuery(xPos).height();
	
	if (_SelectorIs=='selectlocal1') {
		_localIs = 1;
	} else {
		_localIs = 2;
	}
	
	
	
	jQuery('._loc_select').bind('click', function(index) {
    	var _selectedValue = $(this).attr("rel");

    	jQuery(xPos).parents(".reservationrow").find(".reservation_loc"+_localIs+" span").each(function(index){
			jQuery(this).html('<a class="'+_SelectorIs+'">'+_selectedValue+'</a>');
			
			jQuery('.'+_SelectorIs).bind('click', function() {
  				var _element = this;
				
				if (jQuery('#selector').length>0) {
					jQuery('#selector').fadeOut('fast', function() {
	        			jQuery('#selector').remove();
	        			showSelector(_element);
	      			});
				} else {
					showSelector(_element);
				}
			});
			
			jQuery(this).siblings('input[type=hidden]').val(_selectedValue);
			
			var _tdID = jQuery(this).siblings('input[type=hidden]').attr('id');
			jQuery('#td_'+_tdID).html(_selectedValue);
	
			if (_SelectorIs=='selectlocal1') {
				jQuery(this).parents('.reservationrow').find('.reservation_loc2 span').html('TBD');
				jQuery(this).parents('.reservationrow').find('.reservation_loc2 span').siblings('input[type=hidden]').val('TBD');
			}

			if (_SelectorIs=='selectlocal1') {
				var _thisIs = $(this);
				jQuery('#selector').fadeOut('fast', function() {
					jQuery('#selector').remove();
					showSelectorLinks(_thisIs);
				});
			} 
			
			if (_SelectorIs=='selectlocal2') {
				var _thisIs = $(this);
				jQuery('#selector').fadeOut('fast', function() {
					jQuery('#selector').remove();
					jQuery(_thisIs).parents('.reservationrow').find('.charterinforow').find("input:first").focus();
				});
			}
			
		});
	});
	

	jQuery('#closeselector').bind('click', function() {
		jQuery('#selector').fadeOut('fast', function() {
		jQuery('#selector').remove();
		});
	});
		
	jQuery("#selector").css( { "left": (pos.left - 67) + "px", "top":(pos.top - (elementHeight+4)) + "px" } );
	jQuery("#selector").fadeIn();
}



limitItemMenu = function(xItem) {
	jQuery('.productlistcontainer[rel='+xItem+']').each(function(i) {
		jQuery(this).animate({"height":"toggle","width":"toggle", "opacity":"toggle"}, 200); 
	});
}

getCharter = function() {
	//jQuery("#schedulecontainer").fadeTo(200, 0.01); 
	pullCharterFeed();
}

pullCharterFeed = function() {
	
	jQuery.getJSON("http://cianciulli.net/public/upcoming.cfm?format=json&jsoncallback=?",
		function(json){
	       	jQuery.each(json.charters,function(i,day){
	       	
	       		
				jQuery("#schedulecontainer").append('<div class="scheduleday" id="day'+i+'"/>');
				jQuery("#day"+i+"").append("<h6>"+day.date+"</h6>");
				
				$.each(day.trips,function(x,trip){
					jQuery("#day"+i+"").append('<div class="schedulerow" id="day'+i+'row'+x+'"/>');
						jQuery("#day"+i+"row"+x+"").append('<div class="schedule_date">'+trip.status+'</div>');
						jQuery("#day"+i+"row"+x+"").append('<div class="schedule_time">'+trip.time+'</div>');
						jQuery("#day"+i+"row"+x+"").append('<div class="schedule_type">'+trip.type+'</div>');
						jQuery("#day"+i+"row"+x+"").append('<div class="schedule_loc1">'+trip.loc1+'</div>');
						jQuery("#day"+i+"row"+x+"").append('<div class="schedule_loc2">'+trip.loc2+'</div>');
						if (trip.status=='Boarding' && trip.status!='Cancelled') {
							jQuery("#day"+i+"row"+x+"").find(".schedule_date").css({"color":"yellow"});
						}
						if (trip.status=='Cancelled') {
							jQuery("#day"+i+"row"+x+"").find(".schedule_date").css({"color":"red"});
						}
				});
			
				
				
			}); 
			jQuery('.scheduleday').find('.schedulerow:odd').css('backgroundColor','#1d2d3e'); 
			
			
			
			
			
			
			 
			//jQuery("#schedulecontainer").fadeTo(800, 1.0);   
			//hideLoader('loadschedule'); 
			
			//jQuery('#loadschedule').css({'display':'none'});
			
			//jQuery('#loadschedule').css('display', 'none');
			//jQuery('#loadschedule').fadeOut('fast');
	});

}

typeSelectClick = function() {
	
	var label = $(this);
    var input = label.attr("rel");
    alert(input);
}

loadCharterLists = function() {
	
	$.getJSON("http://cianciulli.net/public/chartertypes.cfm?format=json&jsoncallback=?",
		function(json){
	       	$.each(json.types,function(i,type){
	       		$("#typelist ul").append('<li>&raquo; <a class="_type_select" rel="'+type.title+'">'+type.title+'</a></li>');
			});		
	});

	jQuery.getJSON("http://cianciulli.net/public/locations.cfm?format=json&jsoncallback=?",
		function(json){
	       	jQuery.each(json.locals,function(x,locallist){
	       	
	       		jQuery("#locationlist ul:first").append('<li class="_loc_list_'+locallist.type+'" rel="'+locallist.title+'" am="'+locallist.am_avail+'">&raquo; <a class="_loc_select" rel="'+locallist.title+'">'+locallist.title+'</a></li>');
	       		
	       			jQuery("#locationlist li:last").append('<ul class="sublist" rel="'+locallist.title+'"/>');
	       			
	       			jQuery.each(locallist.subs,function(i,subs){
	       				jQuery("#locationlist ul:last").append('<li class="_loc_list_'+locallist.type+'" rel="'+subs.am_avail+'">&raquo; <a class="_loc_select" rel="'+subs.title+'">'+subs.title+'</a></li>');
	       			});
	       			 
			}); 
	});
	
}


/*
Geotagged address is 522 Caribbean Dr., Key Largo, FL, 33037
Latitude updated to 25.0956875
Longitude updated to -80.430743

Latitude updated to 25.099929
Longitude updated to -80.433999
*/


function initialize() {
  var myLatlng = new google.maps.LatLng(25.099929,-80.433999);
  var myOptions = {
    zoom: 14,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.TERRAIN
  }
  var map = new google.maps.Map(document.getElementById("contactmap"), myOptions);
  	// shop 
  	var contentString1 = '<div class="mapinfo">'+
  		'<h3>The Shop</h3>'+
  		'<p>102670 Overseas Hwy.<br />Key Largo, FL 33035<br />'+
  		jQuery('#shoplink').html()+
  		'</p>'+
  		'</div>';
  	
  	var infowindow1 = new google.maps.InfoWindow({
    	content: contentString1
	});

  	var marker = new google.maps.Marker({
		position: new google.maps.LatLng(25.127763,-80.410795), 
		map:map, 
		title:'The Shop'
	});  
	
  	infowindow1.open(map,marker);

	
	// boat
	var contentString2 = '<div class="mapinfo">'+
  		'<h3>The Boat</h3>'+
  		'<p>522 Caribbean Dr.<br />Key Largo, FL 33035<br />'+
  		jQuery('#boatlink').html()+
  		'</p>'+
  		'</div>';
	
	var infowindow2 = new google.maps.InfoWindow({
    	content: contentString2
	});
	
	var marker2 = new google.maps.Marker({
		position: new google.maps.LatLng(25.0956875,-80.430743), 
		map:map, 
		title:'The Boat'
	}); 
	
	google.maps.event.addListener(marker2, 'click', function() {
  		infowindow2.open(map,marker2);
	});

}
  
function loadScript() {
  var script = document.createElement("script");
  script.type = "text/javascript";
  script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=initialize";
  document.body.appendChild(script);
}
  

/* Start - Home Slide Show Functions */


var interval = 0;

testScroll = function() {

	jQuery('.slice_1').first().stop().animate({'marginTop':'-255px'}, 'slow', function() {	
		jQuery(".slice_1:first").remove().insertAfter($(".slice_1:last"));
		jQuery(".slice_1:last").css({'marginTop':'0px'});

	});

	jQuery('.slice_2').first().stop().animate({'marginTop':'255px'}, 'slow', function() {	
		jQuery(".slice_2:last").remove().insertBefore($(".slice_2:first"));
		jQuery(".slice_2:nth-child(2)").css({'marginTop':'0px'});
	});
	
	jQuery('.slice_3').first().stop().animate({'marginTop':'-255px'}, 'slow', function() {	
		jQuery(".slice_3:first").remove().insertAfter($(".slice_3:last"));
		jQuery(".slice_3:last").css({'marginTop':'0px'});

	});
	
	jQuery('.slice_4').first().stop().animate({'marginTop':'255px'}, 'slow', function() {	
		jQuery(".slice_4:last").remove().insertBefore($(".slice_4:first"));
		jQuery(".slice_4:nth-child(2)").css({'marginTop':'0px'});
	});
	
	jQuery('.slice_5').first().stop().animate({'marginTop':'-255px'}, 'slow', function() {	
		jQuery(".slice_5:first").remove().insertAfter($(".slice_5:last"));
		jQuery(".slice_5:last").css({'marginTop':'0px'});

	});

}

startHeaderRotation = function() {
	//getImages();
	
	var _totalSlides = $('#_total').text();
	var _sliderWidth = parseInt(_totalSlides)*255;
	$('#hsc_2_column').css('height',_sliderWidth+'px');
	$('#hsc_2_column').css('marginTop', -(_sliderWidth-255)+'px');
	$('#hsc_4_column').css('height',_sliderWidth+'px');
	$('#hsc_4_column').css('marginTop', -(_sliderWidth-255)+'px');
	
	
	interval = setInterval('autoRotate()',6000);
	/*
	if (_totalSlides == 1) {
		$('#slider_arrow_next').css('display','none');
		$('#slider_arrow_previous').css('display','none');
	} else {
		interval = setInterval('autoRotate()',6000);
	}
	*/	
	
}

getImages = function() {
	var _totalSlides = parseInt($('#_total').text())-1;
	var i=1;
	do
  	{
  		$.get('/embeds/ajax_slide/'+i+'/', function(data) {
			$('.slideset').append(data);
		});
		i++;
  	}
	while (i<=_totalSlides);
	
	$('#slider_arrow_next').fadeIn("slow");
	$('#slider_arrow_previous').fadeIn("slow");
	
	enableSlideButtons();
}

imageClickForward = function() {

	if (!arguments[0]) {
		// Kill Auto ::
		clearInterval(interval);
	}	 
	testScroll();
	
	/*
	disableSlideButtons(); 
	$('.slide').first().stop().animate({'marginLeft':'-788px'}, 600, function() {	
		$(".slide:first").remove().insertAfter($(".slide:last"));
		$(".slide:last").css({'marginLeft':'0px'});
		enableSlideButtons();
	});
	*/
}

imageClickBackward = function() {

	if (!arguments[0]) {
		// Kill Auto ::
		clearInterval(interval);
	}	
	
	disableSlideButtons();
	
	$(".slide:last").css({'marginLeft':'-788px'});
	$(".slide:last").remove().insertBefore($(".slide:first"));
	
	$('.slide').first().stop().animate({'marginLeft':'0px'}, 600, function() {	
		enableSlideButtons();
	});

}

autoRotate = function() {
	//disableSlideButtons();
	imageClickForward('auto');
}

enableSlideButtons = function() {
	$('#slider_arrow_next').css({'opacity':'1.0'});
	$('#slider_arrow_next').bind('click', function() {
		imageClickForward();
	});
	$('#slider_arrow_previous').css({'opacity':'1.0'});
	$('#slider_arrow_previous').bind('click', function() {
		imageClickBackward();
	});
	
}
disableSlideButtons = function() {
	$('#slider_arrow_next').unbind('click');	
	$('#slider_arrow_next').css({'opacity':'0.5'});
	$('#slider_arrow_previous').unbind('click');	
	$('#slider_arrow_previous').css({'opacity':'0.5'});
	
}







/* End - Home Slide Show Functions */


showLoader = function(xID) {
	jQuery('#'+xID).css({'display':'block'});
	//jQuery('#'+xID).animate({"opacity":"toggle"}, 400, function(){
	//		jQuery(this).css({'display':'block'});
	//});
}


hideLoader = function(xID) {
	jQuery('#'+xID).css({'display':'none'});
	//jQuery('#'+xID).delay(600).animate({"opacity":"toggle"}, 800, function(){
	//		jQuery(this).css({'display':'none'});
	//});
}



