/* ::: constructor ::: */
function Keyword( propertyList )
{
	// instance variable
	this.propertyList;
	this.selectedWordProperty;

	// instance method
	this.init;
	this.setPropertyList;
	this.getSelectedWord;
	this.setSelectedWordProperty;
	this.setKeywordStyle;
	this.getStyleString;

	// initialize
	this.init( propertyList );
}


/* :: instance method - init :: */
Keyword.prototype.init = function( propertyList )
{
	this.setPropertyList( propertyList );
	this.setSelectedWordProperty();
}


/* :: instance method - setPropertyList :: */
Keyword.prototype.setPropertyList = function( propertyList )
{
	this.propertyList = propertyList;
}


/* :: instance method - getSelectedWord :: */
Keyword.prototype.getSelectedWord = function()
{
	var parameter  = ( location.search ).substr( 1 );
	var parameters = parameter.split( '&' );

	for( var i = 0; i < this.propertyList.length; i++ )
	{
		for( var j = 0; j < parameters.length; j++ )
		{
			if( parameters[j].indexOf( this.propertyList[i].name ) != -1 )
			{
				if( parameters[j].split( '=' )[1] == this.propertyList[i].value )
				{
					return this.propertyList[i];
				}
			}
		}	
	}
}


/* :: instance method - setSelectedWordProperty :: */
Keyword.prototype.setSelectedWordProperty = function()
{
	this.selectedWordProperty = this.getSelectedWord() ? this.getSelectedWord() : '';
}


/* :: instance method - setKeywordStyle :: */
Keyword.prototype.setKeywordStyle = function()
{
	if( this.selectedWordProperty != '' )
	{
		var selector      = "." + ( this.selectedWordProperty.name ).toString() + ( this.selectedWordProperty.value ).toString();
		var styleString01 = '<style type="text/css" media="screen,print">' + selector + '{';
		var styleString02 = this.getStyleString( this.selectedWordProperty.styles );
		var styleString03 = '}' + '</style>';
		var styleElement  = styleString01 + styleString02 + styleString03;
		document.write( styleElement );
	}
}


/* :: instance method - getStyleString :: */
Keyword.prototype.getStyleString = function( styles )
{
	var styleString = new String();

	for( var i = 0; i < styles.length; i++ )
	{
		styleString += styles[i].property + ':' + styles[i].value + ';';
	}

	return styleString;
}



/* ::: cofiguration ::: */
var keywordPropertys =
[
	{
		name : 'key',
		value : '1',
		styles :
		[
			{ property : 'background-color', value : '#ace1ed' }
		]
	},
	{
		name : 'key',
		value : '2',
		styles :
		[
			{ property : 'background-color', value : '#f8d59d' }
		]
	},
	{
		name : 'key',
		value : '3',
		styles :
		[
			{ property : 'background-color', value : '#dcbaf6' }
		]
	}
];


var staffVoice = new Keyword( keywordPropertys );
staffVoice.setKeywordStyle();

