
function photoRelay(img)
{
	photoAdd(img);
}

function photoAdd(img)
{
	photoAdminClose();

	var photo_html = '<img class="photoListImage" src="/useruploads/_images/' + img + '" />';

	// Add to photo list
	$('#photo_list').html(photo_html);
	$('#photo').val(img);

	if ($('#photo_list').children().length > 0)
	{
		$('#photo_add').attr('disabled','disabled');
		$('#photo_remove').removeAttr('disabled');
	}
}

function photoUpload(w,h)
{
	var html = '<iframe width="100%" height="100%" frameborder="1" scrolling="auto" src="http://' + window.location.hostname + '/ajax/admin/module:photo/output:photoRelay/width:'+w+'/height:'+h+'/"></iframe>';
	$('#mainContentEditor').html(html);

	photoAdminOpen();
}

function photoAdminClose()
{
	$('#mainMask').fadeOut(500, function()
	{
		$('#mainContentEditor').hide();
	});
}

function photoRemove()
{
	$('#photo').val('');
	$('#photo_list').empty();
	$('#photo_add').removeAttr('disabled');
	$('#photo_remove').attr('disabled','disabled');
	$('#photo_list').html('<img src="/modules/attorney_search/images/imgUserLarge.gif" />');
}

function photoAdminOpen()
{
	var width = $(document).width();
	$('#mainMask').css('width', width);

	var height = $(document).height();
	$('#mainMask').css('height', height);
	
	$('#mainMask').click(function() {
		window.location.reload();
	});

	$('#mainMask').fadeTo(500, 0.6);
	$('#mainMask').fadeIn(500, function()
	{
		$('#mainContentEditor').css('width', '80%');
		$('#mainContentEditor').css('height', '80%');

		$('#mainContentEditor').css('top', ( $(window).height() - $('#mainContentEditor').height() ) / 2 + $(window).scrollTop() + 'px');
		$('#mainContentEditor').css('left', ( $(window).width() - $('#mainContentEditor').width() ) / 2 + $(window).scrollLeft() + 'px');
	});

	$('#mainContentEditor').show();
}

var geocoder; 
var map = Array();

function createMap(id, address)
{
	geocoder = new google.maps.Geocoder();
	codeAddress(id, address);
	
	var latlng = new google.maps.LatLng(0,0);
	var myOptions = {
		zoom: 13,
		center: latlng,
		disableDefaultUI: true,
		navigationControl: true,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	
	map[id] = new google.maps.Map(document.getElementById('map_'+id), myOptions);
} 

function codeAddress(id, address)
{
	if (geocoder)
	{
		geocoder.geocode({ 'address': address}, function(results, status)
		{
			if (status == google.maps.GeocoderStatus.OK)
			{
				map[id].setCenter(results[0].geometry.location);
				var marker = new google.maps.Marker({
					map: map[id],
					position: results[0].geometry.location
				});
			} else {
				$('#map_'+id).remove();
			}
		});
	}
}

