﻿var bWidth=0;
var intLeft=0;
var intRight=0;
var minTMain=0;
var maxTMain=0;
var show="none";
var vecGo=0;
$(window).bind("load",function(){onlo();});

$(document).ready(function(){	
	
	var PayMin=0;
	var PayMax=10;
		
	setInterval(updateInfo,500);
	setInterval(updateVector,30);
	var hWind=$(window).height();
	$("#container #content").css("min-height",(parseInt(hWind)-160) + "px");	
		//validator
		$(".submit").click(function(){
			var send=true;
			$(".validEmpty").each(function(){
				var val=$(this).val();		
				if(val.match(/[А-Яа-яA-Za-zЁё]+/)===null || val.match(/[А-Яа-яA-Za-zЁё]+/)!=val)
				{
					send=false;
					$(this).parent().parent().find("td .error").removeClass("error").addClass("suscess");
				}else{
					$(this).parent().parent().find("td .suscess").removeClass("suscess").addClass("error");
				}
			});
			$(".validEmail").each(function(){
				var val=$(this).val();		
				if(val.match(/\w+@\w+\.[a-z]{2,3}/)===null)
				{
					send=false;
					$(this).parent().parent().find("td .error").removeClass("error").addClass("suscess");
				}else{
					$(this).parent().parent().find("td .suscess").removeClass("suscess").addClass("error");
				}
			});
			
			
			
			$(".validTel").each(function(){
				var val=$(this).val();		
				if(val.match(/^\+(1|20|210|211|212|213|214|215|216|217|218|219|220|221|222|223|224|225|226|227|228|229|230|231|232|233|234|235|236|237|238|239|240|241|242|243|244|245|246|247|248|249|250|251|252|253|254|255|256|257|258|259|260|261|262|263|264|265|266|267|268|269|27|28|290|291|292|293|294|295|296|297|298|299|30|31|32|33|34|350|351|352|353|354|355|356|357|358|359|36|370|371|372|373|374|375|376|377|378|379|380|381|382|383|384|385|386|387|388|389|39|40|41|420|421|422|423|424|425|426|427|428|429|43|44|45|46|47|48|49|500|501|502|503|504|505|506|507|508|509|51|52|53|54|55|56|57|58|590|591|592|593|594|595|596|597|598|599|60|61|62|63|64|65|66|670|671|672|673|674|675|676|677|678|679|680|681|682|683|684|685|686|687|688|689|690|691|692|693|694|695|696|697|698|699|7|800|801|802|803|804|805|806|807|808|809|81|82|83|84|850|851|852|853|854|855|856|857|858|859|86|870|871|872|873|874|875|876|877|878|879|880|881|882|883|884|885|886|887|888|889|89|90|91|92|93|94|95|960|961|962|963|964|965|966|967|968|969|970|971|972|973|974|975|976|977|978|979|98|990|991|992|993|994|995|996|997|998|999)\s*(?:(?:\(\s*(?:(?:(\d{1})\s*\)\s*(\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d))|(?:(\d{2})\s*\)\s*(\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d))|(?:(\d{3})\s*\)\s*(\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d))|(?:(\d{4})\s*\)\s*(\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d))|(?:(\d{5})\s*\)\s*(\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d))|(?:(\d{6})\s*\)\s*(\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d))|(?:(\d{7})\s*\)\s*(\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d))|(?:(\d{8})\s*\)\s*(\d(?:\s*-?\s*)\d))))|((?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d(?:\s*-?\s*)\d))$/)===null)
				{
					send=false;
					$(this).parent().parent().find("td .error").removeClass("error").addClass("suscess");
				}else{
					$(this).parent().parent().find("td .suscess").removeClass("suscess").addClass("error");
				}
			});
			if(send)
			{
				$("#sendMe").submit();
			}
			return false;
		});
	
});
	function onlo()
	{
		var setL=0;
		$("#top_vanns #wrp .imgT").each(function(i,el){
			
			bWidth+=parseInt($(el).width())+12;
			$("#top_vanns #wrp").css("width",bWidth+"px");
		  if($(el).find("img").attr("class")=="select")
		  	setL=$(el).position().left+$(el).width()/2;
		
		});
		$(".right,.left").css("display","block");
		$(".left").mouseenter(function(){intLeft=setInterval(onLeft,30);}).mouseleave(function(){clearInterval(intLeft);});
		$(".right").mouseenter(function(){intRight=setInterval(onRight,30);}).mouseleave(function(){clearInterval(intRight);});
		$(".imgT").click(function(){
			var position = $(this).position();
			//alert(position.left);
			if(!position.left)
				position.left=0;
			position.left+=$(this).width()/2;
			var opaset=this;
			$("#top_vanns #wrp").animate({left:(minTMain-position.left)+"px"},400,"swing",function(){
				window.location=$(opaset).find("a").attr("href");																					
			});
			$("#top_vanns #wrp .imgT").css("border","none");
			$(this).filter("img").css("border","3px solid #f00");
			return false;
		
		});
		
		$(".left").click(function(){
			var position = $("#top_vanns #wrp .imgT:first").position();

			if(!position.left)
				position.left=0;
			position.left+=$("#top_vanns #wrp .imgT:first").width()/2;
			$("#top_vanns #wrp").animate({left:-(position.left-$("#content").width()/2)+"px"},400,"swing");
			return false;
		});
		
		$(".right").click(function(){
			var position = $("#top_vanns .imgT:last").position().left;
			position-=$("#content").width()/2;
			position+=$("#top_vanns #wrp .imgT:last").width()/2;
			$("#top_vanns #wrp").animate({left:-(position)+"px"},400,"swing");
			return false;
		});
		minTMain=$("#content").width()/2-$("#top_vanns #wrp img:first").width()/2;
		
		//maxTMain=-($("#top_vanns #wrp").width()-$("body").width()/2-$("#top_vanns #wrp img:last").width());
		if(typeof $("#top_vanns #wrp img:last").position().left !== "unenfined")
		   maxTMain=-($("#top_vanns #wrp img:last").position().left-$("#content").width()/2+$("#top_vanns #wrp img:last").width()/2);

		$("#top_vanns #wrp").css("left",(minTMain-setL)+"px");
	}
	
	function onRight()
	{
		if(vecGo>-15)
		vecGo-=2;
	}
	
	function onLeft()
	{

		if(vecGo<15)
		vecGo+=2;

	}
	
	function updateInfo()
	{
		minTMain=$("#content").width()/2-$("#top_vanns #wrp img:first").width()/2;
		maxTMain=-($("#top_vanns #wrp img:last").position().left-$("#content").width()/2+$("#top_vanns #wrp img:last").width()/2);
		var hWind=$(window).height();
		$("#container #content").css("min-height",(parseInt(hWind)-160) + "px");	
	}
	
	function updateVector()
	{
		if(vecGo==0)
			return;
			
		var next=parseInt($("#top_vanns #wrp").css("left"))+vecGo;
		
		if(next>=minTMain)
			next=minTMain;
			
		if(next<=maxTMain)
			next=maxTMain;
		if(vecGo<0)
			vecGo++;
		if(vecGo>0)
			vecGo--;
		$("#top_vanns #wrp").css("left",next+"px");
	}
