/* This script was written by Leonard Burton for LookTouchFeel */
jQuery(document).ready(function($) {
	
	lbFadeTime = 1000 ; 
	easeType = 'easeOutCubic' ;
	
	var defOpacLightbox ;
	var defOpacLightboxPanel ;
	
	$('#bn-lightbox-panel-content').find('input[type=text]').each(function(){
		
			// Store default value in 'rel' for reference.
			$(this).attr('rel', $(this).val());
			
			// Check if field is empty or placeholder changed.
			$(this).focus(function(){
				if($(this).val() == "" || $(this).val() == $(this).attr('rel')){
					$(this).val('') ;
				}
			});
			
			// If unchanged or empty, restore placeholder.
			$(this).blur(function(){
				if($(this).val() == "" || $(this).val() == $(this).attr('rel')){
					$(this).val( $(this).attr('rel') ) ;
				}
				
			});
			
		});
	
	function lightboxInit(){
		
		$( "#datepicker" ).datepicker();
		$( "#datepicker" ).datepicker( "option", "dateFormat", "DD, d MM, yy");
		
		$('#bn-lightbox-panel').css('top','100px');
		defOpacLightbox = $('#bn-lightbox').css('opacity') ;
		defOpacLightboxPanel = $('#bn-lightbox-panel').css('opacity') ;
		
		// Close button behaviours
		$('#bn-lightbox-close').text('Close');
		$('#bn-lightbox-close').click(function(){ lightboxClose() });
		
		lastSeg = window.location.pathname.substr(window.location.pathname.lastIndexOf('/') + 1) ;
		
		// Checks links for ref and fades in box when found
		$('a.book-now-open').click(function(){
			
			$('#selInterests').find('option').each(function(){
				conv = $(this).val().toLowerCase().split(' ').join('-');
				if(conv == lastSeg){
					$(this).attr('selected','selected')
				}
			});
			
			$('body').css('overflow', 'hidden')
			$('#bn-lightbox-panel').css('top','100px');
			
			$('#bn-lightbox').fadeTo(lbFadeTime, defOpacLightbox, function(){
				$('#bn-lightbox-panel').fadeTo(lbFadeTime * 2, defOpacLightboxPanel, easeType) 
			});
			
			return false;
				
		});
		
	}
	
	function lightboxClose(){
		$('body').css('overflow', 'auto')
		$('#bn-lightbox-panel').fadeTo(lbFadeTime, 0, function(){
			$('#bn-lightbox').fadeOut(lbFadeTime,easeType);
			$('#bn-lightbox-panel').css('top','-1000px');
		});
			
	}
	
	lightboxInit();
	
});
