function perepass(input_tmp, input_real){
	$(input_real).css('display', 'none');
	$(input_tmp).focusin(function(){
		$(input_tmp).css('display','none');
		$(input_real).show(function(){
			$(input_real).focus();
		});
	});	
	$(input_real).focusout(function(){
		if ('' == $(input_real).val()){
			$(input_real).css('display','none');
			$(input_tmp).css('display', 'inline');
		}
	});

}
function peremultiple(form){
	$('.multiple', form).each(function(){
		var theblock = this;
		$('.mult', this).each(function(index){
			if(index>0){
				$(this).hide();
				$('#footer').hide().show();
			}
		});
		$('.multiply span', this).click(function(){
			var added = false;
			var last_visible = true;
			$('.mult', theblock).each(function(index){
				if (!added && $(this).is(':hidden')){
					$(this).show();
					added = true;
				}
				last_visible = $(this).is(':visible');
			});
			if(last_visible){
				$(this).hide();
			}
		});
		
	});
}

$(function(){
	$('select').customSelect({scrollBarWidth:14,boxHeight:200,boxOptions:{arrowSize:17,boxSize:200,sliderSize:61}});
//	$('select').customSelect({scrollBarWidth:12,boxHeight:100,boxOptions:{arrowSize:9,boxSize:100,sliderSize:20}});
	perepass('#false_search', '#real_search');
	$('.drug_content_item').hide();
	
	$('.drug_menu ul li').each(function(){
		var theli = this;
		if(!$(theli).hasClass('_blank')){
			$('a', this).click(function(){
				$('.drug_menu ul li').removeClass('active');
				$('.drug_content_item').hide();
				$($(this).attr('href')).show();
				$(theli).addClass('active');
				$(this).blur();
				return false;
			});
		}
		
	});
	$('.drug_menu ul li a').first().click();
	peremultiple($('.supervision'));
});



function disableAddToCart(elementId, mode, text)
{
	var	element = document.getElementById(elementId);
	if (!element)
		return;
	
	if (mode == "detail")
		$(element).html("<span>" + text + "</span>").toggleClass("disabled")
			.removeAttr("href").unbind('click').css("cursor", "default");
	else if (mode == "list")
		$(element).html(text).removeClass("catalog-item-buy").addClass("catalog-item-in-the-cart")
			.unbind('click').css("cursor", "default");
}

function addToCart(element, mode, text)
{
	if (!element || !element.href)
		return;

	var button = $(element);
	if (mode == "detail")
		button.toggleClass("disabled").unbind('click').css("cursor", "default");
	else if (mode == "list")
		button.removeClass("catalog-item-buy").addClass("catalog-item-in-the-cart").unbind('click').css("cursor", "default");

	$.get(
		element.href + "&ajax_buy=1",
		$.proxy(
			function(data) {

				if (this.mode == "detail")
					this.button.removeAttr("href").html("<span>" + text + "</span>");
				else if (this.mode == "list")
					this.button.removeAttr("href").html(text);


				var hoverClassName = "";
				var wrapper = null;
				if (this.mode == "detail")
				{
					hoverClassName = "catalog-detail-hover";
					wrapper = this.button.parents("div.catalog-detail");
				}
				else if (this.mode == "list")
				{
					hoverClassName = "catalog-item-hover";
					wrapper = this.button.parents("div.catalog-item");
				}

				wrapper.unbind("mouseover").unbind("mouseout").removeClass(hoverClassName);


			}, { "button": button, "mode": mode}
		)
	);

	return false;
}

