client=0;curyear=1;curtype=1;var szs=Array();szs[2]="s";szs[3]="m";szs[4]="l";szs[5]="xl";szs[6]="f";t=window.location.hash;t2=t.substr(2,t.length-2);$(document).ready(function(){$('#client_log').click(function(){if(client==0){client=1;$("#user_login").fadeIn();}
else{client=0;$("#user_login").fadeOut();}});$("#user_close").click(function(){client=0;$("#user_login").fadeOut();});$("#last_img").mouseenter(function(){$("#last_img a").stop().animate({opacity:1},200);});$("#last_img").mouseleave(function(){$("#last_img a").stop().animate({opacity:0},200);});$(".work_in").mouseenter(function(){$kid=$(this).children(".work_grad").children();$kid.css({backgroundPosition:'0 -61px'});$kid.css({color:'#fff'});$kid=$(this).children(".work_grad").children().children("em");$kid.css({color:'#fff'});$kid=$(this).children(".work_image").children();$kid.stop().animate({opacity:0.8},200);});$(".work_in").mouseleave(function(){$kid=$(this).children(".work_grad").children();$kid.css({backgroundPosition:'0 0px'});$kid.css({color:'inherit'});$kid=$(this).children(".work_grad").children().children("em");$kid.css({color:'inherit'});$kid=$(this).children(".work_image").children();$kid.stop().animate({opacity:0},200);});$(".f_tit").click(function(){$target=$(this).next();if($target.css("display")!="none"){$target.fadeOut();tx=$(this).children().html();tx=tx.substr(0,(tx.length-1));tx=tx+'&darr;'
$(this).children().html(tx);}
else{$target.fadeIn();tx=$(this).children().html();tx=tx.substr(0,(tx.length-1));tx=tx+'&uarr;'
$(this).children().html(tx);}});});function changeyear(year){document.getElementById("year_"+curyear).className='year_not';document.getElementById("year_"+year).className='year_selected';window.location.hash=year+"-"+curtype;curyear=year;str=".work_0";if(year!=1){for(i=2006;i<2012;i++){if(i!=year){for(b=2;b<7;b++){str+=",.work_"+i+"_"+szs[b];}}}
$(str).fadeOut(300,function(){if(curtype!=1){$(".work_"+year+"_"+szs[curtype]).fadeIn();}
else{for(b=2;b<7;b++){$(".work_"+year+"_"+szs[b]).fadeIn()}}});str="";}
else{for(i=2006;i<2012;i++){if(curtype!=1){$(".work_"+i+"_"+szs[curtype]).fadeIn();}
else{for(b=2;b<7;b++){$(".work_"+i+"_"+szs[b]).fadeIn()}}}}}
function changetype(type){window.location.hash=curyear+"-"+type;document.getElementById("type_"+curtype).className='type_not';document.getElementById("type_"+type).className='type_selected';curtype=type;str=".work_0";if(type!=1){for(i=2;i<7;i++){if(i!=type){for(b=2006;b<2012;b++){str+=",.work_"+b+"_"+szs[i];}}}
$(str).fadeOut(300,function(){if(curyear!=1){$(".work_"+curyear+"_"+szs[type]).fadeIn();}
else{for(b=2006;b<2012;b++){$(".work_"+b+"_"+szs[type]).fadeIn()}}});str="";}
else{for(i=2;i<7;i++){if(curyear!=1){$(".work_"+curyear+"_"+szs[i]).fadeIn();}
else{for(b=2006;b<2012;b++){$(".work_"+b+"_"+szs[i]).fadeIn()}}}}}

$(document).ready(function(){
	
	if($(".p_cli").length>0){
		var wdt=$(window).width();
		
		var pp=Math.floor((wdt-20)/120);
		var wid=Math.floor(wdt/pp);
		$(".p_cli li").css({"width": wid});
	}
	
	var curslide=1;
	var hgt=$(".slide"+curslide).find(".inner").height();
	$("#slider_wrap").stop().animate({"height": hgt+7},0);
	$("#slider_head a").live("click",function(){
		var sl=$(this).attr("rel");
		if(sl!=curslide){
			curslide=sl;
			$("#slider_head a.active").removeClass("active");
			$("#point"+curslide).addClass("active");
			var hgt=$(".slide"+curslide).find(".inner").height();
			$("#slider_wrap").stop().animate({"height": hgt+7},600);
			var nd=100*(1-sl);	
			$("#allslides").stop().animate({"marginLeft": nd+"%"},600);
		}
	})
	
	$("#project_stages .stage").live("mouseenter",function(){
		if($(".active").length==0){
			$(".stage").each(function(){
				var wdt=$(this).attr("alt");
				wdt-=1;
				$(this).stop().animate({width: wdt+"%"},150);
			})
			var wdt=$(this).attr('alt');
			wdt=wdt++;
			wdt+=4;
			$(this).stop().animate({width: wdt+"%"},200);
		}
	})
	$("#project_stages .stage").live("mouseleave",function(){
		if($(".active").length==0){
			$(".stage").each(function(){
				var wdt=$(this).attr("alt");
				$(this).stop().animate({width: wdt+"%"},150);
			})
		}
	})
	$("#project_stages .stage").live("click",function(){
		var id=$(this).find("span").html();
		if(!$(this).hasClass('active')){
			$(".stage.active").removeClass("active");
			$(this).addClass("active");
			$(".stage").each(function(){
				var wdt=2;
				$(this).stop().animate({width: wdt+"%"},150);
			})
			var wdt=88;
			$(".infotext").fadeOut(10);
			
			$(this).stop().animate({width: wdt+"%"},200,function(){
				var lft=$(this).position().left+$(this).width()-426;
				$(".infotext div").css({"display": "none", "width": 420});
				$(".infotext").find(".txt"+id).css({"display": "inline-block"});
				$(".infotext").css({"left": lft}).fadeIn('fast');
				var hgt=$(".infotext").find(".txt"+id).height();	
				$(".infowrap").stop().animate({"height":hgt},150);
				
			});
		}else {
			$(this).removeClass("active");
			$(".stage").each(function(){
				var wdt=$(this).attr("alt");
				wdt-=1;
				$(this).stop().animate({width: wdt+"%"},150);
			})
			$(".infotext").fadeOut(10);
			$(".infowrap").stop().animate({"height":0},150);
			var wdt=$(this).attr('alt');
			wdt=wdt++;
			wdt+=4;
			$(this).stop().animate({width: wdt+"%"},200);
		}
	})
	
	var workslide=0;
	var maxminus=($(".workslide").length-1)*(-1);
	$(".workslide_but_left, .workslide_but_right").live("click",function(){
		if($(this).hasClass("workslide_but_left")){
			if(workslide<0){
				workslide++;
			}
			if(workslide==0){
				 $(".workslide_but_left").animate({"opacity": 0.5},200).addClass("disabled"); 
			  }
			$(".workslide_but_right").animate({"opacity": 1},200).removeClass("disabled"); 
		}
		else{
			  if(workslide>maxminus) workslide--;
			  if(workslide==maxminus){
				 $(".workslide_but_right").animate({"opacity": 0.5},200).addClass("disabled"); 
			  }
			   $(".workslide_but_left").animate({"opacity": 1},200).removeClass("disabled"); 
		}
		
		$(".workslider").stop().animate({"margin-left": (workslide*100)+"%"},200);
	})
	
	$("#footer_tree").live("click",function(){
		$(window).scrollTo($("#header"),1000);
	})
	
	$("input").live('focus',function(){
		if($(this).val()==$(this).attr("alt")){
			$(this).val("");	
		}
	})
	$("input").live('blur',function(){
		if($(this).val()==''){
			txt=$(this).attr("alt");
			$(this).val(txt);	
		}
	})
	
	$(".calc_button").live("click",function(){
		if(!$(this).hasClass("active")){
			
			var nm=$("#calc_name").val();
			var phone=$("#calc_phone").val();
			var mail=$("#calc_mail").val();
				
			if(mail==$("#calc_mail").attr("alt") && phone==$("#calc_phone").attr("alt")){
				resetCalc(0,contactsError);	
			}else {
				var regexp = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;
		
				if(phone==$("#calc_phone").attr("alt") && !regexp.test(mail)){
					resetCalc(0,"Вы неверно указали адрес электронной почты");	
				}else {
				
					$(this).addClass("active");
					$(this).stop().animate({"height": 102},200);
					$(this).children("span").stop().animate({"height": 100},200);
					$(this).find("font").fadeOut(200,function(){
						$(this).parent().parent().find("em").animate({"opacity": 1,"height": 100});
						
						var sz=$(".selected").attr("alt");
						var lang=1;
							if($("#lang2").attr("checked"))lang=2;
						var design=1;
							if($("#design2").attr("checked"))design=2;
						var like=$("#calc_like").val();
						var info=$("#calc_info").val();
						var adds=new Array();
						$(".calc_adds_form").find("input").each(function(){
							if($(this).attr("checked")){
								adds.push($(this).attr("alt"));	
							}
						})
						
						if($("#hasfile").val()==1){
							$("#file_upload_form").submit();	
						}else {
							addCalc(0);	
						}
						
					})
				}
			}
			
			
		}
	})
	
	var cursize=$("#cursize").val();
	$(".calc_size_form span").live("click",function(){
		var id=$(this).attr("alt");
		if(id!=cursize){
			$(".selected").removeClass("selected");
			$(this).addClass("selected");
			$(".calc_adds_form").slideUp('fast',function(){
				$("#block"+cursize).css({"display": "none"});
				$("#block"+id).css({"display": "inline-block"});
				cursize=id;
				$(".calc_adds_form").slideDown('fast');
			})
		}
	})
	
	var timeholder=0;
	
	$(".calc_contacts_form input").focus(function(){
		$(".calc_contacts_hint").fadeIn('fast');
		clearTimeout(timeholder);
	})
	$(".calc_contacts_form input").blur(function(){
		timeholder=setTimeout('$(".calc_contacts_hint").fadeOut("fast");',200);
	})
})

function resetCalc(tp,msg){
	$(".calc_button").removeClass("active");
	$(".calc_button").stop().animate({"height": 45},200);
	$(".calc_button").children("span").stop().animate({"height": 43},200);
	$(".calc_button").find("font").fadeIn(200,function(){
		$(this).parent().parent().find("em").animate({"opacity": 0,"height": 43});
		
	})	
	if(tp==0){
		if($(".calc_error").length>0)$(".calc_error").remove();
		$(".calc_button").after("<div class='calc_error'>"+msg+"</div>");
		$(".calc_error").slideDown('fast',function(){
			$(this).delay(2000).slideUp('fast');
		});
	}	
}

function resumeUpload(fileId){
	if(fileId!=0){
		addCalc(fileId);	
	}else {
		resetCalc(0,"Не удалось загрузить файл");	
	}
}

function addCalc(fileId){
	var nm=$("#calc_name").val();
	var phone=$("#calc_phone").val();
	var mail=$("#calc_mail").val();
	var sz=$(".selected").attr("alt");
	var lang=1;
		if($("#lang2").attr("checked"))lang=2;
	var des=1;
		if($("#design2").attr("checked"))des=2;
	var like=$("#calc_like").val();
	var info=$("#calc_info").val();
	var adds=new Array();
	$(".calc_adds_form").find("input").each(function(){
		if($(this).attr("checked")){
			adds.push($(this).attr("alt"));	
		}
	})
	if(nm==$("#calc_name").attr("alt"))nm="";
	if(mail==$("#calc_mail").attr("alt"))mail="";
	if(phone==$("#calc_phone").attr("alt"))phone="";
	$.post(base_url+"services/addCalc",{name: nm, tel: phone, email: mail, size: sz, language: lang, design: des, sitelike: like, more: info, additional: adds, file: fileId},function(data){
		if(data==0){
			resetCalc(0,"Ошибка доступа к базе данных. Попробуйте ещё раз");
		}else {
			$("#calculator").slideUp(1000,function(){
				$("#success_text").slideDown('fast');	
			});
				
		}
	})
	
}	

$.fn.customFileInput = function(){
//apply events and styles for file input element
var fileInput = $(this)
.addClass('customfile-input') //add class for CSS
.mouseover(function(){ upload.addClass('customfile-hover'); })
.mouseout(function(){ upload.removeClass('customfile-hover'); })
.focus(function(){
upload.addClass('customfile-focus');
fileInput.data('val', fileInput.val());
})
.blur(function(){
upload.removeClass('customfile-focus');
$(this).trigger('checkChange');
})
.bind('disable',function(){
fileInput.attr('disabled',true);
upload.addClass('customfile-disabled');
})
.bind('enable',function(){
fileInput.removeAttr('disabled');
upload.removeClass('customfile-disabled');
})
.bind('checkChange', function(){
if(fileInput.val() && fileInput.val() != fileInput.data('val')){
fileInput.trigger('change');
}
})
.bind('change',function(){
//get file name
var fileName = $(this).val().split(/\\/).pop();
//get file extension
var fileExt = 'customfile-ext-' + fileName.split('.').pop().toLowerCase();
//update the feedback
uploadFeedback
.text(fileName) //set feedback text to filename
.removeClass(uploadFeedback.data('fileExt') || '') //remove any existing file extension class
.addClass(fileExt) //add file extension class
.data('fileExt', fileExt) //store file extension for class removal on next change
.addClass('customfile-feedback-populated'); //add class to show populated state
//change text of button
uploadButton.text('Сменить');
$("#hasfile").val(1);
})
.click(function(){ //for IE and Opera, make sure change fires after choosing a file, using an async callback
fileInput.data('val', fileInput.val());
setTimeout(function(){
fileInput.trigger('checkChange');
},100);
});

//create custom control container
var upload = $('<div class="customfile"></div>');
//create custom control button
var uploadButton = $('<span class="customfile-button" aria-hidden="true">Выбрать</span>').appendTo(upload);
//create custom control feedback
var uploadFeedback = $('<span class="customfile-feedback" aria-hidden="true">Выберите файл</span>').appendTo(upload);

//match disabled state
if(fileInput.is('[disabled]')){
fileInput.trigger('disable');
}


//on mousemove, keep file input under the cursor to steal click
upload
.mousemove(function(e){
fileInput.css({
'left': e.pageX - upload.offset().left - fileInput.outerWidth() + 20, //position right side 20px right of cursor X)
'top': e.pageY - upload.offset().top  - 3
});
})
.insertAfter(fileInput); //insert after the input

fileInput.appendTo(upload);

//return jQuery
return $(this);
};

