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

componentHintText = function(name) {
	this.__componentText = __componentText;
	this.__componentText(name);
	
	this.compAudio = null;	
};

componentHintText.prototype = new __componentText;
componentHintText.prototype.type = "componentHintText";

componentHintText.prototype.onBaseCreate = function(obj) {
	this.captureMouseEvents();
};

componentHintText.prototype.componentHintTextBaseOnCreate = componentHintText.prototype.onCreate;
componentHintText.prototype.onCreate = function(obj) {
	this.componentHintTextBaseOnCreate();
	
	if (this.enableFlashPlayer) {
		var e = new componentFlashAudioPlayer;
		e.myParent = this;
		e.id = this.id + 'Audio';
		e.step = -1;
		e.src = this.flashAudioPlayerSrc;
		e.x = 0;
		e.y = 0;
		e.w = 1;
		e.h = 1;
		e.loop = false;
		e.flashVars = "";
		this.compAudio = page.addChild(e);
	} else {		
		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);	
	}
	
	if (PageInterface.GetValue("state") != psDesigning && lms && this.disableOnlineOfflineMix != false )
	{
		this.resourcesStatus 	= lms.resourcesStatus();
		this.resourcesURL 		= lms.resourcesURL();
	} else this.resourcesURL = resourcesURL;
	
	var match = this.text.match(/\{[^\{]+\}/gi);
	var hintArr = this.hintsForWords.split("||");
	
	var baskets = this.text;
	
	if (PageInterface.GetValue("state") == psDesigning){
		for (var i=0; i < match.length; i++) {
			onlyText = match[i].substr(1,match[i].length-2);	
			
			baskets = baskets.replace(match[i], '<span id="_'+this.id+'_'+i+'" style="background: '+this.selectedColor+'; font-size:' + getFontSize(this.font.size, 'px') + 'px; color:' + this.font.color + '; font-family:' + this.font.family + ';">'+onlyText+'</span>');
		};	
	}else{
		for (var i=0; i < match.length; i++) {
			onlyText = match[i].substr(1,match[i].length-2);	
			var descHint = ' ';
			for (var j=0; j < hintArr.length; j++){
				var splited = hintArr[j].split("#!#");
				if (onlyText == splited[0]) {
					descHint = this.changeRabits(splited[1]);
				};
			};		
			
			//baskets = baskets.replace(match[i], '<span id="_'+this.id+'_'+i+'" style="background: '+this.selectedColor+'; font-size:' + this.getFontSize(this.font.size, 'px') + 'px; color:' + this.font.color + '; font-family:' + this.font.family + ';" onMouseover="pc.'+this.id+'.mouseOverSpan(\''+descHint+'\', this, \''+this.mouseOverColor+'\');" onMouseout="pc.'+this.id+'.mouseOutSpan(this, \''+this.selectedColor+'\');">'+onlyText+'</span>');

			var arr = hintArr[i].split("#!#");
			
			baskets = baskets.replace(match[i], '<span id="_'+this.id+'_'+i+'" style="background: '+this.selectedColor+'; font-size:' + getFontSize(this.font.size, 'px') + 'px; color:' + this.font.color + '; font-family:' + this.font.family + ';" onMouseover="pc.'+this.id+'.mouseOverSpan(\''+descHint+'\', this, \''+this.mouseOverColor+'\');" onMouseout="pc.'+this.id+'.mouseOutSpan(this, \''+this.selectedColor+'\');" onMousedown="pc.'+this.id+'.mouseClickSpan(this, \''+arr[2]+'\'); ">'+onlyText+'</span>');			
		};
	};
	
	this.text = baskets;
};

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

componentHintText.prototype.changeRabits = function(coment)
{
	coment = coment.replace(/"/g, "&quot;");
	coment = coment.replace(/'/g, "&#146;");
	
	return coment;
};

componentHintText.prototype.getAudioIndex = function(audioFile)
{
	var result = -1;
	var contentArr = this.hintsForWords.split("||");
	for(var i=0; i < contentArr.length; i++){
		var oneArr = contentArr[i].split('#!#');
		if (oneArr[2] == audioFile) {
			result = i;
			break;
		}
	}
	return result;
}

componentHintText.prototype.mouseClickSpan = function( obj, audio )
{	
	if (this.enableFlashPlayer) {
		this.compAudio.flashVars = "playIdx="+this.getAudioIndex(audio)+"&autoStart=true&playOnce=true";
		this.compAudio.show();
	} else {
		this.compAudio.setUrl(this.resourcesURL + audio);
		this.compAudio.actionMediaPlay();
	};	
};

componentHintText.prototype.mouseOverSpan = function( descHint, obj, color )
{
	var pageDiv = document.getElementById(this.id+'Div');
	
	pageDiv.innerHTML = descHint;
	if (is.ie) {
		var X = event.x;
		var Y = event.y;	
	}else {
		var X = event.clientX; 
		var Y = event.clientY
	}
	pageDiv.style.left = X + 30;
	pageDiv.style.top = Y + 30;
	pageDiv.style.visibility = 'inherit';

	obj.style.background = color;
};

componentHintText.prototype.mouseOutSpan = function(obj, color)
{
	var pageDiv = document.getElementById(this.id+'Div');
	pageDiv.style.visibility = 'hidden';
	
	obj.style.background = color;
};

componentHintText.prototype.onAfterLoad = function(obj)
{
	var newdiv = document.createElement('div');
	newdiv.setAttribute("id", this.id+'Div');
	
	newdiv.style.background = this.definitionBckgColor;
	newdiv.style.border = 'solid '+this.definitionBorderColor+' 1px';
	newdiv.style.fontFamily = this.font.family;
	newdiv.style.fontSize = getFontSize(this.font.size, "px");
	newdiv.style.color = this.fontColor;
	newdiv.style.position = 'absolute';
	newdiv.style.visibility = 'hidden';
	
	document.body.appendChild(newdiv);	
};


























