var state	= "";

jQuery(function($) {

	//	State browse field change
	$("div#state select").change( function(event) {
	
		var cat_id	= $(this).attr("value");
		
		state	= $(this).children("option:selected").attr("id");
		
		$("div#metros select").empty();
		
		$("div#metros select").load( "/about-the-area/inc-metro-browse", { parent_id: cat_id } );
		
		metros_browse();
	});
	
	//	Photo delete
	$("div#photo a#photo_delete").click( function(event) {
		$("div#photo").load( "/about-the-area/ajax-photo-delete/", { entry_id:$(this).attr("href") }, function(event) { $("div#photo_form").show() });
		return false;
	});

	//	Submit
	$("form#entryform").submit( function(event) {
	
		var cat_name	= $("form#entryform div#state select").attr("value");
		
		if ( !cat_name || cat_name == "" )
		{
			alert( "Please select a state." );
			return false;
		}
	
		var metro_name	= $("form#entryform div#metros select").attr("value");
		
		if ( !metro_name || metro_name == "" )
		{
			alert( "Please select a metro." );
			return false;
		}
	
		var tag_name	= $("form#entryform div#tag select").attr("value");
		
		if ( !tag_name || tag_name == "" )
		{
			alert( "Please select a topic." );
			return false;
		}
	});
});

function metros_browse ()
{
	var cls = $("div#metros").attr("class");
	
	if ( cls == "nojump" )
	{
		return;
	}
	
	var temp_return	= "/about-the-area/";
	
	$("div#metros select").unbind("change");
	
	$("div#metros select").change( function(event) {
		var cat_id	= $(this).attr("value");
		
		var metro	= $(this).children("option:selected").attr("id");
		
		window.location	= temp_return + state + "/" + metro;
	});
}