(function() {
	$.attachUpdater(function() {
		function turn_off() {
			var password = $('#showcase-password').val();
			$.ajax({url: '/portlet/showcase/turn_off',
				data: {'showcase-password': password},
				dataType: 'json',
				success: function(json) {
					if (json.data && json.data.status === false) {
						$('#showcase-password-popup').popdown();
						$('#showcase-password-error').hide();
						document.location.reload();
					} else {
						$('#showcase-password-error').show();
					}
				}
			});
		};

		$('#showcase-turn-on').bind('click.update', function(event) {
			event.preventDefault();
			event.stopPropagation();
			$.ajax({url: '/portlet/showcase/turn_on',
				dataType: 'json',
				success: function(json) {
					document.location.reload();
				}
			});
		});
		
		$('#showcase-turn-off').bind('click.update', function(event) {
			event.preventDefault();
			event.stopPropagation();
			$('#showcase-password-popup').popup();
			$('#showcase-password').focus();
		});
		
		$('#showcase-submit-cancel').bind('click.update', function(event) {
			event.preventDefault();
			event.stopPropagation();
			$('#showcase-password-popup').popdown();
		});
		
		$('#showcase-form').bind('submit.update', function(event) {
			event.preventDefault();
			event.stopPropagation();
			turn_off();
		});
	});
})();

