//Cufon.replace('h1.cufon', { fontFamily: 'HeliosExtLight' });
Cufon.replace('h1.cufon', { fontFamily: 'HeliosExtThin' });
Cufon.replace('h2.cufon', { fontFamily: 'HeliosExtThin' });
Cufon.replace('div.cufon', { fontFamily: 'HeliosExtThin' });

$(document).ready(function(){

function smartColumns() { //функция, подсчитывающая ширину колонок
  //сброс ширины строки до 100% после изменения размера экрана
  $("div.pr_list").css({ 'width' : "100%"});

  var colWrap = $("div.pr_list").width(); //определяем ширину строки
  var colNum = Math.floor(colWrap / 220); //определяем, сколько столбцов в 200px вместится в строку и округляем число до целого
  var colFixed = Math.floor(colWrap / colNum); //ширину строки делим на количество столбцов, округляем до целого числа, в результате получаем точную скорректированную ширину колонки

  $("div.pr_list").css({ 'width' : colWrap}); //ставим точную ширину строки в пикселях вместо использования % - это предотвратит возможные баги в разных браузерах при различных разрешениях экрана
  $("div.pr_list div.pr_item").css({ 'width' : colFixed}); //ставим точную ширину измененным столбцам

}

smartColumns(); //запускаем функцию после загрузки страницы

$(window).resize(function () { //запускаем функцию после каждого изменения размера экрана
  smartColumns();
});


function smartColumnsCatalog() { //функция, подсчитывающая ширину колонок
  //сброс ширины строки до 100% после изменения размера экрана
  $("div.catalog_list").css({ 'width' : "100%"});

  var colWrap = $("div.catalog_list").width(); //определяем ширину строки
  var colNum = Math.floor(colWrap / 220); //определяем, сколько столбцов в 200px вместится в строку и округляем число до целого
  var colFixed = Math.floor(colWrap / colNum); //ширину строки делим на количество столбцов, округляем до целого числа, в результате получаем точную скорректированную ширину колонки

  $("div.catalog_list").css({ 'width' : colWrap}); //ставим точную ширину строки в пикселях вместо использования % - это предотвратит возможные баги в разных браузерах при различных разрешениях экрана
  $("div.catalog_list div.catalog_item").css({ 'width' : colFixed}); //ставим точную ширину измененным столбцам
  $("div.tovar_block").css({ 'width' : colFixed - 20});
  $("div.tovar_block a.tovar_pic img").css({ 'width' : colFixed - 20});
}

smartColumnsCatalog(); //запускаем функцию после загрузки страницы

$(window).resize(function () { //запускаем функцию после каждого изменения размера экрана
  smartColumnsCatalog();
});

$(document).bind("ajaxComplete",function(){
  smartColumns();
  smartColumnsCatalog();
});

//close
$("a.select_link").live('click', function() {
	$(this).next("div").toggle("fast").show(); ;
	$(this).toggleClass("active");
	$(this).parent().hover(function() {  
         }, function(){  
             $('a.select_link').removeClass("active");
			 $(this).parent().find("div.delect_submenu_c").fadeOut('fast'); 
	}); 
});

//close2
$("a.dl").live('click', function() {
	$(this).next("div").slideToggle("fast");
	$(this).toggleClass("gal_act");
});

//close
$("a.close").live('click', function() {
	$(this).siblings("div").slideUp("fast");
});

$("div.index_banner_c div.tovar_block").hover(function() {
		$(this).children("div.t_info").fadeIn()
    }, function(){
		$(this).children("div.t_info").fadeOut('slow'); //When the mouse hovers out of the subnav, move it back up  
	}  
);

$("a.tl").live('click', function() {
	$(this).siblings("div").fadeOut();
    $(this).next("div.m_submenu_c").fadeIn('fast').show(); 
	$(this).addClass("active");
	$(this).parent().hover(function() {  
         }, function(){  
             $('a.tl').removeClass("active");
			 $(this).parent().find("div.m_submenu_c").fadeOut('fast'); 
	}); 
});

$("a.proizv_select").live('click', function() {
    $(this).next("div.proizv_select_block").fadeIn('fast').show(); 
	$(this).addClass("active");
	$(this).parent().hover(function() {  
         }, function(){  
             $('a.proizv_select').removeClass("active");
			 $(this).parent().find("div.proizv_select_block").fadeOut('fast'); 
	}); 
});

$("a#a1").click(function() {
	$("#m1").slideToggle();
	$("#m1").siblings("div").slideUp();
	$(this).parent().parent().find(".tm").removeClass("active");
	$(this).toggleClass("active");
});
$("a#a2").click(function() {
	$("#m2").slideToggle();
	$("#m2").siblings("div").slideUp();
	$(this).parent().parent().find(".tm").removeClass("active");
	$(this).toggleClass("active");
});
$("a#a3").click(function() {
	$("#m3").slideToggle();
	$("#m3").siblings("div").slideUp();
	$(this).parent().parent().find(".tm").removeClass("active");
	$(this).toggleClass("active");
});
$("a#a4").click(function() {
	$("#m4").slideToggle();
	$("#m4").siblings("div").slideUp();
	$(this).parent().parent().find(".tm").removeClass("active");
	$(this).toggleClass("active");
});
$("a#a5").click(function() {
	$("#m5").slideToggle();
	$("#m5").siblings("div").slideUp();
	$(this).parent().parent().find(".tm").removeClass("active");
	$(this).toggleClass("active");
});
$("a#a6").click(function() {
	$("#m6").slideToggle();
	$("#m6").siblings("div").slideUp();
	$(this).parent().parent().find(".tm").removeClass("active");
	$(this).toggleClass("active");
});

/*  CarouFredSel: an infinite, circular jQuery carousel.
02	    Configuration created by the "Configuration Robot"
03	    at caroufredsel.frebsite.nl
04	
05	$("dfgdg").carouFredSel({
06	    width: "variable",
07	    height: 420,
08	    items: {
09	        visible: "variable",
10	        width: 335,
11	        height: 420
12	    },
13	    scroll: {
14	        mousewheel: true,
15	        items: 1,
16	        fx: "cover",
17	        easing: "easeInQuad",
18	        duration: 500
19	    },
20	    auto: false,
21	    pagination: "#pager_container",
22	    next: {
23	        button: ".next_btn",
24	        key: "left"
25	    },
26	    prev: {
27	        button: ".prev_btn",
28	        key: "right"
29	    }
30	});
*/

// Fuild layout carousel

$(window).resize(function() {
	var newWidth = $(window).width();
	$('#makeMeScrollable').carouFredSel({
		width: newWidth,
		items: {
	        minimum: "4",
	        width: 300,
			height: 377
	    },
		scroll: {
			items: 1,
	        mousewheel: true,
		},
		auto: false,
		pagination: ".pager_container",
		next: {
	        button: ".next_btn",
	        key: "left"
	    },
	    prev: {
	        button: ".prev_btn",
	        key: "right"
	    }
	});
});
$(window).resize();


//Слайдер. Документация здесь: http://www.slidesjs.com/
$(function(){
	$('#slides').slides({
		preload: true,
		preloadImage: 'loading.gif',
		effect: 'slide, fade',
		randomize: true,
		play: 5000,
		hoverPause: true,
		crossfade: true,
		slideSpeed: 500		
	});
});

     $("a.tl_a").hover(function() { //When trigger is clicked...  
   
         $(this).parent().find("div.sub_menu").slideDown('fast').show(); //Drop down the subnav on click  
		 $(this).addClass("h_active");
         $(this).parent().hover(function() {  
         }, function(){  
             $('a.tl_a').removeClass("h_active");
			 $(this).parent().find("div.sub_menu").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up  
		 });  
         }
);

//faq

$(".faq_ans").addClass("hidden");
$(".q_link").click(function() {
	$(this).addClass("q_active");
	$(this).siblings("a").removeClass("q_active");
	$(this).siblings("div").slideUp(300);
	$(this).next("div").slideDown(500);
});

	
$("a.fancybox").fancybox({
	'titlePosition'	: 'over',
	'overlayOpacity' : 0.7,
	'overlayColor' : '#000'
});
$("a[rel='gal']").fancybox({
	'titlePosition'	: 'over',
	'overlayOpacity' : 0.7,
	'overlayColor' : '#000'
});

	$("#cbform").bind("submit", function() {

		if ($("#c1").val().length < 1) {
			document.getElementById('c1').style.borderColor = '#ff0000';
			return false;
		}
		if ($("#c2").val().length < 1) {
			document.getElementById('c2').style.borderColor = '#ff0000';
			return false;
		}

		$.fancybox.showActivity();

		$.ajax({
			type	: "POST",
			cache	: false,
			url		: "/css/inc/ajax/cb.php",
			data	: $(this).serializeArray(),
			success : function(data) {
				$.fancybox(data);
			}
		});
		
		return false;
	});

});


