$(function(){	
	$.krypton.tooltip();
	$.krypton.zebra();
	
	
	$("a.fancy").fancybox({ 'titleShow' : false, 'transitionIn'	: 'elastic', 'transitionOut' : 'elastic', 'width' : '90%','scrolling' : 'no'});
	$("a[rel=unitpics]").fancybox({ 'transitionIn' : 'none', 'transitionOut' : 'none', 'titlePosition' 	: 'over' });
	$('#block_content_nav a').bind('click', function(e){
		e.preventDefault();
		var $this = $(this);
			$bnav = $("#block_content_nav a"),
			$index = $("#block_content_nav a").index(this),
			$blockcontent =  $("#block_content div"),
			$cont_sel = $('#block_content div:eq('+$index+')');
		//alert(index);
		if ($this.parent('li').hasClass("active")){
		} else {
		$this.parent('li').addClass('active');
		$bnav.not(this).parent('li').removeClass('active');
		$blockcontent.fadeOut(1, function(){
				$('#block_content div:eq('+$index+')').fadeIn('1000','easeInCirc');
			});
		}
	});
	
	
	
	if (!$('#step_form_session').length ) {
	$('#progress_table .step-click, #progress_table_pay .step-click').click( function(){
		var $index = $(this).index(),
			$indexplus = $index+1;
			//alert($indexplus);
		
		if ($indexplus =='1') {
			$('#step_form_session_send input[name="s"]').remove();
			var $action2 = $('#step_form_session_send').attr('action', 'searchFINALGROUP_modify.php');
			//alert($action);
		}
		
		if ($indexplus =='2') {
			var $building = $('#step_form_session #building').val('');
			var $unitname = $('#step_form_session #unitname').val('');
			var $rmtype = $('#step_form_session #rmtype').val('');
			var $acctype = $('#step_form_session #acctype').val('-1');
			//alert( $building +' '+ $unitname2);
		}
		
		if ($indexplus =='3') {
			var $unitname2 = $('#step_form_session #unitname').val('');
			var $acctype2 = $('#step_form_session #acctype').val('-1');
			$('#step_form_session_send input[name="s"]').val('units');
			$('#step_form_session_send').attr('action', 'avail_searchFINALGROUPUNIT.php');
			//alert($unitname);
		}
		
		if ($indexplus =='4') {
			$('#step_form_session_send input[name="s"]').remove();
			$('#step_form_session_send input[name="b"]').remove();
			var $action = $('#step_form_session').attr('action', 'avail_detailFINALGROUP.php');
			//alert($action);
		}
		
		if($('#step_form_session_send input[name="hotel"]') =='y'){
					alert('hotel');	
					//$('#step_form_session_send').attr('action', 'searchFINALGROUP_modify_hotel.php');
				}
		
		if($(this).hasClass('step')){
		
		$('#blue_loading').fadeIn(100);
		// $('#top_cookie_navigation_wrapper').hide(1);
		
		
		
		var $form = $('#step_form_session'),
       		$send = $form.find( 'input[name="sendurl"]' ).val(),
       		$url = $form.attr( 'action');
       		
			$('html, body').animate({ scrollTop: 0 }, 'slow');
			$.post($send, $form.serialize(), function(data) {
  				//alert('Load was performed.'+data);
    			//$("#step_form_session_send").submit();
			});
		}
	});	
	} else {
		$('#progress_table .step-click, #progress_table_pay .step-click').click( function(){
		
		
		
		$('#blue_loading').fadeIn(100);
		
			var $index = $(this).index(),
				$indexplus = $index+1;
				//alert($indexplus);
			
		
			if ($indexplus =='1') {
				$('#step_form_session_send input[name="s"]').remove();
				var $ht = $('#step_form_session input[name="hotel"]').val();
				if( $ht =='y'){
					$('#step_form_session_send').attr('action', 'searchFINALGROUP_modify_hotel.php');
				} else {
					var $action2 = $('#step_form_session_send').attr('action', 'searchFINALGROUP_modify.php');
				}
			//alert($action);
			}
			if ($indexplus =='2') {
			var $building = $('#step_form_session #building').val('');
			var $unitname = $('#step_form_session #unitname').val('');
			var $rmtype = $('#step_form_session #rmtype').val('');
			var $acctype = $('#step_form_session #acctype').val('-1');
			//alert( $building +' '+ $unitname2);
			
			var $ht = $('#step_form_session input[name="hotel"]').val();
				if( $ht =='y'){
					$('#step_form_session_send').attr('action', 'avail_searchHOTEL.php');
				}
			
		}
			if ($indexplus =='3') {
			var $building = $('#step_form_session #building').val();
			var $unitname2 = $('#step_form_session #unitname').val('');
			var $acctype2 = $('#step_form_session #acctype').val('-1');
			$('#step_form_session_send input[name="s"]').val('unit');
			$('#step_form_session_send input[name="s"]').val('unit');
			
			if($building ==''){
				$('#step_form_session_send').attr('action', 'searchFINALGROUP_modify.php');
			}else {
				$('#step_form_session_send').attr('action', 'avail_searchFINALGROUPUNIT.php');
			}
			
			//alert($unitname);
		}
			if ($indexplus =='4') {
			$('#step_form_session_send input[name="s"]').remove();
			$('#step_form_session_send input[name="b"]').remove();
			var $action = $('#step_form_session').attr('action', 'avail_detailFINALGROUP.php');
			//alert($action);
		}
			
			
			if($(this).hasClass('step')){
				//$('#blue_loading').fadeIn(100);
				$('#top_cookie_navigation_wrapper').hide(1);
				
				var $ht = $('#step_form_session_send input[name="hotel"]').val();
				if( $ht =='y'){
					$('#step_form_session_send').attr('action', 'searchFINALGROUP_modify_hotel.php');
				}
		
			var $form = $('#step_form_session'),
       			$send = $form.find( 'input[name="sendurl"]' ).val(),
       			$url = $form.attr( 'action');
       		
				$('html, body').animate({ scrollTop: 0 }, 'slow');
				$.post($send, $form.serialize(), function(data) {
  					//alert('Load was performed.'+data);
    				$("#step_form_session_send").submit();
				});
			}
		
		
		
	});
	}
	
	var saveck = new cookieset2("fav_cookie", "saveck");
	function cookieset2(cookieName, inst){
		var date = 365;
		var cookie = $.cookie(cookieName, { path: "/", expires: date });
		var items = cookie ? cookie.split(/,/) : new Array();
		var self = inst;
		
		return {
			"add": function(val) {
			items.push(val);
			$.cookie(cookieName, items.join(','), { path: "/", expires: date });
			//alert(saveck.items());
		},
			"clear": function() {
			items = null;
			//clear the cookie.
			$.cookie(cookieName, null, { path: "/", expires: date });
		},
			"items": function() {
			//Get all the items.
			return items;
		}, 	
			"remove": function(val){
			items = $.grep(items, function(n, i){
				return (n != val);
			});
			$.cookie(cookieName, items.join(','), { path: "/", expires: date });
			//alert(filterck.items());
		},
			"check": function(val){
				if($.inArray(val,items) > -1) {
					//alert('found');
					//alert(saveck.items());
				} else {
					//alert('not found');
					$("#top_cookie_navigation_wrapper").slideDown(100);
					this.add(val);
				}
		}
			}
	}  
	
		
	if($.cookie('fav_cookie')){
		$("#top_cookie_navigation_wrapper").slideDown(100);
		var $checkfav_toggle = saveck.items();
		$.each($checkfav_toggle, function(index, favval){
			fav_checkselect(favval);
		});
	}	
    
    function fav_checkselect(favval){
		var $session_stamp = $('#save_search').attr('rel');
		if($session_stamp == favval ){
			$('#save_search').addClass('fav_added');
			$('#save_search').text('Remove From Favorites');
		} 
	}
    
    function clear_fav_hide(){
    	if(saveck.items() =='null'){
    		$('#save_search').removeClass('fav_added');
			$('#save_search').text('Add to Favorites');
			$("#top_cookie_navigation_wrapper").slideUp(100);
    	}
    }
    
    
    $('#save_search').click( function(){
		var $this = $(this),
			session_stamp = $('#save_search').attr('rel');
		if($this.hasClass('fav_added')){
			saveck.remove(session_stamp);
			$this.removeClass('fav_added');
			$this.text('Save for later');
			clear_fav_hide();
		} else {
			saveck.check(session_stamp);
			$this.addClass('fav_added');
			$this.text('Remove from saved');
		}
	});
       
    
    $('#cookie_fav').hover(function($rest){
    	$hov = '0';
    	var	$rest = '<li><a href="#" id="remove_fav_list">Clear All</a></li>',
    		fav_arr = $.cookie('fav_cookie').split(','),
      		fv_end = fav_arr.length,
      		fv_st = 0;
		$.each(fav_arr, function(index, cval ){
    			fav_items(cval, index);
    			fv_st++;
 		});
 		if(	fv_st >= fv_end ){
 			$('#fav_list').append($rest);
 			$(this).children('#fav_list').stop(true, true).slideDown(200);
		} 
    }, function(){
    	$('#fav_list').html('');
    	$(this).children('#fav_list').stop(true, true).slideUp(200);
    });
   
   	
   
    $('#remove_fav_list').live('click', function(event) {
   		var date = 365;
 		event.preventDefault();
    	//alert('remove them all');
    	$.cookie('fav_cookie', null, { path: "/", expires: date });
    	
    	$("#top_cookie_navigation_wrapper").slideUp(100);
    	$('#save_search').removeClass('fav_added');
		$('#save_search').text('Add to Favorites');
		$('.fc_fav').removeAttr("checked");	
	});
  
    
    function fav_items(cval){ 
    	$('#fav_list').prepend('<li><a href="https://www.brett-robinson.com/_iqbooking_session_new/avail_detailGROUP.php?unitname='+ cval +'&arrival=&departure=&adults=&direct=2">'+ cval +'</a></li>'); 
    }
    
    
	$(".detail_book_form").submit(function(event) {
		event.preventDefault();
		$('#blue_loading').fadeIn(100);
		$('#top_cookie_navigation_wrapper').hide(1);
		var $form = $( this ),
			$url = $form.find( '.detail_book_form input[name="sendurl"]' ).val();
		$('html, body').animate({ scrollTop: 0 }, 'slow');
		$.post($url, $form.serialize(), function(data) {
			//alert('Load was performed.'+data);
			$(".detail_book_form_send").submit();
		});
	});
	$('#bookForm').submit(function(){
		//$('#blue_loading').fadeIn(100);
		//$('#top_cookie_navigation_wrapper').hide(1);
	});

	$("#single_stay_direct").submit(function(event) {
		$('#blue_loading').fadeIn(100);
		$('#top_cookie_navigation_wrapper').hide(1);
		event.preventDefault(); 
		var $form = $( this ),
		$send = $form.find( 'input[name="sendurl"]' ).val(),
		$url = $form.attr( 'action');
		
		$('html, body').animate({ scrollTop: 0 }, 'slow');
		$.post($send, $form.serialize(), function(data) {
			//alert('Load was performed.'+data);
			$("#single_stay_direct_send").submit();
		});
	});	
	$("#search_unit_detail_nd").submit(function(event) {
		event.preventDefault();
		$('#blue_loading').fadeIn(100);
		$('#top_cookie_navigation_wrapper').hide(1);
		var direct_arr = $("#search_unit_detail_nd #fymd").val(),
			direct_dep = $("#search_unit_detail_nd #tymd").val();
		$('#search_unit_detail_nd_send input[name="arrival"]').val(direct_arr);		
		$('#search_unit_detail_nd_send input[name="departure"]').val(direct_dep);
		var $form = $( this ),
			$url = $form.find( 'input[name="sendurl"]' ).val();
		$('html, body').animate({ scrollTop: 0 }, 'slow');
		$.post($url, $form.serialize(), function(data) {
			//alert('Load was performed.'+data);
			$("#search_unit_detail_nd_send").submit();
		});
	});
	$("#availability_search_modform").submit(function(event) {
		event.preventDefault();
		$('#blue_loading').fadeIn(100);
		$('#top_cookie_navigation_wrapper').hide(1);
		$("#availability_search_modform_send").submit();
		
	});

	function blue_loader_insert($book){		
		var $tips = new Array(
			"You can learn all about area events and packages in our online Insider Guide.",
			"When you sign up for our mailing list you will always be up to date on the latest specials",
			"You can get your questions answered on our web site with friendly Live Chat",
			"We have a wide variety of great beach homes and condos for sale year-round",
			"Most of our properties have swimming pools, BBQ grills, and meeting spaces",
			"You can be entered to win prizes all the time by Simply Liking us on Facebook"		
		);
		
		var tip_c = $tips.length,
		rnd_tip = randomFromTo(0,tip_c-1),
		window_h = getDocHeight();
			 					
		if($book =='yes'){
			var $load_content = '<img src="https://www.brett-robinson.com/_iqbooking_session_new/images/loading_message_bg.png" style="display:none;" /><img src="https://www.brett-robinson.com/_iqbooking_session_new/images/tips_loader.gif" style="display:none;" /><div id="blue_loading" class="bloading" style="display:none; height:'+ window_h +'px;"><div id="loading_centered"><div id="loader_space"><p>Searching</p></div><div id="tip_space"><h2 class="avenir">Processing Reservation</h2><p>This may take up to 60 seconds, please do not click the back button.</p></div></div>';
		}else {
			var $load_content = '<img src="https://www.brett-robinson.com/_iqbooking_session_new/images/loading_message_bg.png" style="display:none;" /><img src="https://www.brett-robinson.com/_iqbooking_session_new/images/tips_loader.gif" style="display:none;" /><div id="blue_loading" class="bloading" style="display:none; height:'+ window_h +'px;"><div id="loading_centered"><div id="loader_space"><p>Searching</p></div><div id="tip_space"><h2 class="avenir">Did You Know..</h2><p>'+ $tips[rnd_tip]+'</p></div></div>';
		}
		
		if ( $('div').hasClass("bloading") ) {
		} else { 
			$('#body').prepend($load_content);	}
		}
		
		
	function blue_loader_insert_secure($book){		
		var $tips = new Array(
			"You can learn all about area events and packages in our online Insider Guide.",
			"When you sign up for our mailing list you will always be up to date on the latest specials",
			"You can get your questions answered on our web site with friendly Live Chat",
			"We have a wide variety of great beach homes and condos for sale year-round",
			"Most of our properties have swimming pools, BBQ grills, and meeting spaces",
			"You can be entered to win prizes all the time by Simply Liking us on Facebook"		
		);
		
		var tip_c = $tips.length,
		rnd_tip = randomFromTo(0,tip_c-1),
		window_h = getDocHeight();
			 					
		if($book =='yes'){
			var $load_content = '<img src="https://www.brett-robinson.com/_iqbooking_session_new/images/loading_message_bg.png" style="display:none;" /><img src="https://www.brett-robinson.com/_iqbooking_session_new/images/tips_loader.gif" style="display:none;" /><div id="blue_loading_secure" class="bloading" style="display:none; height:'+ window_h +'px;"><div id="loading_centered"><div id="loader_space"><p>Searching</p></div><div id="tip_space"><h2 class="avenir">Processing Reservation</h2><p>This may take up to 60 seconds, please do not click the back button.</p></div></div>';
		}else {
			var $load_content = '<img src="https://www.brett-robinson.com/_iqbooking_session_new/images/loading_message_bg.png" style="display:none;" /><img src="https://www.brett-robinson.com/_iqbooking_session_new/images/tips_loader.gif" style="display:none;" /><div id="blue_loading_secure" class="bloading" style="display:none; height:'+ window_h +'px;"><div id="loading_centered"><div id="loader_space"><p>Searching</p></div><div id="tip_space"><h2 class="avenir">Did You Know..</h2><p>'+ $tips[rnd_tip]+'</p></div></div>';
		}
		
		if ( $('div').hasClass("bloading") ) {
		} else { 
			$('#body').prepend($load_content);	}
		}
		
			
	function randomFromTo(from, to){
			return Math.floor(Math.random() * (to - from + 1) + from);
		}
	function getDocHeight() {
			var D = document;
			return Math.max(
				Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
				Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
				Math.max(D.body.clientHeight, D.documentElement.clientHeight)
			);
		}
								
	function randomFromTo(from, to){
			return Math.floor(Math.random() * (to - from + 1) + from);
		}
	
	
});







