/*
 * Copyright (C) 1995-2011 by 4system Polska Sp. z o.o.
 * All Rights Reserved.
 */

componentSayingExercise = function(name)
{
	this.componentElement = componentElement;
	this.componentElement(name);
	
	this.buttons = new Array();
	this.texts = new Array();	
	this.activeX = new Array();	
	
	this.activeXObj = null;
};

componentSayingExercise.prototype = new componentElement();
componentSayingExercise.prototype.type = "componentSayingExercise";

componentSayingExercise.prototype.componentSayingExerciseBaseonCreate = componentSayingExercise.prototype.onCreate;
componentSayingExercise.prototype.onCreate = function(obj) 
{
	//this.componentSayingExerciseBaseonCreate();
	
	if ( PageInterface.GetValue("state") != psDesigning && lms && this.disableOnlineOfflineMix != false ) 
	{
		this.resourcesStatus 	= lms.resourcesStatus();
		this.resourcesURL 		= lms.resourcesURL();
	} else this.resourcesURL = resourcesURL;
	
	var sizeDiv = '<span id="sizeDiv" style="width: '+eval(this.w-this.audioPlayW-10)+' ; visibility: hidden; position: absolute; font-family:' + this.fontFamily
	+ '; font-size:' + this.getFontSize(this.fontSize, "px") + 'px; color:' + this.fontColor + ';"></span>';
	
	var ob = document.getElementById(this.id);
	ob.innerHTML += sizeDiv;
	
	var controlRightW = 0;
	
	if (PageInterface.GetValue("state") == psNormal){
		var activeXElem = new __componentText;
		activeXElem.parentText = this; 
		activeXElem.id = this.id+'_controlActiveX';
		if (this.activeXDir == "bottom"){
			activeXElem.x = this.x+eval(this.w/2)-171;
			activeXElem.y = this.y+this.h-232;
		}else{
			activeXElem.x = this.x+this.w-341;
			activeXElem.y = this.y+eval(this.h/2)-120;			
			controlRightW = 350;
		}
		activeXElem.w = 362;
		activeXElem.h = 262;
		activeXElem.step = this.step;
		
		activeXElem.onCreate = this.onCreateActiveX;
		activeXElem.onPaint = this.onPaintActiveX;
		activeXElem.text = this.getActiveXHTMLDef(this.id+'_controlActiveX');	
		activeXElem.specificRemove = this.__specificRemove;
		
		this.activeXObj = page.addChild(activeXElem);
	}else{
		var image = new componentImage;
		image.myParent = this; 
		image.id = this.id+'_screen';
		if (this.activeXDir == "bottom"){
			image.x = this.x+eval(this.w/2)-171;
			image.y = this.y+this.h-232;
		}else{
			image.x = this.x+this.w-341;
			image.y = this.y+eval(this.h/2)-120;
		}
		image.w = 341;
		image.h = 230;
		image.src = 'audioAXRec.jpg';
		
		page.addChild(image);
		this.activeX.push( image );	
		
		var textTemp = new __componentText;
		textTemp.parentText = this; 
		textTemp.id = this.id+'_warning';
		textTemp.text = this.textDesign;
		if (this.activeXDir == "bottom"){
			textTemp.x = this.x+eval(this.w/2)-171;
			textTemp.y = this.y+this.h-100;
		}else{
			textTemp.x = this.x+this.w-341;
			textTemp.y = this.y+eval(this.h/2);
			controlRightW = 350;
		}		
		textTemp.w = 341;
		textTemp.h = 232;
		textTemp.align = "center";
		
		page.addChild(textTemp);		
		this.activeX.push( textTemp );	
		
	};
	var textArr = this.text.split('||');
	var audioButtonsArr = new Array(this.audioPlay, '_load_', 'Load');
	
	var tempX = this.x + 5;
	var tempY = this.y + 5;	
	
	for (var i=0; i < textArr.length; i++){
		var oneRow = textArr[i].split('#!#');
		
		var textTemp = new __componentText;
		textTemp.parentText = this; 
		textTemp.id = this.id+'_text_'+i; 
		textTemp.text = oneRow[0];
		textTemp.x = tempX;
		textTemp.y = tempY;
		textTemp.w = this.w - this.audioPlayW - 10 - controlRightW;
		
		if (document.getElementById("sizeDiv")) {
			document.getElementById("sizeDiv").innerHTML = oneRow[0];
			var height = document.getElementById("sizeDiv").offsetHeight;
		};		
		
		textTemp.h = height + 8;
		textTemp.borderWidth = 1;
		textTemp.padding = 5;
		textTemp.borderColor = this.textBorderColor;
		textTemp.bgColor = this.textBckgColor;
		
		var compText = page.addChild(textTemp);
		this.texts.push( textTemp );	
		
		var lastImageW = 0;
		
		var image = new componentImage;
		image.myParent = this; 
		image.id = this.id+audioButtonsArr[1]; 
		image.x = this.x + this.w - this.audioPlayW - controlRightW;		
		image.y = tempY;
		image.w = this.audioPlayW;
		image.h = this.audioPlayH;
		
		image.src = audioButtonsArr[0];
		image.cursor = 'hand';
		image.fileName = oneRow[1];
		
		image.captureMouseEvents = this.captureMouseEvents;
		var funct = 'this.onMouseClickImage'+audioButtonsArr[2];
		image.eventClick = eval(funct);
		
		page.addChild(image);
		this.buttons.push(image);
		if (height > this.audioPlayH) tempY += height + 10;
			else tempY += this.audioPlayH + 3;
	};	
};

componentSayingExercise.prototype.onCreateActiveX = function()
{
	this._setHTMLDef(this.text);
}

componentSayingExercise.prototype.onPaintActiveX = function()
{	
	return;
};

componentSayingExercise.prototype.isReady = function()
{
	var isLoaded = false;
	for (var i=0; i < this.buttons.length; i++)
	{
		var isLoaded = this.buttons[i].isReady();
		if (!isLoaded) return false;
	};	
	
	this.isLoaded = isLoaded;
	return this.isLoaded;
};

componentSayingExercise.prototype.onMouseClickImageLoad = function()
{
	if (PageInterface.GetValue("state") == psNormal){
		var obj = document.getElementById(this.myParent.id + '_controlActiveXactiveX');
		
		var fileName = this.fileName;
		if (obj && fileName != '') {
			obj.WavPattern = this.myParent.resourcesURL + fileName;
			if (typeof(obj.ResizeForm) != 'undefined')
				obj.ResizeForm(341, 230, 1);
		};		
		return(true);	
	}else{
		showMessage('Load file work correctly after course export.');
	};
};

componentSayingExercise.prototype.getActiveXHTMLDef = function(id)
{
	var t = '';	
	t += '<OBJECT id="'+ id + 'activeX"';
	t += ' classid="clsid:9E05090D-A2E3-4240-990C-2B3FF1097453"';
	t += ' codebase="'+ this.resourcesURL +'axRecorderProj1.ocx#version=1,0,0,315"';
	t += ' width=341 height=230 align=center hspace=0 vspace=0 name="'+ id +'activeX">';		
	t += '<param name="WavPattern" value="">';		
	t += '<param name="ResizeForm" value="">';		
	t += '</OBJECT>';
	
	return t;
};

componentSayingExercise.prototype.getFontSize = function(value, format)
{
	var fontSizesPX = new Array(0,10,13,16,18,24,32,48);
	var fontSizesPT = new Array(0, 8,10,12,14,18,24,36);
	var pxSize = fontSizesPT[parseInt(value)];
	if (format == "px") {
		pxSize = fontSizesPX[parseInt(value)];
	}
	return pxSize;
};

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

}

componentSayingExercise.prototype.onPaint = function(obj) 
{
	var obj = document.getElementById(this.id+'_controlActiveXactiveX');
	if (obj) {
		obj.WavPattern = '';
		if (typeof(obj.ResizeForm) != 'undefined')
			obj.ResizeForm(341, 230, 1);
	};
};

componentSayingExercise.prototype.__specificRemove = function() 
{
	var obj = document.getElementById(this.id + 'activeX');
	if (obj) {
		if (typeof(obj.DoUnload) != 'undefined')
			obj.DoUnload();
	};		
};

componentSayingExercise.prototype.PlayPattern = function()
{
	var obj = document.getElementById(this.id + 'activeX');
	if (obj) {
		if (typeof(obj.PlayPattern) != 'undefined')
			obj.PlayPattern();
	};		
	return(true);	
};

componentSayingExercise.prototype.PausePattern = function()
{
	var obj = document.getElementById(this.id + 'activeX');
	if (obj) {
		if (typeof(obj.PausePattern) != 'undefined')
			obj.PausePattern();
	};		
	return(true);	
};

componentSayingExercise.prototype.StopPattern = function()
{
	var obj = document.getElementById(this.id + 'activeX');
	if (obj) {
		if (typeof(obj.StopPattern) != 'undefined')
		obj.StopPattern();
	};		
	return(true);		
};

componentSayingExercise.prototype.RecordNew = function()
{
	var obj = document.getElementById(this.id + 'activeX');
	if (obj) {
	if (typeof(obj.RecordNew) != 'undefined')
		obj.RecordNew();
	};		
	return(true);		
};

componentSayingExercise.prototype.PlayNew = function()
{
	var obj = document.getElementById(this.id + 'activeX');
	if (obj) {
		if (typeof(obj.PlayNew) != 'undefined')
			obj.PlayNew();
	};		
	return(true);		
};

componentSayingExercise.prototype.PauseNew = function()
{
	var obj = document.getElementById(this.id + 'activeX');
	if (obj) {
		if (typeof(obj.PauseNew) != 'undefined')
			obj.PauseNew();
	};		
	return(true);		
};

componentSayingExercise.prototype.StopNew = function()
{
	var obj = document.getElementById(this.id + 'activeX');
	if (obj) {
		if (typeof(obj.StopNew) != 'undefined')
			obj.StopNew();
	};		
	return(true);	
};

componentSayingExercise.prototype.Compare = function()
{
	var obj = document.getElementById(this.id + 'activeX');
	if (obj) {
		if (typeof(obj.Compare) != 'undefined')
			obj.Compare();
	};		
	return(true);	
};
