Cufon.replace('.index_titles .index_item .title .bg, .footer .hd, h1, .portfolio_column .title, .notfound_left, .notfound_text', { fontFamily: 'OfficinaSerifExtraBoldC' });

Cufon.replace('.seo .hd, .index_slogan, #contacts .cities a, h2, h3, #report .report_hd, #vacancies .all_vacancies .hd, #txt .right_column .hd, #vacancies .vacancy_item h3, .news_title a, .sitemap_column .fst_level a, .portfolio_list_column .site_title, .events .hd_date_red, .faq_list .trigger, .about_us_item .about_hd a, .about_us_item .event_date, .len_blogs_right .blog_title', { fontFamily: 'OfficinaSansBookOSC' });

Cufon.replace('.top_nav a, .top_nav_sub a', { fontFamily: 'OfficinaSerifBookC' });





$(document).ready(function() {

	$(".portfolio_column:last").css("padding-right", "0px");

	$(".top_nav li:last-child").addClass("li_last").after('<br clear="all" />');

	$(".top_nav_sub li:last-child").after('<br clear="all" />');

	$(".trail li:last-child").css({borderRight:'none'});

	$(".trail li:last-child").html($(".trail li:last-child a").html());

	$("#partners .parnters li:nth-child(3n), #partners .parnters li:last-child").after("<br clear='all' />");

	$("#main_clear").click(function(){

		$(".index_titles .index_item .picture:visible").slideUp(400);

		$(this).css("cursor", "default");

	});

	/*$(".index_titles .index_item .portfolio_start").hover(

		function(){

			$(this).children(".picture").slideDown(400);

			$(this).addClass("item_single_red");

			setTimeout('400');

		},

		function(){

			$(this).children(".picture").slideUp(400);

			$(this).removeClass("item_single_red");

			setTimeout('400');

		}

	);*/

	function showStartPortfolio (element) {

		//$(".index_titles .index_item .portfolio_start").unbind('mouseover');

		element.children(".picture").slideDown(400, function(){

			/*$(".index_titles .index_item .portfolio_start").bind('mouseleave',function(){

				removeStartPortfolio($(this));

				});*/

		});

		$("#main_clear").css("cursor", "pointer");

	}

	

	/*function removeStartPortfolio (element) {

		//$(".index_titles .index_item .portfolio_start").unbind('mouseleave');

		element.children(".picture").slideUp(400, function(){

			/*$(".index_titles .index_item .portfolio_start").bind('mouseover',function(){

				showStartPortfolio($(this));

				});

		});

		element.removeClass("item_single_red");

	}*/

	

	/*$(".index_titles .index_item .portfolio_start").mouseover(

		function(){

			showStartPortfolio($(this));

		});*/

	

	$(".index_item").mouseover(function(){

		$(this).addClass("item_double");

		$(this).children(".portfolio_start").children(".preview").css("border-bottom-color", "#D91018");

	});

	$(".index_item").mouseout(function(){

		$(this).removeClass("item_double");

		$(this).children(".portfolio_start").children(".preview").css("border-bottom-color", "#6F7172");

	});

	$(".index_item .picture").click(function(){

		var url = $(this).children(".red_label").attr("href");

		window.location = url;

	});

	

	$(".index_item").click(function(){

		$(".index_item").removeClass("item_single_red");

		if ($(this).children(".portfolio_start").children(".picture:visible").size() <= 0) {

			var showelement = $(this).children(".portfolio_start");

			if ($(".index_titles .index_item .picture:visible").size() > 0) {

				$(".index_titles .index_item .picture:visible").slideUp(400, function(){

					showStartPortfolio(showelement);

				});

			} else {

				showStartPortfolio(showelement);

			}

		}

		$(this).addClass("item_single_red");

	});

	

	$(".index_item .preview").click(function(){

		$(".index_item").parent().parent().removeClass("item_single_red");

		if ($(this).parent().parent().children(".portfolio_start").children(".picture:visible").size() <= 0) {

			var showelement = $(this).parent().parent().children(".portfolio_start");

			if ($(".index_titles .index_item .picture:visible").size() > 0) {

				$(".index_titles .index_item .picture:visible").slideUp(400, function(){

					showStartPortfolio(showelement);

				});

			} else {

				showStartPortfolio(showelement);

			}

		}

		$(this).parent().parent().addClass("item_single_red");

	});

	

	/*$(".index_titles .index_item .portfolio_start").mouseleave(

			function(){

				$(this).children(".picture").slideUp(400);

				$(this).removeClass("item_single_red");

				$(".index_titles .index_item .portfolio_start").bind('mouseover', function(){

					showStartPortfolio($(this));

				});

			});*/

	

	$(".top_nav a, .top_nav_sub a").hover(

		function(){$(this).parent().addClass("hover");},

		function(){$(this).parent().removeClass("hover");}

	);

	

	$(".quote_block").append('<div class="nib"></div>');

	

	$(".subscribe .inp").focus(function(){

		if ($(this).attr("value") == 'e-mail') {

			$(this).attr("value", "");

		}

	});

	

	$("#contacts .cities .feedback a").click(function(){

		if($(".cities").hasClass("feedback_active")) {

			$(".cities li.current").addClass("active");

			$(".cities").removeClass("feedback_active");

			$(".contact_form").slideUp(500);

			$(".google_maps, address").slideDown(500);

		} else {

			$(".cities li").removeClass("active");

			$(".cities").addClass("feedback_active");

			$(".google_maps, address").slideUp(500);

			$(".contact_form").slideDown(500);

		}

			return false;

	});

	

	$("#contacts .cities .city a").click(function() {

		

		if($(".cities").hasClass("feedback_active")) {

			$(".contact_form").slideUp(500);

			$(".cities").removeClass("feedback_active");

			$(".contact_form").slideUp(500);

			$(".google_maps, address").slideDown(500);

			$(".cities li").removeClass("active");

			$(".current").removeClass("current");

			$(this).parent().addClass("active");

		}



		if(!$(this).parent().hasClass("current")) {

			$(".cities li").removeClass("active");

			$(".current").removeClass("current");

			$(this).parent().addClass("active");

			$(this).parent().addClass("current");

			

			$(".google_maps #map_spb").hide();

			$(".google_maps #map_moscow").hide();

			$("#contacts address span").hide();

			

			$("#map_" + $(this).attr("href")).addClass("current");

			var citymap = $("#map_" + $(this).attr("href")).html();

			$("#map_" + $(this).attr("href")).empty();

			$("#map_" + $(this).attr("href")).show();

			$("#map_" + $(this).attr("href")).html(citymap);

			$("#addr_" + $(this).attr("href")).addClass("current");

			$("#addr_" + $(this).attr("href")).show();

		}

		return false;

	});

	

	/*$(window).load(function() {

		$("#map_moscow").hide();

	});*/



	$(".clients_item .roller").mouseover(

			function(){

				$(this).children(".roller_bg").slideDown(500);

			}

		);



	$(".clients_item").mouseleave(

		function(){

			$(".roller_bg").stop(true,true);

			$(this).children(".roller").children(".roller_bg").slideUp(500);

		}

	);



	$(".roller_bg").has(".article").has(".downloads").css("backgroundColor","#D7DCDE");

	

	$(".clients_item .roller .roll a").click(function(){return false;});



	$(".portfolio_selector .selected").not(".portfolio_selector_plus .selected").toggle(

			function(){

				$(this).next(".popup").slideDown(200);

			},

			function(){

				$(this).next(".popup").slideUp(200);

			}

		);

		/*$(".portfolio_selector_plus .selected").toggle(

			function(){

				$(this).parent().addClass("portfolio_selector_minus");

			},

			function(){

				$(this).parent().removeClass("portfolio_selector_minus");

			}

		);*/

		

	$('#yearfilter li a').click(function(){

		var val = $(this).attr("rel");

		$('#yearform').val(val);

		$('#filterform').submit();

		return false;

	});

	$('#spherefilter li a').click(function(){

		var val = $(this).attr("rel");

		$('#sphereform').val(val);

		$('#filterform').submit();

		return false;

	});

	$('#typefilter li a').click(function(){

		var val = $(this).attr("rel");

		$('#typeform').val(val);

		$('#filterform').submit();

		return false;

	});

	$('#favoritefilter').click(function(){

		var val = $('#favoriteform').val();

		var neval = (val == 0) ? 1 : 0;

		$('#favoriteform').val(neval);

		$('#filterform').submit();

		return false;

	});

	$('.portfolio_pager ul li a').click(function(){

		if ($('#filterform').size() > 0) {

			var act = $(this).attr('href');

			$('#filterform').attr('action', act);

			$('#filterform').submit();

			return false;

		}

	});

	$('.project_pages .back_to_list').click(function(){

		$('#backform').submit();

		return false;

	});

	$('#searchpager ul li a').click(function(){

		var act = $(this).attr('href');

		$('#searchform').attr('action', act);

		$('#searchform').submit();

		return false;

	});

	

	

	$(".portfolio_column .tags li:last-child").after('<br clear="all" />');



	Cufon.now();

	

	

	if($(".portfolio_left_column .project_pages").length>0){	

		var offset_first = $(".project_pages_placeholder").offset();

		$(".portfolio_left_column .project_pages").css({top:offset_first.top, left:30});

		$(window).scroll(function(){

			if (offset_first.top<$(window).scrollTop()+$(window).height()){

				$(".project_pages_placeholder").each(function(){

					var offset=$(this).offset();

					if (offset.top>$(window).scrollTop()-42 && offset.top<$(window).scrollTop()+$(window).height()){

						$(".portfolio_left_column .project_pages").removeClass("project_pages_semi").animate({top:offset.top}, {duration:300,queue:false});

						return false;

					}

					else {

						$(".portfolio_left_column .project_pages").addClass("project_pages_semi").animate({top:$(window).scrollTop()+$(window).height()/2-24}, {duration:300,queue:false});				

					}

				});

			}

		});

		$(window).trigger('scroll');

	}





	$(".project_pages").hover(

		function(){$(this).addClass("project_pages_semi2");},

		function(){$(this).removeClass("project_pages_semi2");}

	);

	

	$("div.contact_form form").submit(function() {

		var check = true;

		$(".field").removeClass("wrong");

		if($("input[name='FEEDBACK_NAME']").val() == "") {

			$("input[name='FEEDBACK_NAME']").parent().addClass("wrong");

			check = false;

		}

		

		var reg_mail = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;

		if($("input[name='FEEDBACK_EMAIL']").val() == "" || !reg_mail.test($("input[name='FEEDBACK_EMAIL']").val())) {

			$("input[name='FEEDBACK_EMAIL']").parent().addClass("wrong");

			check = false;

		}

		

		if($("input[name='FEEDBACK_CAPTION']").val() == "") {

			$("input[name='FEEDBACK_CAPTION']").parent().addClass("wrong");

			check = false;

		}

		

		if($("textarea[name='FEEDBACK_MESSAGE']").val() == "") {

			$("textarea[name='FEEDBACK_MESSAGE']").parent().addClass("wrong");

			check = false;

		}

		

		if($("input[name='FEEDBACK_CAPTCHA']").val() == "") {

			$("input[name='FEEDBACK_CAPTCHA']").parent().addClass("wrong");

			check = false;

		}

		

		/*

		function validateEmail(elementValue){  

			var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  

			return emailPattern.test(elementValue);  

		}  

		*/

		

		if(!check) {

			return false;

		}

	});

	

	$("div.event_register form").submit(function() {

		var check = true;

		$(".field").removeClass("wrong");

		if($("input[name='EVENT_DATE[]']:checked").size() <= 0 && $("#hiddeneventdate").size() <= 0) {

			$("input[name='EVENT_DATE[]']").parent().addClass("wrong");

			check = false;

		}

		

		if($("input[name='EVENT_QUANTITY']").val() == "") {

			$("input[name='EVENT_QUANTITY']").parent().addClass("wrong");

			check = false;

		}

		

		if($("input[name='EVENT_FIO']").val() == "") {

			$("input[name='EVENT_FIO']").parent().addClass("wrong");

			check = false;

		}

		

		if($("input[name='EVENT_PHONE']").val() == "") {

			$("input[name='EVENT_PHONE']").parent().addClass("wrong");

			check = false;

		}

		

		var reg_mail = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;

		if($("input[name='EVENT_MAIL']").val() == "" || !reg_mail.test($("input[name='EVENT_MAIL']").val())) {

			$("input[name='EVENT_MAIL']").parent().addClass("wrong");

			check = false;

		}



		

		if($("input[name='EVENT_CAPTCHA']").val() == "") {

			$("input[name='EVENT_CAPTCHA']").parent().addClass("wrong");

			check = false;

		}

		

		/*

		function validateEmail(elementValue){  

			var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  

			return emailPattern.test(elementValue);  

		}  

		*/

		

		if(!check) {

			return false;

		}

	});

	

	$(".search input.inp").click(function(){

			$(".search input.inp").val('');

			console.info($(".search input.inp"));

			$(".search input.inp").unbind("click");

	});

	

	$(".widther .scrollpart a").click(function(){

		if ($(this).hasClass("active")) {

			return false;

		} else {

			var newSrc = $(this).attr("href");

			var newText = $(this).attr("rel");

			$("#gallery_pic").attr("src",newSrc);

			$("#gallery_txt").html(newText);

			$(".widther .scrollpart a").removeClass("active");

			$(this).addClass("active");

			return false;

		}

		return false;

	});

	function reportImgScroller() {

        if ($(".widther a").size() > 0 ) {

	        var statulwidth = 0;

	        $(".widther a").each(function(){

	                statulwidth += 15 + $(this).outerWidth();

	        });

	        var marginstr = $(".widther .scrollpart").css("margin-left");

	        var marginint    = parseInt(marginstr.replace('px', ''));

	        var fulllenght = marginint+statulwidth;

	        if (fulllenght > 741) {

	        	$(".widther").width(680);

	            $("#gallery_pager").show();

	            $("#gallery_pager .prev").click(

	                function(){

	                       var newmarginstr = $(".widther .scrollpart").css("margin-left");

	                       var newmarginint    = parseInt(newmarginstr.replace('px', ''));

	                        if (newmarginint >= -150) {

	                                $(".widther .scrollpart").animate({marginLeft:'+='+(0-newmarginint)});

	                        } else {

	                                $(".widther .scrollpart").animate({marginLeft:'+=150'});

	                        }

	                        return false;

	                });

	            $("#gallery_pager .next").click(

	                function(){

	                        var ulwidth = 0;

	                        $(".widther a").each(function(){

	                                ulwidth += $(this).outerWidth() + 15;

	                        });

	                        var curmarginstr = $(".widther .scrollpart").css("margin-left");

	                        var curmargin    = parseInt(curmarginstr.replace('px', ''));

	                        var fulllenght = curmargin+ulwidth;

	                        var ostatok = ulwidth+curmargin-680;

	                        if (fulllenght > 680) {

	

	                                if (ostatok < 150) {

	                                        $(".widther .scrollpart").animate({marginLeft:'-='+ostatok});

	                                } else {

	                                        $(".widther .scrollpart").animate({marginLeft:'-=150'});

	                                }

	                        }

	                        return false;

	                });

            }

        }

	}



	reportImgScroller();

});



function scrollPic (picid) {

	$('.project_pages ul li').removeClass('active');

	var activeli = '#prev_'+picid;

	var bigpic   = '#pic_'+picid;

	$(activeli).addClass('active');

	$.scrollTo($(bigpic));

}
