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

componentGrammar = function(name)
{
	this.componentElement = componentElement;
	this.componentElement(name);
  
  	if (arguments[1]) {
	} else {
		this.text = this.addChild(new __componentText(null));
		this.image = this.addChild(new __componentImage(null));
	};
};

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

componentGrammar.prototype.onBaseCreate = function(obj)
{
	this.resourcesURL = resourcesURL;
	this.resourcesStatus = "online";
	if (this.execution) {
		if (PageInterface.GetValue("state") != psDesigning && lms && lms.name != "lmsOffline") {
			this.resourcesStatus = lms.resourcesStatus();
			if (this.disableOnlineOfflineMix) this.resourcesURL = resourcesURL;
			else this.resourcesURL = lms.resourcesURL();
		}
		
	    this.resourcesURL = unescape(this.resourcesURL);
		
		this.imagesNameArr = [ this.imageSrc ];
		this.getPreloadImagesArr();
	}
};

componentGrammar.prototype.onCreate = function()
{
	if (!this.execution) {
		this.text.p_checkMarkers = this.p_checkMarkers;
		this.text.p_checkPNG = this.p_checkPNG;
		this.text.pngFix = this.pngFix;
		
		this.image.p_checkMarkers = this.p_checkMarkers;
		this.image.p_checkPNG = this.p_checkPNG;
		this.image.pngFix = this.pngFix;
	}
	this.captureMouseEvents();
};

componentGrammar.prototype.onPaint = function(obj)
{
	if (this.execution) {
		document.getElementById(this.id + "_image_contentObj").src = this.resourcesURL + this.imageSrc;
	}else{
		this.image.x = this.w - this.image.w - 2;
		this.image.y = 0;
		this.text.x = 0;
		this.text.y = 0;
		this.text.w = this.w - this.image.w - 2;
		this.text.h = this.h;
	}
};

componentGrammar.prototype.componentGrammarBaseSetSizeScaledElement = componentGrammar.prototype.setSizeScaledElement;
componentGrammar.prototype.setSizeScaledElement = function (x, y, w, h)
{
	if(this.execution){
		document.getElementById(this.id + "_textDIV").style.width = w-(this.imageW-4);
		document.getElementById(this.id + "_textDIV").style.height = h;
		document.getElementById(this.id + "_textDIV").style.clip = 'rect(0px '+eval(w-(this.imageW-2))+' '+h+' 0px)';	
		document.getElementById(this.id + "_imageDIV").style.left = w-(this.imageW);		
	};
	this.componentGrammarBaseSetSizeScaledElement(x, y, w, h);
};

componentGrammar.prototype.eventClick = function(e)
{
	if (typeof(this.keyword) != "undefined" && this.keyword != "" && this.keyword != "-" ) {
		openLexicon('../grammar/', this.keyword);
	}else {
		showMessage('Please add a dictionary word in component properties.');
	}
	return false;
};

componentGrammar.prototype.isReady = function()
{
	if (this.execution) {
		this.isLoaded = preloadImage(this, "_1");
		return this.isLoaded;	
	}else{
		return(this.image.isReady());
	};
};

