/**
 * класс создаёт контейнер для контентов модального
 * инлайнового окошка
 * @param {jQuery} items набор элементов, которые и будут нашим контентом
 * @param {Object} handlers хэш обработчиков показа контента ( [номер] -> function(){} )
 */
function modalContents( items, handlers, hide )
{
	this.items = items
	this.ids = {}

	var self = this
	this.items.each(
		function ()
		{
			var currentItem = $(this)
			self.ids[currentItem.attr('id')] = currentItem
		}
	)

	this.currentItem = null
	this.handlers = handlers

	this.length = items.length

	/**
	 * скрывает контейнер контента с индексом index
	 * @param {jQuery} item контейнер контента
	 */
	this.hide =
		function ( item )
		{
			item.hide()
		}
	/**
	 * показывает контейнер контента с индексом index
	 * @param {jQuery} item контейнер контента
	 */
	this.show =
		function ( item )
		{
			item.show()
		}

	/**
	 * показываем элемент
	 * @param {string} index идентификатор элемента для показа
	 */
	this.select =
		function ( index )
		{
			if ( this.currentItem )
			{
				this.hide( this.currentItem )
			}

			this.currentItem = this.ids[index]
			if ( this.handlers[index] )
			{
				this.handlers[index]()
			}

			this.show( this.currentItem )
		}

	/**
	 * скрываем все элементыы
	 */
	this.hideAll =
		function ()
		{
			var currentItem
			var currentHandler

			for( var currentIndex = 0, length = this.length ; currentIndex < length ; currentIndex++ )
			{
				currentItem = this.items.eq(currentIndex)
				this.hide( currentItem )
			}

		}

	/**
	 * переводим контейнер в начальное состояние
	 * (скрываем все элементы, кроме первого, а первый показываем)
	 */
	this.reset =
		function ()
		{
			this.hideAll()
			this.select( this.items.eq(0).attr('id') )
		}

	if ( typeof hide == 'undefined' )
	{
		this.reset()
	}
	else
	{
		this.hideAll()
	}
}