$(document).ready(function(){


	// выравнивание
	wid1280 = function(){
		for (tt=0; tt<$('.act').length; tt++){
			if (tt%3 == 2) {
				$('.act').eq(tt).css({'margin-right': '0'});
			} else if (tt%3 == 1) {
				$('.act').eq(tt).css({'margin-right': '2%'});
			} else if (tt%3 == 0) {
				$('.act').eq(tt).css({'margin-right': '2%'});
			}
				
		};
	}; wid1280();


	wid1024 = function(){
		for (tt=0; tt<$('.act').length; tt++){
			if (tt%2 == 1) {
				$('.act').eq(tt).css({'margin-right': '0'});
			} else if (tt%2 == 0) {
				$('.act').eq(tt).css({'margin-right': '2%'});
			}
		};
	};

	wid800 = function(){
		for (tt=0; tt<$('.act').length; tt++){
			if (tt%2 == 1) {
				$('.act').eq(tt).css({'margin-right': '0'});
			} else if (tt%2 == 0) {
				$('.act').eq(tt).css({'margin-right': '2%'});
			}
		};
	};

	wid640 = function(){
		for (tt=0; tt<$('.act').length; tt++){
			if (tt%2 == 1) {
				$('.act').eq(tt).css({'margin-right': '0'});
			} else if (tt%2 == 0) {
				$('.act').eq(tt).css({'margin-right': '2%'});
			}
		};
	};

	wid480 = function(){
		for (tt=0; tt<$('.act').length; tt++){
				$('.act').eq(tt).css({'margin-right': '0'});
		};
	};
	
	wid400 = function(){
		for (tt=0; tt<$('.act').length; tt++){
				$('.act').eq(tt).css({'margin-right': '0'});
		};
	};

	go_rize = function(){
		
		$('body').removeClass('wid1280').removeClass('wid1024').removeClass('wid800').removeClass('wid640').removeClass('wid480').removeClass('wid400');
		
		if (document.documentElement.clientWidth >= 1060){
			$('body').addClass('wid1280');
			wid1280();
		} 
		else if (document.documentElement.clientWidth >= 920){
			$('body').addClass('wid1024');
			wid1024();
		} 
		else if (document.documentElement.clientWidth >= 750){
			$('body').addClass('wid800');
			wid800();
		} 
		else if (document.documentElement.clientWidth >= 600){
			$('body').addClass('wid640');
			wid640();
		} 
		else if (document.documentElement.clientWidth >= 440){
			$('body').addClass('wid480');
			wid480();
		} 
		else {
			$('body').addClass('wid400');
			wid400();
		}
	}; go_rize();


  	$(window).resize(function() {
   		go_rize();
	});

	// купить купон
	$('.click_info').mouseover(function(){
			$('i', this).show().closest('.act').find('.open_info').slideDown();
		});
	$('.act').mouseenter(function(){
		$('.open_info').slideUp('fast', function(){
			$('.click_info i').hide();
		});
			$openCity = 0;
			$('.city_select').animate({'top': -($('.city_select').innerWidth()+32)+'px'});
		});

	// города
	$openCity = 0;
	$('.user_city').click(function(){
		if ($openCity == 0) {
			$openCity = 1;
			$('.city_select').css({'top': -($('.city_select').innerWidth()+32)+'px'}).show().animate({'top':'32px'},'slow');
		};
	});

	$('.city_select').mouseleave(function(){
		$openCity = 0;
		$('.city_select').animate({'top': -($('.city_select').innerWidth()+32)+'px'});
	});


	// autohide
 	(function(){
		var $labels = $('label._autohide');
		$labels.each(function() {
			var $label = $(this);
			var id = $label.attr('for');
			var $input = $('#'+id);
			
			$input.focus(function(){
				$label.hide();
			}).blur(function(){
				if(!$input.val()){
					$label.show();
				}
			}).change(function(){
				if($input.val()){
					$label.hide();
				}
			});
			
			if ($input.val()) {
				$label.hide();
			}
		});
	})();   


	//Клик город регистрация
	$('.city_form').click(function(){
		$('.city_select_reg').show().css({'left': $(this).position().left-36+'px','top': $(this).position().top-55+'px'});
	});

	$('.menu_city_select li').click(function(){
		$('#citi_select').val($(this).attr('rel'));
		$('.city_select_reg').hide();
		$('.city_form span').html($(this).html())
	});

	$('.city_select_reg').mouseleave(function(){
		$('.city_select_reg').hide()
	});

	// таб вход - регистрация
	NumberIR = 0; 
	InterReg = function(){

		if (NumberIR == 0) {
			$('.inter_cntn').show();
			$('.reg_cntn').hide();
			$('.inter').removeClass('active_wa').addClass('active_wa');
			$('.reg').removeClass('active_wa');
		}
		if (NumberIR == 1) {
			$('.inter_cntn').hide();
			$('.reg_cntn').show();
			$('.reg').removeClass('active_wa').addClass('active_wa');
			$('.inter').removeClass('active_wa');
		}		

	}; InterReg();


	$('.inter').click(function(){
		NumberIR = 0;
		InterReg();
	});
	$('.reg').click(function(){
		NumberIR = 1;
		InterReg();
	});

	$('.inter_a').click(function(){
		$('.window_bg').show();
		NumberIR = 0;
		InterReg();
	});

	$('.reg_a').click(function(){
		$('.window_bg').show();
		NumberIR = 1;
		InterReg();
	});

	$('.closer_ar, .wbg_closer').click(function(){
		$('.window_bg').hide();
	});



    // прокрутка фото
	var ddH = document.documentElement.clientHeight;
	
	getscroll = function(){
	   $yPosition = document.documentElement.scrollTop + document.body.scrollTop + ddH + 300;
	   $hht = $yPosition-500 - ddH;
	   for (i=0; i<$('.img_load').length; i++) {
	    if ($('.img_load').eq(i).offset().top <= $yPosition) {
	     if ($('.img_load').eq(i).offset().top <= $hht) {
	     } else {
	      $('.img_load').closest('a').eq(i).addClass('gen');
	     };
	    };
	   };
	   	var $GL = $('.gen').length;
		   for (x=0; x<$GL; x++) {
		    $rel = $('.gen').eq(x).attr('rel');
		    $('.gen').eq(x).find('.img_load').remove();
		    $('.gen').eq(x).prepend('<img src="'+ $rel +'" alt=""/>');
		   };
	   $('.foto_act a').removeClass('gen');
	 }; getscroll();
	
	 $(window).scroll(function(){ 
	  getscroll(); 
	 });


	// фотогалерея
	$('.fg_window').click(function(e){
		$('body').append('<div class="image_foto_fg"><div class="foto_corn"><div class="foto_download"></div></div>');
		$('.bg_fg_window').show();
		$('.image_foto_fg').css({'left': e.pageX + 46 +'px', 'top': e.pageY - 260 +'px'});
		$(this).mousemove(function(e){
			$('.image_foto_fg').css({'left': e.pageX + 46 +'px', 'top': e.pageY - 260 +'px'});
		});
		$('.foto_download').html('<img src="'+ $(this).attr('href') +'" alt=""/>');
		$('.bg_fg_window_click, .closer_fg').click(function(){
			$('.bg_fg_window').remove();
		});   
		$(this).mouseleave(function(){
			$('.image_foto_fg').remove();
		});  
		return false;
	});


	// frend send
	$('.frend_send').toggle(
		function(){
		$('.content_tab_inner').slideDown();
	},function(){
		$('.content_tab_inner').slideUp();
	});






});
















