/**
 * @author Coolmen
 * @version 20100313
 */


/**
 * @class Ballon
 * @param {} el
 * @param {} options
 */
function Ballon ( el, options ) {
	
	var show_speed = 'fast';
	var hide_speed = 'slow';
	
	var ballon		= $(el);
	var container	= ballon.children('span');
	var controller	= ballon.prev('a');

	/**
	 * Статус баллон:
	 *		true	-- открыт
	 *		false	-- закрыт
	 * @type bullean 
	 */
	var status		= null;

	/**
	 * создание баллона
	 */
	this.init = function () {
		status		= ! ballon.hasClass('hidden');
		controller.hover( this.show, this.hide );
	};
	
	/**
	 * Показываем баллон
	 * @return {Boolean}
	 */
	this.show = function () {
		// Если баллон спрятал показываем его
		if ( !status ) {
			hide_all();
			status = true;
			ballon.removeClass('hidden');
			container.stop().fadeTo(0,1).hide().fadeIn( show_speed,
				function() {
					container.show();
				});
		}
		return false;
	};

	/**
	 * Прячим баллон
	 * @return {Boolean}
	 */
	this.hide = function () {
		if ( status ) {
			status = false;
			container.stop().fadeOut( hide_speed,
				function() {
					ballon.addClass('hidden');
				});
		}
		return false;
	}

	/**
	 * Прячим все открытые баллоны
	 */
	function hide_all () {
		$('.ballon').each( function () {
				this.ballon.hide();
			});
	}
	
	this.init();
}


/**
 * Морда jQuery
 * @param {} options
 */
jQuery.fn.ballons = function( options ) {
	this.each( function () {
			this.ballon = new Ballon( this );
		});
};


$(document).ready( function() {
	// Поднимаем баллоны
	$('#model-link .ballon').ballons();
})




