	var PopupPosting = function()
	{
		var postingCache = new Array();
		var postingId = -1;

		var anchorElement;

		var popupTimeoutId;
		var popupDisplay = false;

		$("#popup-posting").bind('mouseenter', function()
		{
			clearTimeout(popupTimeoutId);
		});

		$("#popup-posting").bind('mouseleave', function()
		{
			popupTimeoutId = setTimeout(function(){
				$('#popup-posting').hide();
			}, 1000);
		});

		return {
			'setPostId': function(postId)
			{
				postingId = postId;

				if (popupDisplay == true)
				{
					$.ajax(
					{
						url     : "/ajax?action=getPost&post-id=" + postId,
						dataType: 'json',
						success : function(data)
						{
							$('#popup-posting').html(data.html);
						}
					});
				}
			},
			'setAnchor': function(anchorObject)
			{
				anchorElement = anchorObject;
			},
			'show': function(extraParams)
			{
				clearTimeout(popupTimeoutId);
				elementOffset = anchorElement.offset();
				$('#popup-posting').css('left', elementOffset.left - 205);
				$('#popup-posting').css('top', elementOffset.top);

				popupTimeoutId = setTimeout(function()
				{
					$.ajax(
					{
						url     : "/ajax?action=getPosting&post-id=" + postingId,
						data: extraParams,
						dataType: 'json',
						success : function(data)
						{
							$('#popup-posting').html(data.html);
						}
					});
					$('#popup-posting').show();
					popupDisplay = true;
				}, 2000);
			},
			'hide': function(direction)
			{
				clearTimeout(popupTimeoutId);
				popupTimeoutId = setTimeout(function(){
					$('#popup-posting').hide();
					popupDisplay = false;
				}, 600);
			}
		}
	}
	
	function getFlashMovieObject(movieName)
	{
		if (window.document[movieName])
		{
			return window.document[movieName];
		}
	
		if (navigator.appName.indexOf("Microsoft Internet")==-1)
		{
			if (document.embeds && document.embeds[movieName])
				return document.embeds[movieName];
		}
		else
		{
			return document.getElementById(movieName);
		}
	}

	var Webcam = function(element)
	{
		var elementName = element;
		var object = getFlashMovieObject(elementName);
		
		return {
			'takeSnapshot': function()
			{
				object.takeSnapshot();
			},
			'retakeSnapshot': function()
			{
				object.retakeSnapshot();
			},
			'uploadSnapshot': function(title, description, tags, destination, geolocation)
			{
				object.uploadSnapshot(title, description, tags, destination, geolocation);
			}
		}
	}
	

	var Dialog = function()
	{
		var currentDialog = '';
		var shown = false;
		
		return {
			'show': function(dialogName, options, callback)
			{
				if (shown == true)
				{
					$('#overlay').hide();
					$('#overlay-background').hide();
					$('#overlay .overlay-content').html('');
					$('#overlay .overlay-content#dialogs-'+currentDialog).attr('id', '');
					shown = false;
				}
				
				currentDialog = dialogName;
				
				// Check if the dialog is in the storage-div, otherwise load from ajax
				if ($('#dialog-storage #dialogs-'+dialogName).length > 0)
				{
					$('#overlay .overlay-content').html($('#dialog-storage #dialogs-'+dialogName).html());
					$('#overlay .overlay-content').attr('id', 'dialogs-'+dialogName);
					
					//add close button
					$('#overlay .overlay-content').append('<a id="button-close" href="#">close</a>');
					
					$('#overlay').show();
					$('#overlay-background').show();
					
					shown = true;

					if (callback !== undefined)
						callback(options);
				}
				else
				{
					shown = true;
					
					//show initial version while loading
					$('#overlay').show();
					$('#overlay-background').show();
					
					$.ajax(
					{
						url     : "/ajax?action=dialogLoad&name="+dialogName,
						dataType: 'json',
						data: options,
						success : function(data)
						{
							if (shown === true)
							{
								if(data.result == 'OK')
								{
									$('#overlay .overlay-content').html(data.html);
									$('#overlay .overlay-content').removeClass('loading');
									$('#overlay .overlay-content').attr('id', 'dialogs-'+dialogName);
									
									//add close button
									$('#overlay .overlay-content').append('<a id="button-close" href="#">close</a>');
									
									if (callback !== undefined)
										callback(options);
								}
								else
								{
									$('#overlay .overlay-content').html($('#dialog-storage #dialogs-error').html());
									$('#overlay .overlay-content').attr('id', 'dialogs-error');
									$('#overlay #dialogs-error .error-message').html(data.error);
									
									//add close button
									$('#overlay .overlay-content').append('<a id="button-close">close</a>');
								}
							}
						},
						error : function(a,b,c)
						{
							alert(a + " " + b + " " + c);
						}
					});
				}
			},
			'hide': function(direction)
			{
				$('#overlay').hide();
				$('#overlay-background').hide();
				
				/*
				$('#overlay .overlay-content').html('<h2 id="loading">Loading...</h2>');
				$('#overlay .overlay-content#dialogs-'+currentDialog).attr('id', '');
				$('#overlay .overlay-content').addClass('loading');*/
					
				/*$('#overlay').fadeOut(200, function()
				{

					shown = false;
				});*/
				
			}
		}
	}

