if ((top.ChannelServiceInit == "undefined") || (top.ChannelServiceInit != true))
{

	/**
	 *
	 * ChannelService CLASS definition.
	 *
	 */

	function ChannelService() {
	    this.channels = new Array();
	    this.parentDocument = null;
	}

	/**
	 * Returns the free Channel number in the channel list.
	 */

	ChannelService.prototype.getFreeChannelNumber = function()
	{
		var count = 0;
		for ( count = 0; count < this.channels.length; count++){
			if ( this.channels[count] == null)
				return count;
		}
		return this.channels.length;
	}

	/**
	 * Sets the DOMDoc for channelService.
	 * @argument parentDocument - document of the main window
	 */

	ChannelService.prototype.setDOMDoc = function (parentDocument)
	{
		this.parentDocument = parentDocument;
	}

	/**
	 * Returns a free Channel available.
	 * @returns Channel available
	 */

	ChannelService.prototype.getChannel = function()
	{
		if( this.parentDocument != null){
			var freeChannel = this.getFreeChannelNumber();
			this.channels[freeChannel] = new Channel(this.parentDocument, 'channel'+ freeChannel);
			return this.channels[freeChannel];
		}
	}

	/**
	 * Releases the channel with given Id.
	 * @argument channelId.
	 */

	ChannelService.prototype.releaseChannel = function ( channelId ){
		var channelCount = channelId.substr(7);
		this.channels[channelCount].release();
		this.channels[channelCount] = null;
	}


	/**
	 * Create a ChannelService instance - on the main window
	 */

	if ( top.channelService == null)
	{
		top.channelService = new ChannelService();
		top.channelService.setDOMDoc(document);
	}
	
	
	//////////////////////////////////////

	top.ChannelServiceInit = true;
}
	