$(document).ready(function(){	
	$("span.action[title]").tooltip({ position: 'top right', effect: 'fade' });
	
	// pre-set the overlay; loaded on click below
	$("#suggestUpdate").overlay();
	var oAPI = $("#suggestUpdate").data("overlay");
		
	$("#suggestButton").hover(function(){
		$(this).children('.hover').fadeIn(100);
	}, function(){
		$(this).children('.hover').fadeOut(100);
	});
	
	$(".action").click(function(){
		var clicked = $(this).parent().parent().find('.singleTollName').html();
		$('select#location option').each(function(){
			if ($(this).html() == clicked) {
				$(this).attr('selected','selected');
			}
		});
		// load the overlay
		oAPI.load();
	});

	$("form#suggestionForm").validate({ submitHandler:
		function(form){
			var options = { target: '#thanks',
			success: function(){
					// close form overlay
					oAPI.close();
					$('#thanks').overlay({ top: 200 });
					var newAPI = $('#thanks').data("overlay");
					newAPI.load();
					$('#thanks').delay(2500).fadeOut(400);
					newAPI.close();
				} 
			};
			$(form).ajaxSubmit(options);
		}
	});
});

function changePage(){
	var state = $('select.state option:selected').val();
	
	if (state != '' && state != undefined) {
		window.location = '/states/' + state + '/';
	}
}
