
var popupShow=false;

$(window).load(function(){
	
	$('img.flash_banner').each(function(){
		if($(this).attr('alt')){
			var swf_path = $(this).attr('alt');
			var div_id = 'flash_banner_'+$(this).parent('a').attr('href');
			var img_width = $(this).width();
			var img_height = $(this).height();
			$(this).parent('a').parent('div').html('<span id="'+div_id+'"></span>');
			$('span#'+div_id).css('display', 'block');
			var version = deconcept.SWFObjectUtil.getPlayerVersion();
			if(version['major']>=8){
				so = new SWFObject(swf_path + "?rand="+(Math.random()*1000000), div_id+"__", img_width, img_height, "8.0.0", "#ffffff", true);
				so.addParam("salign", "lt");
				//so.addParam("allowScriptAccess", "sameDomain");
				so.addParam("menu", "false");
				so.addParam("wmode", "transparent");
				so.write(div_id);
			}
		}
	});
	
	$("#subscribeForm").each(function(){
		this.reset();						  
	});
	$("#fullSubscribleForm").each(function(){
		this.reset();						  
	});
	if($("#fullSubscribleForm").length)
		$("#fullSubscribleForm").ajaxForm(function(data) {
			if(data==1){
				$(".mainCont","#subscribeWin").fadeOut("fast");
				$(".thxBox","#subscribeWin").fadeIn("slow", function(){
					$(this).fadeOut(1000, function(){
						$("#subscribeWin").hide("slow", function(){
							$("#winBg").hide();								
						});
					});													
				});													  
			}else{
				$(".mainCont","#subscribeWin").fadeOut("fast");
				$(".nothxBox","#subscribeWin").fadeIn("slow", function(){
					$(this).fadeOut(1000, function(){
						$("#subscribeWin").hide("slow", function(){
							$(this).show();	
							$(".mainCont","#subscribeWin").fadeIn("fast");
						});
					});													
				});													  	
			}
		});
	
	$("#feedbackForm").each(function(){
		this.reset();						  
	});
	
	if($("#feedbackForm").length)
		$("#feedbackForm").ajaxForm(function(data) {
			if(data==1){
				$(".mainCont","#feedbackWin").fadeOut("fast");
				$(".thxBox","#feedbackWin").fadeIn("slow", function(){
					$(this).fadeOut(1000, function(){
						$("#feedbackWin").hide("slow", function(){
							$("#winBg").hide();								
						});
					});													
				});													  
			}else{
				$(".mainCont","#feedbackWin").fadeOut("fast");
				$(".nothxBox","#feedbackWin").fadeIn("slow", function(){
					$(this).fadeOut(1000, function(){
						$("#feedbackWin").hide("slow", function(){
							$(this).show();	
							$(".mainCont","#feedbackWin").fadeIn("fast");
						});
					});													
				});													  	
			}
		});
	
	$("#studyForm").each(function(){
		this.reset();						  
	});
	
	if($("#studyForm").length)
		$("#studyForm").ajaxForm(function(data) {
			if(data==1){
				$(".studyBoxForm","#studyWin").fadeOut("fast");
				$(".thxBox","#studyWin").fadeIn("slow", function(){
					$(this).fadeOut(1000, function(){
						$("#studyWin").hide("slow", function(){
							$("#winBg").hide();								
						});
					});													
				});			
			}else{
				$(".studyBoxForm","#studyWin").fadeOut("fast");
				$(".nothxBox","#studyWin").fadeIn("slow", function(){
					$(this).fadeOut(1000, function(){
						$("#studyWin").hide("slow", function(){
							$(this).show();	
							$(".studyBoxForm","#studyWin").fadeIn("fast");
						});
					});													
				});						
			}
		});
		
	$("#winBg").css("height", $("#bg").height()+"px");
	$("input.textField").each(function(){
		$(this).attr("val", $(this).val());
		$(this).focus(function(){
			if($(this).val()==$(this).attr("val"))
				$(this).val("");
		});
		$(this).blur(function(){
			if(!$(this).val())
				$(this).val($(this).attr("val"));
		});
	});
	$("textarea.textField").each(function(){
		$(this).attr("val", $(this).val());
		$(this).focus(function(){
			if($(this).val()==$(this).attr("val")){
				$(this).css("textAlign", "left");
				$(this).val("");
			}
		});
		$(this).blur(function(){
			if(!$(this).val()){
				$(this).css("textAlign", "center");
				$(this).val($(this).attr("val"));
			}
		});
	});
	
	$(".selectBox img").click(function(){
		if($("ul", $(this).parent()).css("display")=="none")
			$(this).parent().css("zIndex", "100");
		else
			$(this).parent().css("zIndex", "2");
		$("ul", $(this).parent()).slideToggle("fast");							  
	});
	$(".selectBox a").click(function(){
		$(this).parents("div:first").css("zIndex", "2");
		$(this).parents("ul:first").slideUp("fast");
		$("div",$(this).parents("div:first")).text($(this).text());
		$("input",$(this).parents("div:first")).val($(this).attr("href"));
		if($(this).parents(".selectBox").attr("id")=="select1"){
			$("#selBox2").show();
			$("li", "#select2").hide();
			$("li.sel2_"+$(this).attr("href"), "#select2").show();
		}
		if($(this).parents(".selectBox").attr("id")=="select2"){
			$("#selBox3").show();
			$("li", "#select3").hide();
			$("li.sel3_"+$(this).attr("href"), "#select3").show();
		}
		return false;
	});
	
	$("#pointer", ".yearBox").click(function(){
		$(this).toggleClass("active");
		$(this).next().slideToggle("fast");
	});
	$("a", ".yearBox ul").click(function(){
		$("span:first", ".yearBox").text($(this).text());		
		$(this).parent().parent().slideToggle("fast");
		$("#year img").attr("id", "yea"+$(this).attr("id"));
		$("#pointer", ".yearBox").toggleClass("active");
		var month=$("#month img").attr("id").substr(5,$("#month img").attr("id").length);
		var year=(2000+parseInt($("#year img").attr("id").substr(4,$("#year img").attr("id").length)));
		$.post(ROOT+"calendar.php",{
			month: month,
			year: year
		}, function(data){
			$(".days").html(data);
		});
		return false;
	});
	$("#pointer2", ".monthBox").click(function(){
		$(this).toggleClass("active");
		$(this).next().slideToggle("fast");
	});
	$("a", ".monthBox ul").click(function(){
		$("span:first", ".monthBox").text($(this).text());		
		$(this).parent().parent().slideToggle("fast");
		$("#month img").attr("id", "mon"+$(this).attr("id"));
		$("#pointer2", ".monthBox").toggleClass("active");
		var month=$("#month img").attr("id").substr(5,$("#month img").attr("id").length);
		var year=(2000+parseInt($("#year img").attr("id").substr(4,$("#year img").attr("id").length)));
		$.post(ROOT+"calendar.php",{
			month: month,
			year: year
		}, function(data){
			$(".days").html(data);
		});
		return false;
	});
	
	$(".days div").live("mouseover",function(){
		$("div", this).show();						  
	});
	$(".days div").live("mouseout",function(){
		$("div", this).hide();						  
	});
	
	$("img:first", "#yearNews").click(function(){
		$(this).next().slideToggle("fast");
	});
	$("a", "#yearNews ul").click(function(){
		$("span:first", "#yearNews").text($(this).text());		
		$(this).parent().parent().slideToggle();
		return false;
	});
	$("img:first", "#monthNews").click(function(){
		$(this).next().slideToggle("fast");
	});
	$("a", "#monthNews ul").click(function(){
		$("span:first", "#monthNews").text($(this).text());		
		$("span:first", "#monthNews").attr("id",$(this).attr("href"));
		$(this).parent().parent().slideToggle();
		return false;
	});
	$("#ok").click(function(){
		$(this).attr("href",$(this).attr("href")+$("span:first", "#yearNews").text()+"/"+$("span:first", "#monthNews").attr("id")+"/");					
	});
	
	$("#winBg").click(function(){
		$("#winBg").hide();						  
		$(".winBox").hide();
		if($(".popupBox").length)
			$(".popupBox").hide();
	});
	$(".close").click(function(){
		$("#winBg").hide();						  
		$(".winBox").hide();
		if($(".popupBox").length)
			$(".popupBox").hide();
		return false;
	});
	$(".phones a").click(function(){
		$("#winBg").show();
		$(".winBox").css("top",($(window).scrollTop()+50)+"px");
		$("#city2Win").show();
		return false;
	});
	$(".medal").click(function(){
		$("#winBg").show();
		$(".winBox").css("top",($(window).scrollTop()+50)+"px");
		$("#medalWin").show();
		return false;
	});
	$(".aboutBox").click(function(){
		$("#winBg").show();
		$(".mainCont","#feedbackWin").show();
		$(".winBox").css("top",($(window).scrollTop()+50)+"px");
		$("#feedbackWin").show();
		return false;
	});
	$("#subscribeButton").click(function(){
		if(!$(this).prev().val() || $(this).prev().val()=="введите ваш e-mail"){
			$(this).prev().val("");
			return false;
		}
		$("#subscripleFormEmail").val($(this).prev().val());
		$("#winBg").show();
		$(".mainCont","#subscribeWin").show();
		$(".winBox").css("top",($(window).scrollTop()+50)+"px");
		$("#subscribeWin").show();
		return false;
	});
	$(".mapBox a").click(function(){
		$(".cityBox.active").removeClass("active");
		$("#allCities").show();
		$("#winBg").show();
		$(".winBox").css("top",($(window).scrollTop()+50)+"px");
		$("#geographyWin").show();						  
		return false;
	});
	$(".geoCols a").click(function(){
		$("#allCities").hide();
		$("#city"+$(this).attr("href")).addClass("active");	
		$(".next").show();
		return false;
	});
	$(".next").click(function(){
		var city=$(".cityBox.active");
		city.removeClass("active");
		$("#allCities").show();
		return false;
	});
	
	$(".substanceBox .tab").click(function(){
		$(this).next().toggle();								   
		return false;
	});

	$("#mebelLink, #mebelLink_").click(function(){
		$("#winBg").show();
		$(".winBox").css("top",($(window).scrollTop()+50)+"px");
		$("#mebelWin").show();
		$("#flash_mebel").show();
		var version = deconcept.SWFObjectUtil.getPlayerVersion();
		if(version['major']>=9){
			so = new SWFObject(ROOT+"swf/catalog/book.swf?rand="+(Math.random()*1000000)+"", "fl_mebel", "606", "436", "9.0.0", "#dedede", true);
			so.addParam("salign", "lt");
			so.addParam("allowScriptAccess", "sameDomain");
			so.addParam("menu", "false");
			so.addParam("wmode", "transparent");
			so.addVariable('IDS_FROM_JS', $('#furniture_catalog_ids').val());
			so.addVariable('PHOTOS_FROM_JS', $('#furniture_catalog_photos').val());
			so.addVariable('ROOT_FROM_JS', ROOT);
			so.addVariable('TYPE_FROM_JS', 'furniture');
			so.write("flash_mebel");
		}
		return false;					   
	});
	
	$("#productionLink, #productionLink_").click(function(){
		$("#winBg").show();
		$(".winBox").css("top",($(window).scrollTop()+50)+"px");
		$("#productionWin").show();
		$("#flash_production").show();
		var version = deconcept.SWFObjectUtil.getPlayerVersion();
		if(version['major']>=9){
			so = new SWFObject(ROOT+"swf/catalog/book.swf?rand="+(Math.random()*1000000)+"", "fl_mebel", "606", "430", "9.0.0", "#dedede", true);
			so.addParam("salign", "lt");
			so.addParam("allowScriptAccess", "sameDomain");
			so.addParam("menu", "false");
			so.addParam("wmode", "transparent");
			so.addVariable('IDS_FROM_JS', $('#production_catalog_ids').val());
			so.addVariable('PHOTOS_FROM_JS', $('#production_catalog_photos').val());
			so.addVariable('ROOT_FROM_JS', ROOT+'content/');
			so.addVariable('TYPE_FROM_JS', 'production');
			so.write("flash_production");
		}
		return false;					   
	});
	
	
	$("#studioLink").click(function(){
		$("#winBg").show();
		$(".winBox").css("top",($(window).scrollTop()+50)+"px");
		$("#galleryWin").show();
		$("#studioList").attr("mS",$("#studioList").parent().width()-$("#studioList").width()+15);
		return false;					   
	});
	$("#pointR", ".galleryListBox").click(function(){
		if(!$(this).attr("cl") && parseInt($("#studioList").css("left"))>$("#studioList").attr("mS")){
			$(this).attr("cl", "1");
			$("#studioList").animate({"left": "-=132px"}, "normal", function(){
				$("#pointL", ".galleryListBox").attr("cl", "");
				$("#pointR", ".galleryListBox").attr("cl", "");
			});
		}
		return false;												   
	});
	$("#pointL", ".galleryListBox").click(function(){
		if(!$(this).attr("cl") && parseInt($("#studioList").css("left"))<0){
			$(this).attr("cl", "1");
			$("#studioList").animate({"left": "+=132px"}, "normal", function(){
				$("#pointL", ".galleryListBox").attr("cl", "");
				$("#pointR", ".galleryListBox").attr("cl", "");
			});
		}
		return false;												   
	});
	$("#studioList img").click(function(){
		$(".workBox.active", "#galleryWin").removeClass("active");
		$("#work"+$(this).attr("id")).addClass("active");								
	});
	
	$("#teachersLink").click(function(){
		$("#winBg").show();
		$(".winBox").css("top",($(window).scrollTop()+50)+"px");
		$("#teachersWin").show();
		$("#teachersList").attr("mS",$("#teachersList").parent().width()-$("#teachersList").width()+15);
		return false;					   
	});
	$("#teachersList img").click(function(){
		$(".workBox.active", "#teachersWin").removeClass("active");
		$("#teacher"+$(this).attr("id")).addClass("active");								
	});
	$("#pointR2", ".galleryListBox").click(function(){
		if(!$(this).attr("cl") && parseInt($("#teachersList").css("left"))>$("#teachersList").attr("mS")){
			$(this).attr("cl", "1");
			$("#teachersList").animate({"left": "-=132px"}, "normal", function(){
				$("#pointL2", ".galleryListBox").attr("cl", "");
				$("#pointR2", ".galleryListBox").attr("cl", "");
			});
		}
		return false;												   
	});
	$("#pointL2", ".galleryListBox").click(function(){
		if(!$(this).attr("cl") && parseInt($("#teachersList").css("left"))<0){
			$(this).attr("cl", "1");
			$("#teachersList").animate({"left": "+=132px"}, "normal", function(){
				$("#pointL2", ".galleryListBox").attr("cl", "");
				$("#pointR2", ".galleryListBox").attr("cl", "");
			});
		}
		return false;												   
	});
	
	
	$("#studyLink").click(function(){
		$("#winBg").show();
		$(".studyBoxForm","#studyWin").show();
		$(".winBox").css("top",($(window).scrollTop()+50)+"px");
		$("#studyWin").show();
		
		return false;					   
	});
	
	
	$(".feedbackFormButton").click(function(){
		$("#winBg").show();
		$(".mainCont","#feedbackWin").show();
		$(".winBox").css("top",($(window).scrollTop()+50)+"px");
		$("#feedbackWin").show();
		return false;
	});
	
	$(".bannerBox").each(function(){
		$('.innerDescriptionBox').css('min-height', parseInt($('.innerDescriptionBox').css('min-height')) + 145);
		$('*html .innerDescriptionBox').css('height', parseInt($('*html .innerDescriptionBox').css('height')) + 145);
		$('.innerDescriptionBox .text').css('min-height', parseInt($('.innerDescriptionBox .text').css('min-height')) + 145);
		$('*html .innerDescriptionBox .text').css('height', parseInt($('*html .innerDescriptionBox .text').css('height')) + 145);
	});
	
	$(".bannerBox a").click(function(){
            if($(this).attr('href') != '' && $(this).attr('href') != '#')
                    return true;
		$("#winBg").show();
		$(".winBox").css("top",($(window).scrollTop()+50)+"px");
		$("#"+$(this).attr("title")+"Win").show();							 
		return false;
	});
	$(".bigBannerBox a").click(function(){
		$("#winBg").show();
		$(".winBox").css("top",($(window).scrollTop()+50)+"px");
		$("#"+$(this).attr("title")+"Win").show();							 
		return false;
	});
	
	$(".minus").click(function(){
		popupShow=false;
		$("#furniture_popup").hide();
		$("#production_popup").hide();
		$("#flash_mebel").css("visibility", "visible");
		$("#flash_production").css("visibility", "visible");
		return false;
	});
	$(".tabNext").click(function(){
		flashNext();
		return false;
	});
	$(".tabPrev").click(function(){
		flashPrev();
		return false;
	});
	$(".substance a").click(function(){
		var url=$(this).attr("href");
		if(url){
			so.setVar('PAGE_ID_FROM_JS', url);
		}
		return false;
	});
	
	$("#furniture_popup img").load(function(){
		if($(this).parent().parent().css("display")!="none"){
			var w=$(this).width()+60;
			var h=$(this).height()+60;
			var l=(650-w)/2;
			$("#furniture_popup div").animate({"width": w+"px","height": h+"px"}, "normal");									   
			$("#furniture_popup").animate({"width": w+"px","height": h+"px", "left": l+"px"}, "normal");									   
		}
	});
	$("#production_popup img").load(function(){
		if($(this).parent().parent().css("display")!="none"){
			var w=$(this).width()+60;
			var h=$(this).height()+60;
			var l=(650-w)/2;
			$("#production_popup div").animate({"width": w+"px","height": h+"px"}, "normal");									   
			$("#production_popup").animate({"width": w+"px","height": h+"px", "left": l+"px"}, "normal");									   
		}
	});

	$(".singTo").click(function(){
		$("#winBg").show();
		$(".studyBoxForm","#studyWin").show();
		$(".winBox").css("top",($(window).scrollTop()+50)+"px");
		$("#studyWin").show();
//		var sel3 = $(this).attr('id');
		var sel3 = $('#select3 a[href='+$(this).attr('id').substr(6)+']').parent().attr('class').substr(5);
		var sel2 = $('#select2 a[href='+sel3+']').parent().attr('class').substr(5);
		$('#select1 a[href='+sel2+']').click();
		$('#select2 a[href='+sel3+']').click();
		return false;							 
	});
	$(".singTo2").click(function(){
		$(".winBox").hide();
		$("#winBg").show();
		$(".studyBoxForm","#studyWin").show();
		$(".winBox").css("top",($(window).scrollTop()+50)+"px");
		$("#studyWin").show();
//		var sel3 = $(this).attr('id');
		var sel3 = $('#select3 a[href='+$(this).attr('id').substr(6)+']').parent().attr('class').substr(5);
		var sel2 = $('#select2 a[href='+sel3+']').parent().attr('class').substr(5);
		$('#select1 a[href='+sel2+']').click();
		$('#select2 a[href='+sel3+']').click();
		return false;							 
	});
	popUpWin = 0;
	$('#print_button').click(function(){
		if(popUpWin)
			if(!popUpWin.closed)
				popUpWin.close();
		popUpWin = open(ROOT+'print/', 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=700,height=600,left=100, top=100,screenX=100,screenY=100');
		return false;
	});

	
	$(".className").click(function(){
		$("#winBg").show();
		$(".winBox").css("top",($(window).scrollTop()+50)+"px");
		$("#descriptWin"+$(this).attr("href")).show();
		return false;
	});
});



function flashShowTab(id, s){
	$(".priceTab.active").removeClass("active");
	$("#tab_"+s+"_"+id).addClass("active");
	var flashUrl=ROOT+"content"+$("#tab_"+s+"_"+id).attr("name");
	$("#"+s+"_popup img").attr("src", flashUrl);
	if(popupShow){
		$("#"+s+"_popup").show();
		$("#flash_mebel").css("visibility", "hidden");
		$("#flash_production").css("visibility", "hidden");
	}
//	alert(flashUrl);
}

function flashPopup(s){
	popupShow=true;
	$("#"+s+"_popup").show();
	var w=$("#"+s+"_popup img").width()+50;
	var h=$("#"+s+"_popup img").height()+50;
	var l=(650-w)/2;
	$("#"+s+"_popup div").animate({"width": w+"px","height": h+"px"}, "normal");									   
	$("#"+s+"_popup").animate({"width": w+"px","height": h+"px", "left": l+"px"}, "normal");									   
}

function flashPrev(){
	$("#furniture_popup").hide();
	$("#production_popup").hide();
	so.setVar('PREV_PAGE_FROM_JS', 1);
}
function flashNext(){
	$("#furniture_popup").hide();
	$("#production_popup").hide();
	so.setVar('NEXT_PAGE_FROM_JS', 1);
}


