$(function() {



	var sublevels = $('.catalogue .sub');

	$('.catalogue .mlevel').click(function() {

		var s = $(this).next('.sub');

		if (s.length > 0) {

			sublevels.not(s).slideUp(400).parent('LI').removeClass('active');

			s.slideDown(400).parent('LI').addClass('active');

			return!1;

		}

	});

    $('.catalogue .slevel').click(function() {

    	var dl = $(this).next('DL');

    	if (dl.length > 0) {

    		dl.parents('DL').find('DL').slideUp(200).parent('DD').removeClass('active');

    		dl.slideDown(200).parent('DD').addClass('active');

			return!1;

		}

	});

	$('.catalogue DD.active DL').slideDown(100);







	$('SELECT').each(function() {

		var s = $(this).hide(), id = s.attr('id'), timer = null;

		s.removeAttr('id');

		var i = $('<div class="ls-text ls-select"><input type="text" id="' + id +

			'" readonly="true" value="' + s.find(':selected').text() +

			'" /><b class="tl"/><b class="tr"/><b class="bl"/><b class="br"/></div>').insertAfter(s);

        var pl = $('<div class="ls-select-list"/>').appendTo('body').hide().hover(function() {

           	clearTimeout(timer);

       	}, function() {

      		timer = setTimeout(function() {

         		pl.hide();

  	       	}, 300);

      	});

        var li = '';

		var option = s.find('OPTION').each(function() {

			var o = $(this);

			li += '<li><a href="#"' + (o.attr('selected') ? ' class="active"' : '') + '>' + o.text() + '</a></li>';

		});

		pl.append('<ul>' + li + '</ul>').find('A').click(function() {

        	pl.find('A').removeClass('active');

            var a = $(this).addClass('active');

            i.find('INPUT').val(a.text());

            option.eq(a.parent().index()).attr('selected', true);

            s.triggerHandler('change');

            pl.hide();

            return!1;

		});

        $('<a href="#"></a>').appendTo(i).parent().click(function() {

            if (pl.css('display') == 'none') {

              	var o = i.offset();

              	pl.css({ 'top': o.top + i.height()+9, 'left': o.left }).width(i.width()+31).show();

        	}

            else pl.hide();

            return!1;

		}).find('a').mouseout(function() {

			timer = setTimeout(function() {

				pl.hide();

			}, 100);

		});

        i.find('INPUT').hover(function() {

           	clearTimeout(timer);

        }, function() {

           	timer = setTimeout(function() {

        		pl.hide();

        	}, 300);

		});

	});



	$('A.thumb').click(function() {

		var s = $(this).attr('href'), b = $('#bigImg').attr('src', '../images/px.gif');

		setTimeout(function() { b.attr('src', s); }, 10);

		return!1;

	});



    $('.ico.help').each(function() {

    	var a = $(this), timer = null,

    		tt = $('<div class="tool-tip"/>').appendTo('body').text(a.attr('title')).hover(function() {

            	clearTimeout(timer);

    		}, function() {

	           	timer = setTimeout(function() {

    	    		tt.hide();

        		}, 100);

    		});

    	a.removeAttr('title').hover(function() {

           	var o = a.offset();

           	tt.css({ 'top': o.top + 12, 'left': o.left + 12 }).show();

	   	}, function() {

	       	timer = setTimeout(function() {

    	   		tt.hide();

        	}, 100);

    	});







    });

	

	jQuery('.dialog-trigger').click(function() {

		var h = jQuery('html').height(), w = jQuery('html').width();

		var overlay = jQuery('#overlay');

		if (overlay.length == 0) overlay = jQuery('<div id="overlay" class="hidden"/>').appendTo('body');

		overlay.height(h).width(w).show();

		var form = jQuery(jQuery(this).attr('rel'));

		form.css({ top: parseInt((h - form.outerHeight())/2)+'px',

				   left: parseInt((w - form.outerWidth())/2)+'px' }).animate({ opacity: 'show' }, 400);

		var close = form.find('.close-trigger').click(function() {

			form.animate({ opacity: 'hide' }, 200);

			overlay.hide();

			return!1;

		});

		form.find('.submit').click(function() {

			close.trigger('click');

		});

		return!1;

	});



});



function my_set_count_mod(id,cnt) {

  set_count_mod(id,cnt); //вызываем стандартную

  $('#recount').trigger('click'); // эмулируем нажатие кнопки

}




