function CMaze(parent)
{
	this.parent = parent;
	
	this.reqs = new CReqs(this);
	
	this.id = null; //only used for saving
	this.data = "";
	
	this.read = function()
	{
		game.response("mazeRead", this.data);
	}
	
	this.load = function(id)
	{
		if(id > 0)
			this.reqs.post("maze.load", '{"id":"'+id+'"}', "mazeLoad", null);
   	//else
    		//this.reqs.post("maze.load", null, "mazeLoad", null);
	}
	
	this.save = function(id)
	{
		this.id = id;
		this.data = "";
		
		game.fb.publishActivity(l.get("fb-activity-text2", []), l.get("fb-activity-play", []), game.fb.getShareLink(id, null));
	}
	
	this.list = function()
	{
		this.reqs.get("maze.list", "mazeList", null);
	}
	
	this.requestCallback = function(self, type, mazeData)
	{
		with(self)
		{
			switch(type)
			{
				case "mazeLoad":
					id = mazeData.id;
					owner = mazeData.owner;
					data = mazeData.data;
					
					//game.fb.incrementCounter(owner);
					game.fb.publishActivity(l.get("fb-activity-text1", []), l.get("fb-activity-play", []), game.fb.getShareLink(id, null));
					
					game.response(type, mazeData.data);
				break;
				/*
				case "mazeSave":
					id = mazeData.id;
				
					game.response(type, mazeData.id);
				break;
				*/
				case "mazeList":					
					var mazes = mazeData;
					var content = "";
					
					if(mazes == null)
						content += l.get("mazes-no-mazes", []);
					else
					{
						for(var i = 0; i < mazes.length; i++)
						{
							var sentence = "";
							if(mazes[i].days == 0)
								sentence = l.get("mazes-edited-today", []);
							else if(mazes[i].days == 1)
								sentence = l.get("mazes-edited-yesterday", []);
							else
								sentence = l.get("mazes-edited-days-ago", [mazes[i].days]);
							
							content += "<a href=\"javascript:game.maze.select("+mazes[i].id+")\"><img src=\"images/saved_maze.png\" alt=\"Maze\"><br />"+sentence+"</a>";
						}
					}
					
					mE("mazes-content").content(content);
					
					game.hideLoader();
					mE("mazes").show();
				break;
			}
		}
	}
	
	this.select = function(id)
	{
		this.load(id);
		
		game.menu.select('game');
	}
	
	this.show = function()
	{
		game.showLoader();
		
		this.list();
		//mE("mazes").show();
	}
	
	this.hide = function(){	mE("mazes").hide(); }
}

