/**
 * Word prototype, rect prototype
 */

//One word
var wordPrototype = function (type) {
	
//Constructor
	this.sortPosition;
	this.id;
	this.realId;
	this.word;
	this.linkWeight;
	this.icon;
	this.entries	= new Array();
	
	this.x			= -1;
	this.y			= -1;
	this.width;
	this.heigth;
	this.size;
	this.font		= new String('Arial');
	this.type		= type; //`normal` or `query`
	
	this.color;
	this.colorWordCenter;
	
	this.onClick;
	this.onMouseOver;
	this.onMouseOut;
	
//Public methods

	//Import object from xml
	this.importFromXml = function(xml){
	
		this.sortPosition	= $(xml).attr('sortPosition');
		this.id				= $('id', $(xml)).text() + this.sortPosition;
		this.realId			= $('id', $(xml)).text();
		this.word			= $('word', $(xml)).text();
		this.linkWeight		= $('linkWeight', $(xml)).text();
		this.icon			= $('icon', $(xml)).text();
		
		if (this.type=='normal') {
			this.onClick = 'addWord(\''+this.id+'\')'
		} else {
			this.onClick = 'deleteWord(\''+this.id+'\')'
		};
		
		this.onMouseOver = 'showEntries(\''+this.id+'\')';
		this.onMouseOut = 'hideEntries()';
		
		//Import entries
		this.entries		= new Array();
		var entries = this.entries;
		$('entry', $(xml)).each(function() {
			var newEntry = new entriePrototype();
			newEntry.importFromXml(this);
			entries[ entries.length ] = newEntry;
		});
	};
	
	//Return first query entrie
	this.getFirstQueryEntry = function() {
		for (var i=0; i<this.entries.length; i++) {
			if (this.entries[i].field=="query") {
				return this.entries[i];
			};
		};
	};
	
	//Return true if keyword is set expression
	this.isSetExpression = function(){
		
		if (this.word.indexOf(' ') == -1) {
			return false;
		}
		else {
			return true;
		};

	};
};
