function promotionWidget() {
	$('#contactModalCont').modal({
		close: false,
		overlayId: 'contactModalOverlay',
		containerId: 'contactModalContainer',
		iframeId: 'contactModalIframe',
		onOpen: comment.open,
		onShow: comment.show,
		onClose: comment.close
	});
}

function editPicture(id) {
$.get("/public/editpicture.php?id=" + id, function(data){
			// create a modal dialog with the data
			$(data).modal({
				close: false,
				overlayId: 'contactModalOverlay',
				containerId: 'contactModalContainer',
				iframeId: 'contactModalIframe',
				onOpen: comment.open,
				onShow: comment.show,
				onClose: comment.close
			});
});
}

function selectLightboxModal(picture, action) {
$.get("/public/selectlightbox.php?picture=" + picture + "&action=" + action, function(data){

                        if(data == -1) {
                            window.location = "/lightbox.htm";
                        }

			// create a modal dialog with the data
			$(data).modal({
				close: false,
				overlayId: 'contactModalOverlay',
				containerId: 'contactModalContainer',
				iframeId: 'contactModalIframe',
				onOpen: comment.open,
				onShow: comment.show,
				onClose: comment.close
			});
});
}

function googleMap() {
	$.get("/public/googleMap.php", function(data){
				// create a modal dialog with the data
				$(data).modal({
					close: false,
					overlayId: 'contactModalOverlay',
					containerId: 'contactModalContainer',
					iframeId: 'contactModalIframe',
					onOpen: comment.open,
					onShow: comment.show,
					onClose: comment.close
				});
	});
}

var comment = {
	message: null,
	open: function (dialog) {
		dialog.overlay.fadeIn(200, function () {
			dialog.container.fadeIn(200, function () {
				dialog.content.fadeIn(200, function () {
					$('#contactModalContainer #name').focus();
				});
				// resize the textarea for safari
				if ($.browser.safari) {
					$('#contactModalContainer textarea').attr({
						cols: '37',
						rows: '8'
					});
				}
			});
		});
	},
	show: function (dialog) {
		$('#contactModalContainer .shave').click(function (e) {
			e.preventDefault();
			// validate form
			if (comment.validate()) {
				$('#contactModalContainer .message').fadeOut(function () {
					$('#contactModalContainer .message').removeClass('error').empty();
				});
				$('#contactModalContainer .title').html('Wird verschickt ...');
				$('#contactModalContainer form').fadeOut(200);
				$('#contactModalContainer .content').animate({
					height: '80px'
				}, function () {
					$('#contactModalContainer .loading').fadeIn(200, function () {
						$.ajax({
							type: "POST", 
							url: 'action/do_addcomment.php',
							data: $('#contactModalContainer form').serialize() + '&action=send'+'&media_id='+$('#media_id').val(),
							dataType: 'html',
							complete: function (xhr) {
								$('#contactModalContainer .loading').fadeOut(200, function () {
									$('#contactModalContainer .title').html('Die Weiterempfehlung wurde verschickt. ');
									$('#contactModalContainer .message').html(xhr.responseText).fadeIn(200);
								});
							},
							error: comment.error
						});
					});
				});
			}
			else {
				if ($('#contactModalContainer .message:visible').length > 0) {
					$('#contactModalContainer .message div').fadeOut(200, function () {
						$('#contactModalContainer .message div').empty();
						comment.showError();
						$('#contactModalContainer .message div').fadeIn(200);
					});
				}
				else {
					$('#contactModalContainer .message').animate({
						height: '50px'
					}, comment.showError);
				}
				
			}
		});
	},
	close: function (dialog) {
		dialog.content.fadeOut(200, function () {
			dialog.container.fadeOut(200, function () {
				dialog.overlay.fadeOut(200, function () {
					$.modal.remove(dialog);
				});
			});
		});
	},
	error: function (xhr) {
		alert(xhr.statusText);
	}};


