// переход к тесту со страницы заявки
function go_to_test(){
    $('#ApplicationForm').attr('action', '/onlinetest/');
    $('#ApplicationForm').submit();
}

/*$(document).ready(function(){
	var container = $('div.sliderGallery');
	var ul = $('ul', container);
				
	var itemsWidth = ul.innerWidth() - container.outerWidth();
				
	$('.slider', container).slider({
		min: 0,
		max: itemsWidth,
		handle: '.handle',
		stop: function (event, ui) {
		ul.animate({'left' : ui.value * -1}, 500);
		},
		slide: function (event, ui) {
		ul.css('left', ui.value * -1);
		}
	});
});*/

	window.onload = function () {
            var container = $('div.sliderGallery');
            var ul = $('ul', container);
            
            var itemsWidth = ul.innerWidth() - container.outerWidth();
            $('.slider', container).slider({
                min: 0,
                max: itemsWidth,
                /*handle: '.handle',*/
                stop: function (event, ui) {
                    ul.animate({'left' : ui.value * -1}, 500);
                },
                slide: function (event, ui) {
                    ul.css('left', ui.value * -1);
                }
            });
        };
		
		
		
$(document).ready(function(){



			 var ua = navigator.userAgent.toLowerCase();
 // Определим Internet Explorer
 if (ua.indexOf("msie") != -1 && ua.indexOf("opera") == -1 && ua.indexOf("webtv") == -1) {
	$('#test_fio_form, #mask, #rassilka_fio_form, #test_end').css('position','absolute');
	$('.slider').css('top','110px');
	$('#close_rassilka').css('margin','0');
    $('.main_bg_people_exam').css('width','316px');
    $('.green_popup').css('width','316px');
    
	
  // alert('Internet Explorer '+navigator.appVersion);
 }
 // Opera
 else if (ua.indexOf("opera") != -1) {
	
 }
 // Gecko = Mozilla + Firefox + Netscape
 else if (ua.indexOf("gecko") != -1) {
   
 }
 // Safari, используется в MAC OS
 else if (ua.indexOf("safari") != -1) {

 }
 // Konqueror, используется в UNIX-системах
 else if (ua.indexOf("konqueror") != -1) {

 }
 
 //else alert('Неизвестно');
		
		
	$('.main_bg_people_education').mouseover(function() {
        $(this).css('background','url(/images/main_page_education_bg.png) 0 0 no-repeat');
        
        $('.main_bg_people_exam').css('background','url(/images/main_page_exam_bg_white.png) 0 0 no-repeat');
        $('.main_bg_people_school').css('background','url(/images/main_page_school_bg_white.png) 0 0 no-repeat');
        $(this).parent('div').css('background','url(/images/frame.png) 1px -5px no-repeat');
        
        $('.main_bg_people_exam').parent('div').css('background','none');
        $('.main_bg_people_school').parent('div').css('background','none');
        
        $('#maska3').fadeIn(0);
    });
    
    $('.main_bg_people_exam').mouseover(function() {
        $(this).css('background','url(/images/main_page_exam_bg.png) 0 0 no-repeat');
        
        $('.main_bg_people_education').css('background','url(/images/main_page_education_bg_white.png) 0 0 no-repeat');
        $('.main_bg_people_school').css('background','url(/images/main_page_school_bg_white.png) 0 0 no-repeat');
        $('#maska3').fadeIn(0);
        $(this).parent('div').css('background','url(/images/frame.png) 1px -5px no-repeat');
        
        $('.main_bg_people_education').parent('div').css('background','none');
        $('.main_bg_people_school').parent('div').css('background','none');
    });
    
    $('.main_bg_people_school').mouseover(function() {
        $(this).css('background','url(/images/main_page_school_bg.png) 0 0 no-repeat');
        
        $('.main_bg_people_education').css('background','url(/images/main_page_education_bg_white.png) 0 0 no-repeat');
        $('.main_bg_people_exam').css('background','url(/images/main_page_exam_bg_white.png) 0 0 no-repeat');
        $('#maska3').fadeIn(0);
        $(this).parent('div').css('background','url(/images/frame.png) 1px -5px no-repeat');
        $('.main_bg_people_education').parent('div').css('background','none');
        $('.main_bg_people_exam').parent('div').css('background','none');
    });
    
    $('.main_bg_people_education').mouseout(function() {
        $('.main_bg_people_education').css('background','url(/images/main_page_education_bg_white.png) 0 0 no-repeat');
    });
    
    $('.main_bg_people_exam').mouseout(function() {
        $('.main_bg_people_exam').css('background','url(/images/main_page_exam_bg_white.png) 0 0 no-repeat');
    });

    $('.main_bg_people_school').mouseout(function() {
        $('.main_bg_people_school').css('background','url(/images/main_page_school_bg_white.png) 0 0 no-repeat');
    });

       
    $('.inner_red_bg').mouseover(function() {
        $('.inner_green_bg').css('background','url(/images/inner_green_white.png) 0 0 no-repeat');
        $('.inner_blue_bg').css('background','url(/images/inner_blue_white.png) 0 0 no-repeat');
        $('#maska3').fadeIn(0);
        
        $(this).parent('div').css('background','url(/images/frame_small.png) 1px -5px no-repeat');
        
        $('.inner_green_bg').parent('div').css('background','none');
        $('.inner_blue_bg').parent('div').css('background','none');
        
    });
    
    $('.inner_green_bg').mouseover(function() {
        
        $('#maska3').fadeIn(0);
        
        $(this).parent('div').css('background','url(/images/frame_small.png) 1px -5px no-repeat');
        
        $('.inner_red_bg').parent('div').css('background','none');
        $('.inner_blue_bg').parent('div').css('background','none');
    });
    
    $('.inner_blue_bg').mouseover(function() {
        
        $('#maska3').fadeIn(0);
        
        $(this).parent('div').css('background','url(/images/frame_small.png) 1px -5px no-repeat');
        
        $('.inner_red_bg').parent('div').css('background','none');
        $('.inner_green_bg').parent('div').css('background','none');
    });
    
    $('#maska3').mouseover(function() {
        //$('.main_bg_people_education').css('background','url(/images/main_page_education_bg_white.png) 0 0 no-repeat');
        //$('.main_bg_people_exam').css('background','url(/images/main_page_exam_bg_white.png) 0 0 no-repeat');
        //$('.main_bg_people_school').css('background','url(/images/main_page_school_bg_white.png) 0 0 no-repeat');
        
        $('.main_bg_people_education').parent('div').css('background','none');
        $('.main_bg_people_exam').parent('div').css('background','none');
        $('.main_bg_people_school').parent('div').css('background','none');
        
        
        $('.inner_red_bg').parent('div').css('background','none');
        $('.inner_green_bg').parent('div').css('background','none');
        $('.inner_blue_bg').parent('div').css('background','none');
        
        $('#maska3').fadeOut(0);
    });
    
    $('.map_no_hover').mouseover(function() {
        $('.main_bg_people_education').parent('div').css('background','none');
        $('.main_bg_people_exam').parent('div').css('background','none');
        $('.main_bg_people_school').parent('div').css('background','none');
    
        //$('.main_bg_people_education').css('background','url(/images/main_page_education_bg_white.png) 0 0 no-repeat');
        //$('.main_bg_people_exam').css('background','url(/images/main_page_exam_bg_white.png) 0 0 no-repeat');
        //$('.main_bg_people_school').css('background','url(/images/main_page_school_bg_white.png) 0 0 no-repeat');
        
        $('.inner_red_bg').parent('div').css('background','none');
        $('.inner_green_bg').parent('div').css('background','none');
        $('.inner_blue_bg').parent('div').css('background','none');
    });
		
	var active_block=1;
	var active_block_name = '#block'+active_block+' input';
	
	//popup
	$('.main_bg_people_education').click(function() {
		$('.red_popup').fadeIn(0);
		$('.green_popup').fadeOut(0);
		$('.blue_popup').fadeOut(0);
		$('#maska').fadeIn(0);
	});
	
	$('.inner_red_bg').click(function() {
		$('.red_popup').fadeIn(0);
		$('.green_popup').fadeOut(0);
		$('.blue_popup').fadeOut(0);
		$('#maska').fadeIn(0);
	});
	
	$('#maska').mouseover(function() {
		$('.red_popup').fadeOut(0);
		$('#maska').fadeOut(0);
	});
	
	$('.main_bg_people_exam').click(function() {
		$('.green_popup').fadeIn(0);
		$('.red_popup').fadeOut(0);
		$('.blue_popup').fadeOut(0);
		$('#maska').fadeIn(0);
	});
	
	$('.inner_green_bg').click(function() {
		$('.green_popup').fadeIn(0);
		$('.red_popup').fadeOut(0);
		$('.blue_popup').fadeOut(0);
		$('#maska').fadeIn(0);
	});
		$('#maska').mouseover(function() {
		$('.green_popup').fadeOut(0);
		$('#maska').fadeOut(0);
	});

	$('.main_bg_people_school').click(function() {
		$('.blue_popup').fadeIn(0);
		$('.green_popup').fadeOut(0);
		$('.red_popup').fadeOut(0);
		$('#maska').fadeIn(0);
	});
	$('.inner_blue_bg').click(function() {
		$('.blue_popup').fadeIn(0);
		$('.red_popup').fadeOut(0);
		$('.green_popup').fadeOut(0);
		$('#maska').fadeIn(0);
	});
	
	$('#maska').mouseover(function() {
		$('.blue_popup').fadeOut(0);
		$('#maska').fadeOut(0);
	});
	//popup
	
/*	$('.red_pop_up_slide').click(function() {
		$('.pop_up_slide div').slideToggle('slow', function() {});
	});
	*/

	$('div.LinkMany').each(function(){
		$(this).find('a:eq(0)').click(function(){
			$(this).parent('div').find('div:eq(0)').slideToggle('slow', function() {});
		});
	});

  /*
	$('div.LinkMany a:eq(0)').click(function() {
		$(this).parent('div').find('div:eq(0)').slideToggle('slow', function() {});
	});
	*/
	
/*	$('.green_url').click(function() {
		var idd=$(this).attr('idd');
		$('#green_inner_'+idd).slideToggle('slow', function() {});
	});
	
	$('.blue_url').click(function() {
		var idd=$(this).attr('idd');
		$('#blue_inner_'+idd).slideToggle('slow', function() {});
	});
	*/
	$('#contact_sotrudnic').click(function() {
		$('#sotrudnic_container').slideToggle('slow');
	});
	
	//Галлерея 
	$('.sliderGallery img').click(function() {
		var src=$(this).attr('full_img')
		$('#gallery_big_img img').attr('src',src);
	});
	//Галлерея 
	

	$("#slider").easySlider();
	
	$('.select_map').click(function() {
		$('.map_bg_hover').fadeIn(0);
	});
	
	$('#hide_map').click(function() {
		$('.map_bg_hover').fadeOut(0);
	});

	$('#get_rassilka').click(function() {
		$('#rassilka_fio_form').fadeIn('slow');
		$('#mask').fadeIn('slow');
	});
	$('#get_rassilka1').click(function() {
		$('#rassilka_fio_form').fadeIn('slow');
		$('#mask').fadeIn('slow');
	});
	
	$('#mask').click(function() {
		$('#rassilka_fio_form').fadeOut('slow');
		$('#mask').fadeOut('slow');
	});
	
	$('#close_rassilka').click(function() {
		$('#rassilka_fio_form').fadeOut('slow');
		$('#mask').fadeOut('slow');
	});
	
	//изменение картинки
	var put="";
	var img="";
	
	$('.map_links a').live('mouseover', function() {
		put=$(this).attr('put');
		img="url(/images/"+put+".png) 0 0 no-repeat";
		$('#map').css('background',img);
				
		//смена bg
		$('.map_links a').css('background','none');
		$('.map_links a').css('color','#253E85');
		
		
		$(this).css('background','#E13C00');
		$(this).css('color','#fff');
		$(this).css('padding','2px 8px 3px 8px');
		$(this).css('border-radius','15px');
		$(this).css('-moz-border-radius','15px');
		$(this).css('-webkit-border-radius','15px');
		//смена bg
		
		//смена главного слова
		/*var name=$(this).attr('name');
		$('#map_big_name').text(name);*/
		//смена главного слова
		
		
		put=$(this).attr('put');
		img="url(/images/"+put+".png) 0 0 no-repeat";
		$('#map').css('background',img);
	});
	
	//изменение картинки

//***************************************//
//****************TESTING****************//
//***************************************//
	
//	$('#start_test').click(function() {
//		//переключатель активности кнопки старт
//		$('#test_fio_form').fadeIn('slow');
//		$('#mask').fadeIn('slow');
//	});
	
//	$('#test_fio_form_close').click(function() {
//		$('#mask').fadeOut('slow');
//		$('#test_fio_form').fadeOut('slow');
//	});
	
//	$('#mask').click(function() {
//		$('#mask').fadeOut('slow');
//		$('#test_fio_form').fadeOut('slow');
//	});
	
	
//	//валидатор
//	var test_error=1;
//	$('.test_ok').click(function() {
//		var fio = $('.fio').val();
//		var phone = $('.phone').val();
//		var email = $('.email').val();
//
//
//
//		if(fio==""){
//			$('.fio').css('border','1px solid red');
//			$('#fio_error').show();
//			test_error=1;
//		}
//		else{
//			test_error=0;
//			$('#fio_error').show();
//			$('#fio_error').attr('src','/images/ok.png');
//		}
//
//		$(".fio").change(function () {
//			fio = $('.fio').val();
//			if(fio!=""){
//				$('.fio').css('border','1px solid #ccc');
//				$('#fio_error').attr('src','/images/ok.png');
//			}
//		});
//
//
//
//		if(phone==""){
//			$('.phone').css('border','1px solid red');
//			$('#phone_error').show();
//			test_error=1;
//		}
//		else{
//			test_error=0;
//			$('#phone_error').show();
//			$('#phone_error').attr('src','/images/ok.png');
//		}
//
//		$(".phone").change(function () {
//			phone = $('.phone').val();
//			if(phone!=""){
//				$('.phone').css('border','1px solid #ccc');
//				$('#phone_error').attr('src','/images/ok.png');
//			}
//		});
//
//
//
//		if(email==""){
//			$('.email').css('border','1px solid red');
//			$('#email_error').show();
//			test_error=1;
//		}
//		else{
//			test_error=0;
//			$('#email_error').show();
//			$('#email_error').attr('src','/images/ok.png');
//		}
//
//		$(".email").change(function () {
//			email = $('.email').val();
//			if(email!=""){
//				$('.email').css('border','1px solid #ccc');
//				$('#email_error').attr('src','/images/ok.png');
//			}
//		});
//		//валидатор
//
//		if(test_error==0){
//			$('#start_test div').css('background','url(/images/start_test.png) 0 0 no-repeat');
//			$('#mask').fadeOut('slow');
//			$('#test_fio_form').fadeOut('slow');
//			test();
//		}
//	});


//	$(".email").change(function () {
//		$('#email_error').show();
//		$('.email').css('border','1px solid #ccc');
//		$('#email_error').attr('src','/images/ok.png');
//	});
//
//	$(".fio").change(function () {
//		$('#fio_error').show();
//		$('.fio').css('border','1px solid #ccc');
//		$('#fio_error').attr('src','/images/ok.png');
//	});
//
//	$(".phone").change(function () {
//		$('#phone_error').show();
//		$('.phone').css('border','1px solid #ccc');
//		$('#phone_error').attr('src','/images/ok.png');
//	});

	
	
	function  test(){
//		$('#uslovie').hide(0);
//		$('#test_container').show(0);
//               $('.test_send').show(0);
		
		//********//
		//**ЧАСЫ**//
		
		var sec=0;
		var min=0;
		
		$("#clock").everyTime(1000, 'test_time', function() {
			if (sec==60){
				sec=0;
				
				min++;
				$('#sec').text(sec);
				
				if(min<10){
					$('#min').text('0'+min);
				}
				else{
					$('#min').text(min);
				}
			}
			
			//если меньше 10ти то прибавляем ноль
			if(sec<10){
				$('#sec').text('0'+sec);
			}
			else{
				$('#sec').text(sec);
			}
			
			sec++;
			
			if(min==45){
				$('#test_end').fadeIn('slow');
				$('#mask').fadeIn('slow');
				$("#clock").stopTime('test_time');
			}
			
		});
		
		
		var count_block = 0;
		var status_error = 1;
		//проверка радио
		var status_otvet=[0,0,0,0,0,0,0,0,0,0];
		var good_blocks=[0,0,0,0,0,0,0,0,0,0];
		var error_input=1;
		var active_block = "block1";
		var count_back=1;
		var first=1;
		var left_click=0;
		$('.blocks input').change(function () {

			
			
			var idd_input=$(this).attr('idd');
			status_otvet[idd_input-1]=1;
			
			
			for(i=0; i<10; i++){
				if (status_otvet[i]==0){
					error_input=1;
					break;
				}
				else{
					error_input=0;
				}
			}
			
			if (error_input==0){
				$('#control_strel_right img').attr('src','/images/test_right_green.png');
			}
			
			//alert(error_input);
			active_block=$(this).attr('page');
			//alert(active_block);
			
			//тут пишем какие блоки отвечены и они соответственно разрешены
			good_blocks[active_block-1]=1;
		});
		//проверка радио
		
		// скроллеры нижние
		$('#control_strel_right').click(function() {
			//alert(error_input+" &nbsp; "+count_back)
			if (error_input==0){
			active_block++;
			
			if (active_block==10){
				$('#control_strel').hide(0);
				$('#send').show(0)
			}
			
			//обнуление
			if(left_click==1){
				count_back--;
			}
			
			if (count_back==1){
				error_input=1;
				$('#control_strel_right img').attr('src','/images/test_right_grey.png');
			}
			
			for(i=0; i<10; i++){status_otvet[i]=0;}
			//обнуление
			active_block_name = '#block'+active_block+' input';
			
			// изменение верхних контроллеров при клике на скроллер нижний
				$('.control').css('background','#253E85');
				$('.control').css('border','1px solid #253E85');
				$('.control').css('color','#fff');
				
				var top_hover_contr='#conotrol_'+active_block;
				
				$(top_hover_contr).css('background','#fff');
				$(top_hover_contr).css('color','#253E85');
				$(top_hover_contr).css('border-bottom','1px solid #fff');
				
			// изменение верхних контроллеров при клике на скроллер нижний
			
			// смена блоков
			$('.blocks').hide();
			$('#block'+active_block).show();
			
			$('#control_strel_left img').attr('src','/images/test_left_green.png');
			num_block++;
			
			//if (first==1){first=0; count_back=0;}
			
			
			
			}
			else{
				alert('Для перехода на следующую страницу вы должны ответить на все вопросы на данной странице');
			}
		});
		
		
		
		$('#control_strel_left').click(function() {
			if(active_block>1){
			active_block--;
			left_click=1;
			count_back++;
			error_input=0;
			
			$('#control_strel_right img').attr('src','/images/test_right_green.png');
			//alert(error_input);
			// изменение верхних контроллеров при клике на скроллер нижний
				$('.control').css('background','#253E85');
				$('.control').css('border','1px solid #253E85');
				$('.control').css('color','#fff');
				
				var top_hover_contr='#conotrol_'+active_block;
				
				$(top_hover_contr).css('background','#fff');
				$(top_hover_contr).css('color','#253E85');
				$(top_hover_contr).css('border-bottom','1px solid #fff');
				
			// изменение верхних контроллеров при клике на скроллер нижний
			
			// смена блоков
			$('.blocks').hide();
			$('#block'+active_block).show();
			
			if(active_block-1==0){
				$('#control_strel_left img').attr('src','/images/test_left_grey.png');
			}
			}
		});
		// скроллеры нижние
		
		// верхние контролллеры
			$('.control').click(function() {
			var idd_block=$(this).attr('idd');

			
			if (good_blocks[idd_block-1]==1){
				var idd=$(this).attr('idd');
				active_block=idd;
				
				// смена блоков
				$('.blocks').hide();
				$('#block'+active_block).show();
				
				if(active_block-1==0){
					$('#control_strel_left img').attr('src','/images/test_left_grey.png');
				}
				else{
					$('#control_strel_left img').attr('src','/images/test_left_green.png');
				}
				
				if(active_block-1==9){
					$('#control_strel_right img').attr('src','/images/test_right_grey.png');
				}
				else{
					$('#control_strel_right img').attr('src','/images/test_right_green.png');
				}
				
				$('.control').css('background','#253E85');
				$('.control').css('border','1px solid #253E85');
				$('.control').css('color','#fff');

				$(this).css('background','#fff');
				$(this).css('color','#253E85');
				$(this).css('border-bottom','1px solid #fff');
			}
			else{
				alert('Для перехода на следующую страницу вы должны ответить на все вопросы на данной странице');
			}
			});
		// верхние контролллеры
		
		
		
		
		//**ЧАСЫ**//
		//********//
				/*$('#test_control div').mouseover(function() {
			$(this).css('background','#fff');
			$(this).css('color','#253E85');
		});
		
		$('#test_control div').mouseout(function() {
			$(this).css('background','#253E85');
			$(this).css('color','#fff');
		});
		*/


                $('.end_test_butt').click(function(){
                   var count_check = $('input:radio:checked').length;
                   if (count_check!=100) alert('Вам необходимо ответить на все 100 вопросов!')
                   else $('#onlinetest_form').submit()
                });

               $('input:radio').change(function(){ // передлать с :radio на имя элемента или класса
                   var count_check =$('input:radio:checked').length;
                   if (count_check==100) $('#xx23').toggleClass('end_test_enabled')

               });

}


/* запускаем часики теста */
if ($('#onlinetest_form').length) test();

//***************************************//
//****************TESTING****************//
//***************************************//


});
