// CurvesFit Functions
$(document).ready(function() {	
	// Autotab phone number
	$('#form_phone_area').autotab({target: 'form_phone_prefix'});
	$('#form_phone_prefix').autotab({target: 'form_phone_suffix'});
	
	$('#form_phone_area_evening').autotab({target: 'form_phone_prefix_evening'});
	$('#form_phone_prefix_evening').autotab({target: 'form_phone_suffix_evening'});

	// Print and hide coupon overlay
	$('#btn_coupon_print,#btn_appt_coupon_print').bind('click', function() {
		$('#coupon_overlay').fadeOut(function() {
			window.print();
			_gaq.push(['_trackEvent', 'print', 'Coupon Print']);
		});	
	});		
	
	// Print and hide coupon overlay
	$('#activate_friend_coupon').bind('click', function() 
	{
		$('#coupon_overlay').fadeOut("fast");
		//change name
		$("#coupon_hdr").html("Guest: Preferred Guest");
		window.print();
		_gaq.push(['_trackEvent', 'print', 'Friend Coupon Print']);
	});		   
});


//Homepage Subnav
$(document).ready(function() {
	$('ul#subnav li').bind('click', function() {
		var contentID = $(this).attr('id');
		$("#content_wrap div").hide();
		$("ul#subnav li").removeClass("subnav_hover");
		$("#content_" + contentID).fadeIn();
		$("#" + contentID).addClass("subnav_hover");
	});
	
	var locations_page_results = 1;
	  
	$("#previous_locations_link").bind('click',function() 
	{
		current_results_id = ".location_detail.location_results_page" + locations_page_results--;
		next_results_id = ".location_detail.location_results_page" + locations_page_results;
		
		$("#new_search_link").hide();
		
		if (locations_page_results == 1)
		{
			$("#previous_locations_link").hide();
		}
		else if (locations_page_results == 2)
		{
			$("#more_locations_link").show();
		}
		
		$(current_results_id).fadeOut(500,function(){
			$("#loading_image").fadeIn(700,function(){
				$("#loading_image").fadeOut(700, function() {
					$(next_results_id).fadeIn(500);  
				});  
			});
		});
	});
	
	
	$("#more_locations_link").bind('click',function() 
	{
		current_results_id = ".location_detail.location_results_page" + locations_page_results++;
		next_results_id = ".location_detail.location_results_page" + locations_page_results;
		
		$("#new_search_link").hide();
		$("#previous_locations_link").show();
		$("#more_locations_link").show();
		
		if (locations_page_results == 3)
		{
			$("#more_locations_link").hide();
			$("#new_search_link").show();
		}
		
		$(current_results_id).fadeOut(500,function(){
			$("#loading_image").fadeIn(700,function(){
				$("#loading_image").fadeOut(700, function() {
					$(next_results_id).fadeIn(500);
				});  
			});
		});
	});
	
	
	$("#new_search_link").bind("click",function(){document.location = 'index.php';});
});
