$(document).ready(function(){

	var countElements = $("#c1 li").size();
	$("ul#c1").css('width', (countElements * 72) + 'px'); // определяем цирину враппера

	//Предзагрузка изображений в конструкторе	
		$("#cDiv1").preloadify({ imagedelay:500 });
		$("#cDiv2").preloadify({ imagedelay:500 });
		$("#image1").preloadify({ imagedelay:500 });
		$("#image2").preloadify({ imagedelay:500 });

		
	//Список №1	
	$('ul#c1 li').click(function() {	
		
		$("ul#c1 li").removeClass("active");
		$(this).addClass("active");
				 
		var 
		inp_name = $(this).children('.inp_name').val();	
		inp_price = $(this).children('.inp_price').val();
		inp_type = $(this).children('.inp_type').val();
		
		c1_id = this.id;
		c2_id = $(".c2_start").val();
			
		$("p#name").html("Модель:<strong> " + inp_name + "</strong>" ); 		
		$("p#price").html("Цена:<strong> " + inp_price + "</strong>" ); 		
		$("p#type").html("Конструкция:<strong> " + inp_type + "</strong>" ); 
		
		$(".c1_start").val(c1_id);		
		$("div#image1").html("<a href='/userfiles/images/doors/div1/d1__" + c1_id + "-" + c2_id + ".jpg'><img src='/files/php/applications/resize.php?img_path=/userfiles/images/doors/div1/d1__" + c1_id + "-" + c2_id + ".jpg&height=269' width='148' height='269' /></a>");
		$("div#image2").html("<a href='/userfiles/images/doors/div2/d2__" + c1_id + "-c2_1.jpg'><img src='/files/php/applications/resize.php?img_path=/userfiles/images/doors/div2/d2__" + c1_id + "-c2_1.jpg&height=289' width='470' height='289' /></a>");
		
		$("div#image1").preloadify({ imagedelay:500 });
		$("div#image2").preloadify({ imagedelay:500 });
		
		$("#image1 a, #image2 a").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
		}).fancyOver();
		
	});
	
	//Список №2	
	$('ul#c2 li').click(function() {	
		
		$("ul#c2 li").removeClass("active");
		$(this).addClass("active");
		
		var 
		inp_color = $(this).children('.inp_color').val();		
		c1_id = $(".c1_start").val();
		c2_id = this.id;// сейчас не меняем второй параметр
		//c2_id = $(".c2_start").val();
		
		$("p#color").html("Цвет:<strong> " + inp_color + "</strong>" ); 
		
		$(".c2_start").val(c2_id);		
		$("div#image1").html("<a href='/userfiles/images/doors/div1/d1__" + c1_id + "-" + c2_id + ".jpg'><img src='/files/php/applications/resize.php?img_path=/userfiles/images/doors/div1/d1__" + c1_id + "-" + c2_id + ".jpg&height=269' width='148' height='269' /></a>"); 
		/*
		$("div#image2").html("<a href='/userfiles/images/doors/div2/d2__" + c1_id + "-" + c2_id + "__big.jpg'><img src='/userfiles/images/doors/div2/d2__" + c1_id + "-" + c2_id + ".jpg' /></a>");  не обрабатываем второе изображение при выборе цвета
		*/
		
		$("div#image1").preloadify({ imagedelay:500 });
		//$("div#image2").preloadify({ imagedelay:500 }); не обрабатываем второе изображение при выборе цвета
		
		$("#image1 a, #image2 a").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
		}).fancyOver();
		
	});
	
	
	/*
    $("select").change(function () {
          var str = "";
          $("select option:selected").each(function () {
                str = $(this).val();
              });
          $("#c1 li").hide();
          $("li.type_" + str).show();
		  
          $("#cDiv1").preloadify({ imagedelay:500 });
          $("#cDiv2").preloadify({ imagedelay:500 });
          $("#image1").preloadify({ imagedelay:500 });
          $("#image2").preloadify({ imagedelay:500 });
		  
        })
        .trigger('change');
	*/	
	
});


