var COOKIE_NAME = 'SPTimes-SLG-Cookie';

$(document).ready(function () {

	//Sets the cookie by what user chose in dialog.
	$('.simplemodal-close').bind('click', function () {
		if ($(this).attr('id') == 'TB') {
			// set cookie by number of days
			var options = { path: '/', expires: 365 };
			$.cookie(COOKIE_NAME, $(this).attr('id'), options);
			$('#SLG_modal_tampabay_button').hide();
			$('#SLG_modal_golfcoast_button').hide();
			window.location = "/tampabay"
			
		} else if ($(this).attr('id') == 'GC') {
			// set cookie by number of days
			var options = { path: '/', expires: 365 };
			$.cookie(COOKIE_NAME, $(this).attr('id'), options);
			$('#SLG_modal_tampabay_button').hide();
			$('#SLG_modal_golfcoast_button').hide();
			window.location = "/gulfcoast"
		}
	});

	//Expires cookie and opens jquery dialog.
	$('#changeLocationBackToModal').bind('click', function () {
		$.cookie(COOKIE_NAME, null);

		$("#seniorlivingmodal").modal({
			minHeight:270, 
			minWidth: 565,  
			onClose: function (dialog) {
				dialog.data.fadeOut(function () {
					$.modal.close();
				});
		}});		
	});

	//This check during initial load. Shows dialog when cookie is null.
	if ($.cookie(COOKIE_NAME) == null) {
		$("#seniorlivingmodal").modal({
			minHeight:270, 
			minWidth: 565,  
			onClose: function (dialog) {
				dialog.data.fadeOut(function () {
					$.modal.close();
				});
		}});
	}
});

//Called on page load. Sets up links and menu using the cookie var.
$(document).ready(function () {
	//alert("load2");
	if ($.cookie(COOKIE_NAME) == 'TB') { 
		$('#region').val('TB');
		$('#cityTB').show();
		$('#cityGC').hide();
		window.location = "/tampabay"
		
	} else if ($.cookie(COOKIE_NAME) == 'GC') {
		$('#region').val('GC');
		$('#cityTB').hide();
		$('#cityGC').show();
		window.location = "/gulfcoast"
	}

	$('#region').change(function () {
		if($(this).val() == 'TB') {
				//filterCategory.fnFilter($(this).val());
				//$('#listings').show();
				$('#cityGC').hide();
				$('#cityTB').show();
			//alert($(this).val());
		} else if ($(this).val() == 'GC') {
				$('#cityTB').hide();
				$('#cityGC').show();
				//alert($(this).val());
		}
	});
});
