$(function(){

	var ff = $;
	ff('html').addClass('js')

/* Input labels
------------------------------ */

	var wrap_label = ff('.wrap_label > input');
	wrap_label.focus(function ()
	{
		ff(this)
			.prev('label')
			.hide()
	}) // End of focus
	wrap_label.blur(function ()
	{
		if ( ff(this).val() == '' )
		{
			ff(this)
				.prev('label')
				.show()
		}
	}) // End of blur

/* Dropdown menu @ sidebar
------------------------------ */

	ff('.bl_sidebar > .list_catalogue > .lvl_0.active > ul').show()
	ff('.bl_sidebar ul.list_catalogue ul.lvl_1 li.active ul.lvl_2').show()

	// submenu lvl_1 collapse toggle
	var lvl_1 = ff('.bl_sidebar > .list_catalogue > .lvl_0.dropdown > h3 > a');
	lvl_1.click(function()
	{
		ff(this)
			.parent()
			.parent()
			.toggleClass('active')
			.find('ul.lvl_1')
			.slideToggle()
		return false;
	}) // End of click

	// submenu lvl_2 collapse
	var lvl_2 = ff('.bl_sidebar .lvl_1 > .list_collapse');
	lvl_2.click(function()
	{
		ff(this)
			.parent()
			.toggleClass('active')
			.find('.lvl_2')
			.slideToggle()
		return false;
	}) // End of click

/* Sort form submit @ compare pg
------------------------------ */

	// sort
	var form_sort = ff('#form_sort');
	var inp_sort = ff('#inp_sort');
	var me = ff('#form_sort > h4.sort > a');

	me.click(function ()
	{
		ff('#inp_by').remove()

		if ( ff(this).parent().is('.down') )
		{
			inp_sort.attr('value', 'down');
		} else {
			inp_sort.attr('value', 'up');
		}
		// by price
		if ( ff(this).is('#price') )
		{
//			alert('price!')
			form_sort
				.append('<input id="inp_by" name="by" type="hidden" value="price"/>')
				.submit()
		} else if ( ff(this).is('#producer') )
		// by producer
		{
//			alert('producer!')
			form_sort
				.append('<input id="inp_by" name="by" type="hidden" value="producer"/>')
				.submit()
		} // end if
		return false;
	}) // End of click
	
	form_sort.find('select').change(function ()
	{
		form_sort.submit()
	}) // End of change

/* Hover
								*/

});
