var currentQuestbookMessage = null;
$(function(){
	$('#tellAFriend').bind(
		'click',
		function() {
			tellForm = $('#tellafriend_form');
			if (tellForm.css('display') == 'none') {
				tellForm.animate({top:1}, 300);
			} else {
				tellForm.animate({top:-400}, 300, function(){$(this).hide()});
			}
			this.blur();
			return false;
		}
	);
	$('#tell_cancel').bind(
		'click',
		function() {
			tellForm = $('#tellafriend_form');
			if (tellForm.css('display') == 'block') {
				tellForm.animate({top:-400}, 300, function(){$(this).hide()});
			}
			this.blur();
			return false;
		}
	);
	$('#tell_send').bind(
		'click',
		tellAFriend
	);
		if (document.getElementById("map")) {
			var map = new GMap2(document.getElementById("map"));
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
			map.setCenter(new GLatLng(51.449907, 3.882433), 11);
			var marker = new GMarker(new GLatLng(51.449907, 3.882433));
			map.addOverlay(marker);
			marker.openInfoWindowHtml('<strong>Steelwelding - Hoofdkantoor</strong><br />Rangeerstraat 21<br />4431 Borsele,<br />Netherlands');
			/*var geocoder = new GClientGeocoder();
			geocoder.getLatLng(
				"Rangeerstraat 21, 4431 NL 's Gravenpolder, Nederland",
				function(point) {
					for(i in point) {
						console.log(i + ':' + point[i]);
					}
				}
			);*/
		}
});

var tellAFriend = function()
{
	$('#tell_send, #tell_cancel').attr('disabled', true);
	$('#tell_ajax_indicator').css('display', 'inline');
	
	$.ajax(
		{
			type			: 'POST',
			url				: '/ajaxserver.php',
			data			: 'plugin=tellafriend&email=' + $('#tell_email').val() + '&name=' + $('#tell_name').val() + '&friend_email=' + $('#tell_friends_email').val() + '&friend_name=' + $('#tell_friends_name').val()  + '&message=' + $('#tell_message').val()  + '&url=' + window.location.href + '&language=' + currentLanguage,
			complete		: function()
			{
				$('#tell_send, #tell_cancel').attr('disabled', false);
				$('#tell_ajax_indicator').hide();
			},
			
			success			: function(xml)
			{
				errors = $('errorResponse', xml);
				okies = $('success', xml);
				
				errors.each(
					function()
					{
						alert(this.firstChild.nodeValue);
					}
				);
								
				if (errors.size() == 0) {
					var message = $('success', xml)[0].firstChild.nodeValue;
					alert(message);
				}
			}
		}
	);
	this.blur();
	return false;
}
