/* Copyright 2009 Palm, Inc.  All rights reserved. */


var PowerManagerService = Class.create(
{
	initialize: function(){
		this.dimStopped = false;
		this.blockRequest = null;
	},


	stopScreenDim: function()
	{
		if (this.dimStopped)
			return;
			
		this.dimStopped = true;
		var parameters = {};
		parameters.requestBlock = true;
		parameters.client = Mojo.appName;
		parameters.subscribe = true;
		
		llog("sending block screen dim, app name: ", parameters.client);
		
		this.blockRequest = new Mojo.Service.Request(
				PowerManagerService.identifier,
				{
					method: 'setProperty',
					parameters: parameters

				}
			);
			
		return this.blockRequest;
	},
	
	allowScreenDim: function()
	{
		if (!this.dimStopped)
			return;
		
		if (this.blockRequest){
			this.blockRequest.cancel();
			this.blockRequest = null;
		}
		
		this.dimStopped = false;		
		var parameters = {};
		parameters.requestBlock = false;
		parameters.client = Mojo.appName;
		
		return new Mojo.Service.Request(
				PowerManagerService.identifier,
				{
					method: 'setProperty',
					parameters: parameters

				}
			);
	},
	
	registerForEvents: function(callback)
	{
		var parameters = {};
		parameters.subscribe = true;
		
		return new Mojo.Service.Request(
				PowerManagerService.identifier,
				{
					method: 'status',
					onSuccess: callback,
					parameters: parameters

				}
			);
	}

});

PowerManagerService.identifier = 'palm://com.palm.display/control';

