

Canvas.prototype.addPoster = function (pId,pSrc,ext)
{
	var newPoster = new Poster(this,pId,pSrc,null,null,ext?ext:null);
	if (!this.getPosterById(pId))
	{
		this.aPosters.push(newPoster);
		this._mIndexes[pId] = [];
		this._mIndexes[pId][0] = [];
		this._mIndexes[pId][0][0] = true;
	}
}

Canvas.prototype.__construct = function()
{
		
	
	this.addPoster(5);
	this.addPoster(4);
	this.addPoster(6);
	this.addPoster(2);
	this.addPoster(8);
	this.addPoster(1);
	this.addPoster(9);
	this.addPoster(3);
	this.addPoster(7);
	
	
	
	addEvent(document, 'mouseup', stopDrag);
	addEvent(document, 'mousedown', startDrag);
	addEvent(document, 'dblclick', zoom);
	
	menuWidth = aWindowSize[0] - menuOffset;
	if (menuState == 1)
	{
		$('MenuContainer').style.width = menuWidth + 'px';
	}
	if (isMSIE)
	{
		this.oElem.className += '';
	}


	//this.concentrateOn(5);
}



Canvas.prototype.duplicatePoster = function (sender,dXi,dYi)
{
	if ((!this._mIndexes[sender._id][sender._Xi+dXi]) || !this.getPosterInMatrix(sender._id,sender._Xi+dXi,sender._Yi+dYi))
	{
		var newPoster = new Poster(this,sender._id,sender._strId,sender._Xi+dXi,sender._Yi+dYi);
		if (!newPoster)
			return false;

		if (!this._mIndexes[sender._id][sender._Xi+dXi])
			this._mIndexes[sender._id][sender._Xi+dXi] = [];
		this._mIndexes[sender._id][sender._Xi+dXi][sender._Yi+dYi] = true;
		this.aPosters.push(newPoster);
		/*this._mIndexes[sender._id][sender._Xi][sender._Yi] = false;
		if (sender.oImg)
			this.oElem.removeChild(sender.oImg);
		sender.oImg = null;
		sender = null;*/
		
	}
	else
		return false;
}

Canvas.prototype.getPosterById = function (pId)
{
	for (var i in this.aPosters)
	{
		if (typeof(this.aPosters[i]) != 'function')
		{
			if (this.aPosters[i]._id == pId)
				return this.aPosters[i];
		}
	}
	return false;
}

Canvas.prototype.getPosterInMatrix = function (pId, Xi, Yi)
{
	return this._mIndexes[pId][Xi][Yi];
}

Canvas.prototype.onDrag = function ()
{
	//debug('');
	for (var i = 0; i < this.aPosters.length; i++)
	{
		
		this.aPosters[i].onDrag();
	}
}

Canvas.prototype.onZoomStart = function ()
{
	this.oDraw.clear();
	
	
}
Canvas.prototype.onZoomEnd = function () 
{
	if (this._cZoom == 1)
	{
		/* In */
		
		removeClass(this.oManOut, "selected");
		removeClass(this.oManInEvt, "selected");
		addClass(this.oManIn, "selected");
		addClass(this.oManOutEvt, "selected");
		
		this.oDraw.drawLine({x: this.oManIn.offsetLeft+1, y: this.oManOut.offsetTop+2}, {x: (89), y: (45)}, {color: '#EF7876', width: 1});
		this.oDraw.drawLine({x: this.oManIn.offsetLeft+1, y: this.oManOut.offsetTop+2}, {x: (89), y: (13)}, {color: '#EF7876', width: 1});
	}
	else
	{
		removeClass(this.oManIn, "selected");
		removeClass(this.oManOutEvt, "selected");
		addClass(this.oManOut, "selected");
		addClass(this.oManInEvt, "selected");
		
		this.oDraw.drawLine({x: this.oManOut.offsetLeft+1, y: this.oManOut.offsetTop+2}, {x: (this.oMiniMap.offsetLeft+this.oMiniMap.offsetWidth - 24), y: (this.oMiniMap.offsetTop+this.oMiniMap.offsetHeight-1)}, {color: '#EF7876', width: 1});
			this.oDraw.drawLine({x: this.oManOut.offsetLeft+1, y: this.oManOut.offsetTop+2}, {x: (this.oMiniMap.offsetLeft+this.oMiniMap.offsetWidth - 23), y: this.oMiniMap.offsetTop+1}, {color: '#EF7876', width: 1});
	}
}