/**
 * Fotolia categories scripts
 *
 * @copyright (c) 2004-2008, SWsoft
 */
function InitCategory(categoryType, categoryId, categoryTitle, parentCategoryId) {
	var categoryControl = $('Fotolia_' + categoryType + '_category_' + categoryId);
	var parentControl = (parentCategoryId) ? $('Fotolia_' + categoryType + '_category_' + parentCategoryId) : null;

	var parentObject = (parentControl) ? parentControl.categoryObject : null;
	var categoryObject = new FotoliaCategory(categoryType, categoryId, categoryTitle, parentObject);

	categoryControl.categoryObject = categoryObject;
	if ('A' == categoryControl.tagName) {
		Event.observe(categoryControl, 'click', function() { categoryObject.select(); });
	}
	return categoryObject;
}

var FotoliaCategory = Class.create();
FotoliaCategory.prototype = {

	/**
	 * Category type
	 *
	 * @var string
	 * @access private
	 */
	_type: null,

	/**
	 * Category id
	 *
	 * @var string
	 * @access private
	 */
	_id: null,

	/**
	 * Category title
	 *
	 * @var string
	 * @access private
	 */
	_title: null,

	/**
	 * Parent category object
	 *
	 * @var FotoliaCategory
	 * @access private
	 */
	_parentObject: null,

	/**
	 * Object constructor
	 *
	 * @access public
	 * @param string
	 * @param string
	 * @param FotoliaCategory
	 * @return void
	 */
	initialize: function(type, id, title, parentObject) {
		this._type = type;
		this._id = id;
		this._title = title;
		this._parentObject = parentObject;
	},

	/**
	 * Selects current category
	 *
	 * @access public
	 * @return void
	 */
	select: function() {
		self.parent.fotoliaSearchFormManager.selectCategory(this);
	},

	/**
	 * Returns category type
	 *
	 * @access public
	 * @return string
	 */
	getType: function() {
		return this._type;
	},

	/**
	 * Returns category id
	 *
	 * @access public
	 * @return string
	 */
	getId: function() {
		return this._id;
	},

	/**
	 * Returns path to the current category
	 *
	 * @access public
	 * @return string
	 */
	getPath: function() {
		var result = (this._parentObject) ? this._parentObject.getPath() : '';
		if ('' != result) {
			result += '/';
		}
		result += encodeURIComponent(this._id);
		result += ' ' + encodeURIComponent(this._title);

		return result;
	}
}