/*

*/
(function($) {

jQuery(document).ready(function(){

	$('.prod-cat').hover(
		function()
		{
			$(this).addClass('budapeht');	
		},
		function()
		{
			$(this).removeClass('budapeht');
		}
	)
	
})

	$(document).ready(function() {
		$("#tmenu a").each(function(j) {
			$(this).css("z-index",100-j);
		});

			$('#btn_information').click(function(){
				if ($(this).attr('haha') == 'N')
				{
					$('#div_information').slideDown();
					$(this).attr('haha','Y');
				}
				else
				{
					$('#div_information').slideUp();
					$(this).attr('haha','N');
				}
				return false;			
			});
		$('#active_sectiond').live('click',function(){
			
			
			var text = '<a href="'+$(this).attr('haha')+'"><img src="/bitrix/themes/.default/images/signplus.gif"  /></a> <a href="'+$(this).attr('haha')+'">'+$(this).parent().find('b:first').text()+'</a>';
			$(this).parent().html(text);
			//$(this).removeClass('active');
			return false;		
		});

		$('#active_sectiond2').live('click',function(){			
			var text = '<a href="'+$(this).attr('haha')+'"><img src="/bitrix/themes/.default/images/signplus.gif"  /></a> <a style="font-size:80%" href="'+$(this).attr('haha')+'">'+$(this).parent().find('b:first').text()+'</a>';
			$(this).parent().html(text);
			//$(this).removeClass('active');
			return false;		
		});
		/*$("#scmenu a").click(function() {
			$("#scmenu a.active").removeClass("active");
			$(this).addClass("active");
			$("div.active-box").removeClass("active-box");
			$("div."+$(this).attr("id")).addClass("active-box");
			return false;
		});*/
		
		scrollMenu();
		lines();
		bl1height();
//		prodheight();
	});

	$(window).resize(function() {
		lines();
//		scrollMenu();
		bl1height();
//		prodheight();
	});

	function bl1height() {
	  var hh1 = "";
	  var hh2 = "";
		$("div.bl1").each(function() {

		  if (hh2 == "") {
			  hh2 = $(this).height();
			  hh1 = hh2;
			}

			newh = $(this).height();

	  	if (hh1 < newh) {
	  		hh1 = newh;
	  	} else {
	  		hh1 = hh2;
	  	}

		});
		$("div.line_V").height(hh1);
	}
	
	function prodheight() {
	  var hh1n = "";
	  var hh2n = "";
		$("div.prod-title").each(function() {

		  if (hh2n == "") {
			  hh2n = $(this).height();
			  hh1n = hh2n;
			}

			newhn = $(this).height();

	  	if (hh1n < newhn) {
	  		hh1n = newhn;
	  	} else {
	  		hh1n = hh2n;
	  	}

		});
		$("div.prod-title").height(hh1n);
	}
	
	function lines() {
		var htmlWidth = $("body").width();
		var contWidth = $("#container").width();
		var leftLine = (htmlWidth - contWidth)/2 + 257;
		var pateWidth = $("#page_text").width();
		var rc = Math.round(pateWidth * 0.24);
//		$("#number").text(htmlWidth);
		$("html").css("background-position", leftLine + "px top")
		$("#container").css("background-position", (contWidth - rc) + "px top")
	}

	function scrollMenu() {
		var div = $('div.sc_menu'),
			ul = $('ul.sc_menu'),
			ulPadding = 0;

		//Get menu width
		var divWidth = div.width();

		//Remove scrollbars
		div.css({overflow: 'hidden'});

		//Find last image container
		var lastLi = ul.find('li:last-child');

		//When user move mouse over menu
		div.mousemove(function(e){
			//As images are loaded ul width increases,
			//so we recalculate it each time
			var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
			var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
			//var left = (e.pageX – div.offset().left) * ( (ulWidth-divWidth) / (divWidth));
			div.scrollLeft(left);
		});
	}

})(jQuery);

// Добавление в корзину
jQuery(document).ready( function(){

	jQuery('.button_basket').live('click', function() {
	
		quantity = jQuery('#' + jQuery(this).attr('input_id')).val();
	
		jQuery('.korz_inner').html('<div align="center" style="margin-top: 50px;"><img src="/AJAX/ajax-loader.gif"></div>');
		
		jQuery.ajax({
		      url: "/AJAX/add_basket.php",
		      type: "POST",
		      data: "ID=" + jQuery(this).attr('item_id') + "&QUANTITY=" + quantity,
		      timeout: 3000,
		      beforeSend: function(){
			//$("#posts").text("Загрузка...");
		      },
		      success: function(data){
			jQuery(".korz_inner").html(data);
			jQuery('#cart-message span').stop().hide().show().css('opacity' , 1).fadeOut(3000);
		      },
		      error: function(xhr, status){
			//jQuery(".korz_inner").html("<span>Ошибка добавления в корзину</span>");
		      }
		});
		
		return false;
		
	});
	
	jQuery('.zoomi').live("mouseover", function() {

		jQuery(this).parent().parent().children('.zoomi2').fadeIn('1500');
		
	});
	
	jQuery('.zoomi2').live("mouseout", function() {
		
		jQuery(this).fadeOut('1500');
		
	});
	
});

function ajax_element(id, iblock_id, section_id)
{
	//var old_data = jQuery("#main_catalog").html();
	jQuery("#main_catalog").html('<div align="center" style="margin-top: 100px;"><img src="/AJAX/ajax-loader.gif"></div>');
	jQuery.ajax({
	      url: "/AJAX/detail.php",
	      type: "POST",
	      data: "IBLOCK_ID=" + iblock_id + "&SECTION_ID=" + section_id + "&ELEMENT_ID=" + id,
	      timeout: 3000,
	      beforeSend: function(){
		//$("#posts").text("Загрузка...");
	      },
	      success: function(data){
		jQuery("#main_catalog").html(data);
	      },
	      error: function(xhr, status){
		location.href = '/catalog/' + iblock_id + '/' + section_id + '/' + id + '/';
	      }
	});
	return false;
	    
}

