/*
 * Copyright (C) 1995-2011 by 4system Polska Sp. z o.o.
 * All Rights Reserved.
 */
 
componentChangeTextAudio = function(name)
{
	this.componentChangeText = componentChangeText;
	this.componentChangeText(name);
	
	this.correctAnswersList = new Array();
	this.interactions = true;
	this.interactionsType = "numeric";
	this.rememberItemsArr = new Array();
	
	this.complete = false;
	this.basicText = '';
	this.counter = 0;
	
	this.iTimerID = null;
	this.allowGF = true;
	
	this.compAudio = null;
	this.buttons = new Array();
	
	this.imageHeigth = 0;
};

componentChangeTextAudio.prototype = new componentChangeText();
componentChangeTextAudio.prototype.type = "componentChangeTextAudio";

componentChangeTextAudio.prototype.onCreate = function(obj)
{	
	if (PageInterface.GetValue("state") != psDesigning &&  lms && this.disableOnlineOfflineMix != false ) 
	{
		this.resourcesStatus 	= lms.resourcesStatus();
		this.resourcesURL 		= lms.resourcesURL();
	} else this.resourcesURL = resourcesURL;

	this.captureMouseEvents();
	this.correctAnswersList = this.correctAnswer;
	
	var font = {};
	font.family = this.fontFamily;
	font.size = this.fontSize;
	font.color = this.fontColor;
	
	if (this.allowGF && project.globalFormating && this.isDefaultFont(font) && !this.isDefaultFont(project.font))
	{
		this.fontFamily = project.font.family;
		this.fontSize = project.font.size;
		this.fontColor = project.font.color;
	};
	
	if (PageInterface.GetValue("state") != psDesigning) this.generateAudio();
	this.generateButtons();
};

componentChangeTextAudio.prototype.generateButtons = function()
{
	var tempX = this.x + 3;
	var tempY = this.y + 3;		
	var imageHeigth = 0;
	var imageWidth = 0;	
	
	var audioButtonsArr = new Array(this.audioPlay, this.audioPause, this.audioStop, '_play_', '_pause_', '_stop_', 'Play', 'Pause', 'Stop');		
	for (var i=0; i < 3; i++){
		var image = new componentImage;
		image.myParent = this; 
		image.id = this.id+audioButtonsArr[i+3]+i; 
		image.x = tempX;
		image.y = tempY;
		var imageTest = new Image();
		imageTest.src = this.resourcesURL + audioButtonsArr[i];
		image.w = imageTest.width;
		image.h = imageTest.height;
		image.src = audioButtonsArr[i];
		image.cursor = 'hand';
		
		image.captureMouseEvents = this.captureMouseEvents;
		var funct = 'this.onMouseClickImage'+audioButtonsArr[i+6];
		image.eventClick = eval(funct);
		
		page.addChild(image);
		this.buttons.push(image);
		
		if (image.h > imageHeigth) imageHeigth = image.h;
		tempX +=  image.w + 5;
	};

	return imageHeigth; 
};

componentChangeTextAudio.prototype.editorPaint = function()
{
	return "";
}

componentChangeTextAudio.prototype.generateAudio = function()
{
	var audioElement = new componentAudio;
	audioElement.myParent = this;
	audioElement.id = this.id+'Audio'; 
	audioElement.src = this.src;
	audioElement.pvWMP64 = false;
	audioElement.pvWMP7up = false;
	audioElement.step = -1;
	audioElement.editorPaint = this.editorPaint;
	this.compAudio = page.addChild(audioElement);	
};

componentChangeTextAudio.prototype.onMouseClickImagePlay = function()
{
	this.myParent.compAudio.actionMediaPlay();
};

componentChangeTextAudio.prototype.onMouseClickImagePause = function()
{
	this.myParent.compAudio.actionMediaPause();
};

componentChangeTextAudio.prototype.onMouseClickImageStop = function()
{
	this.myParent.compAudio.actionMediaStop();
};

componentChangeTextAudio.prototype.onShow = function() {
	if (PageInterface.GetValue("state") != psDesigning) {
		for (var i=0; i < this.buttons.length; i++) {
			this.buttons[i].show();
		}
	}
}

componentChangeTextAudio.prototype.onPaint = function(obj)
{
	if (this.locked) return;

	var s = "";
	var dispAndCorrArray = this.text.toString().split("||");
	//selectedColor = this.selectedColor;
	selectedColor = this.markColor;
	
	bgColor = this.bgColor;
	if (PageInterface.GetValue("state") == psDesigning) {
		var ansArray = this.correctAnswer.split(",");
		var wasHit = false;
		
		s += '<table border="0" cellSpacing="0" cellPadding="0"><tr><td valign="top">&nbsp;&nbsp;<b>';
		if (this.anotherText == '-' && this.showCountNumber == 1) {
				s += '<span id='+this.id+'_span_counter style="background-color:'+this.selectedColor+';';
				s += ' font-size:'+this.getFontSize(this.fontSize, 'px')+'px; color:'+this.fontColor+'; ';
			
			if (this.answerCount == '') var answerCount = this.getAnswerCount(dispAndCorrArray);
			else answerCount = this.answerCount;
			
			s += ' font-family:'+this.fontFamily+';">'+answerCount+'</span>&nbsp;&nbsp;</b>';
			s += '</td>';
		};
		s += '<td>';
		
		for (var i=0; i < dispAndCorrArray.length; i++) {
			var textArray = dispAndCorrArray[i].split('@#@');
			for (var j=0; j < ansArray.length; j++) {
				if (textArray[1] != '') {
					s += "<span id='" + this.id + "_span_" + i + "' "+
						"style='background-color:" + selectedColor + "; font-size:" + this.getFontSize(this.fontSize, "px") + "px; color:" + this.fontColor + "; font-family:" + this.fontFamily + ";'>" ;
					onlyText = this.repalceStrbyStr(textArray[0], "$", "'");
					s += onlyText;						
					s += "</span> ";
					wasHit = true;
					break;
				}
			}
			if (!wasHit){
				s += "<span id='" + this.id + "_span_" + i + "' "+
					"style='background-color:" + this.bgColor + "; font-size:" + this.getFontSize(this.fontSize, "px") + "px; color:" + this.fontColor + "; font-family:" + this.fontFamily + ";'>";
				onlyText = this.repalceStrbyStr(textArray[0], "$", "'");
				s += onlyText;
				s += "</span> ";
			}
			wasHit = false;
		};
		s += '</td></tr></table>'
	} else {
		if (this.answerCount == '') var answerCount = this.getAnswerCount(dispAndCorrArray);
			else answerCount = this.answerCount;
		
		this.counter = answerCount;
		s += '<table border="0" cellSpacing="0" cellPadding="0"><tr><td valign="top">&nbsp;&nbsp;<b>';
		
		if (this.showCountNumber == 1){
			if (this.anotherText == '-') {
				s += '<span id='+this.id+'_span_counter style="background-color:'+this.selectedColor+';';
				s += ' font-size:'+this.getFontSize(this.fontSize, 'px')+'px; color:'+this.fontColor+'; ';
				
				
				s += ' font-family:'+this.fontFamily+';">'+answerCount+'</span>&nbsp;&nbsp;</b>';
				s += '</td>';
			}else if (page.all[this.anotherText]){
				this.basicText = page.all[this.anotherText].text;
				text = this.basicText.replace('{=counter}', this.counter);
				var textObj = PageInterface.GetValue("getChild", this.anotherText);
				var contentObj = textObj.findContentObj();
				if (contentObj)
					contentObj.innerHTML = text;			
			};
		}
		s += '<td>';
		
		for (var i=0; i < dispAndCorrArray.length; i++) {
			var textArray = dispAndCorrArray[i].split('@#@');			
			if (textArray[1] == '') textArray[1] = textArray[0];
		 	s += "<span id='" + this.id + "_span_" + i + "' "+
				"style='background-color:" + this.bgColor + "; font-size:" + this.getFontSize(this.fontSize, "px") + "px; color:" + this.fontColor + "; font-family:" + this.fontFamily + ";' "+
				"onclick = \'pc."+this.id+".clickSPAN(this, \""+bgColor+"\", \""+selectedColor+"\", \""+textArray[1]+"\", this.innerHTML );\'>";
			onlyText = this.repalceStrbyStr(textArray[0], "$", "'");
			s += onlyText;
			s += "</span> ";	
		};
		s += '</td></tr></table>'
	};
	
	this.imageHeigth = this.generateButtons();
	
	s += '<div id='+this.id+'divInput style="visibility: hidden; left:0; top:0; position: absolute">';

	s += '<input id='+this.id+'InputInsideText style="background: '+this.backgroundInputColor+';';
	s += ' border-color: '+this.borderInputColor+'; border-width : '+this.inputBorder+'px; width: 100px" onKeyup="pc.'+this.id+'.keyUp(this);" onKeydown="pc.'+this.id+'.confirmChange(event);" >';
	s += '<img id='+this.id+'ButtonHideDiv src="' + resourcesURL + this.buttonHideDiv + '"';
	s += ' onMousedown="pc.'+this.id+'.mouseDownButtonHideDiv(this, true);" style="cursor: hand">';
	s += '</div>';

	var backupText = s;
	var rows = '<table height="'+eval(this.imageHeigth+10)+'"><tr><td></td></tr></table>';
	s = rows + backupText;
	
	this.setHTML(s);
	//this.onRepaint();
};

/********************************************************************/
