(function($) {
	
	/**********************************************************************************/
	$.fn.inputDefaults = function(options) {
		// дефолтные значения
		var defaults = {
 			cl: 'inactive', // имя класса для неактивного состояния
 			text: this.val()   // значение берется из самого инпута
  		}, 	opts = $.extend(defaults, options);	
  		
  		this.addClass(opts['cl']); 	// добавляем класс к инпуту
  		this.val(opts['text']);			// ставим значение по умолчанию
  		
  		// обрабатываем события фокуса на поле
  		this.focus(function() {
  			if($(this).val() == opts['text']) $(this).val(''); // обнуляем его, если надо
  			$(this).removeClass(opts['cl']); // убираем класс
  		});
  		
  		// теперь очередь блюра
  		this.blur(function() {
  			if($(this).val() == '') {
  				$(this).val(opts['text']); 			// возвращаем значение
  				$(this).addClass(opts['cl']); 	// и класс, если надо
  			}
  		});
	};
	/**********************************************************************************/

	
})(jQuery);

$(function(){
	/* Code highlighter */
	ChiliBook.recipeFolder = "/js/chili/";
	ChiliBook.automatic = true;
	ChiliBook.lineNumbers = true;
	
	/* Textile help in comments */
	var $TextileHelp = $('#TextileHelp');
	$('.js').removeClass('js');
	$('.no-js').css('display', 'none');
	if($TextileHelp.length){
		$TextileHelp.hide();
		$('label[for="message"] a.action').click(
			function(){
				$TextileHelp.slideToggle("slow");
				return false;
			}
		);
	}
	
	/* Autogrow for comments */
	$('.txpCommentInputMessage, #zemMessage').autogrow({
		minHeight: 85,
		maxHeight: 400,
		lineHeight: 20
	});
	
	/* For IE */
	$('.text-input input, .text-input textarea, .text-input select')
		.focus(function(){$(this).parent().addClass('focus')})
		.blur(function(){$(this).parent().removeClass('focus')});
	
	/* Search */	
	$('#Search').inputDefaults({
		cl: 'inactive',
		text: 'Что ищем?'
	});	
	
	/* PrettyPhoto */
	$("a[rel^='pp']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.35, /* Value betwee 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
		callback: function(){}
	});
	
	/* Table color */
	$("tr:odd").addClass('odd');
	$("td").parent().hover(
		function(){$(this).addClass('highlighted');},
		function(){$(this).removeClass('highlighted');}
	);
	
	/* ToolTip */
	$('*[title]').jTT({
		template:	'<div class="ttip">'+
					'<div class="tt-container">' +
					'<h1>%header%</h1>' +
					'<p>%message%</p>' +
					'</div></div>'
	});
	
});