$(document).ready(function(){
$('HTML').addClass('JS');

jQuery.preloadImages = function() {
   jQuery.each (arguments,function (e) {
       jQuery("<img>").attr("src", this);
   });
   return true;
}
if ( $("div.services a").length ) {
$.preloadImages("/images/icon_12.png","/images/icon_22.png","/images/icon_32.png","/images/icon_42.png","/images/icon_52.png");
}
$.preloadImages("/images/corner/imm3.gif","/images/corner/big_2.jpg","/images/corner/big.swf");

if ( $("div.gblock2 a").length ) {
$.preloadImages("/images/gblock22.png");
}
if ( $("div.left_part ul.events li a").length ) {
$.preloadImages("/images/arr_gray.png");
}
if ( $("a.fancyclass").length) {$("a.fancyclass").fancybox({
 		'zoomSpeedIn'			: 600,
 		'zoomSpeedOut'			: 500,
 		'easingIn'				: 'easeOutBack',
 		'easingOut'				: 'easeInBack'
});}
if ( $("a.fancyclassbig").length ) {$("a.fancyclassbig").fancybox({
 		'zoomSpeedIn'			: 600,
 		'zoomSpeedOut'			: 500,
 		'easingIn'				: 'easeOutBack',
 		'easingOut'				: 'easeInBack',
 		'imageScale': false,
 		'centerOnScroll':false
});}

$('div.bg_places table tr').hover(function() {
      $(this).addClass('bg_places2');
}, function() {
      $(this).removeClass('bg_places2');
});

$('table.pressa_table tr').hover(function() { 
      $(this).addClass('overtable_presa');
}, function() {
      $(this).removeClass('overtable_presa');
});

$("div.services a")
.each(function(){
  $(this).attr('save', $(this).attr('class'));
})
.hover(function(){
$(this).addClass($(this).attr('save')+"2");
},function(){
$(this).removeClass($(this).attr('save')+"2");
});
$("div.left_part ul.events li a")
.hover(function(){
$(this).attr('save', $(this).parent().attr('class'));
$(this).parent().removeClass($(this).attr('save'));
},function(){
$(this).parent().addClass($(this).attr('save'));
});

if ( $("tr.last_upload").length ) { 
$("tr.last_upload").addClass("hover_table");
}

$("div.gblock2 a")
.hover(function(){
$("div.gblock2").addClass("gblock22");
},function(){
$("div.gblock2").removeClass("gblock22");
});

$("div.slide_menu div > a").click(
function(){
$(this).next("div").slideToggle("slow");
if ($(this).parent().find("img").attr('src') == '/images/arr.jpg') {
$(this).parent().toggleClass("border_do");
$(this).parent().find("img").attr('src','/images/arr-down.jpg');
$(this).parent().find("img").attr('width','24');
$(this).parent().find("img").attr('height','24');
return false;
}else{
$(this).parent().find("img").attr('src','/images/arr.jpg');
$(this).parent().find("img").attr('width','24');
$(this).parent().find("img").attr('height','24');
$(this).parent().toggleClass("border_do");
return false;
}
}
);

$(".slide_do_click").click(
function(){
$(this).next("div").slideToggle("slow");
return false;
}
);

$("div.client_item")
.mouseover(function(){
$(this).addClass("border_do");
$(this).find("img").attr('save', $(this).find("img").attr('src'));
$(this).find("img").attr('src', $(this).find("img").attr('srcnew'));
})
.mouseout(function(){
$(this).removeClass("border_do");
$(this).find("img").attr('src', $(this).find("img").attr('save'));
});

if ( $("#subscribe").length ) { 
  $("#subscribe").validate({
  		rules: {
  			surname: {required: true,minlength:4},
  			name: {required: true,minlength:3},
  			job: {required: true,minlength:5},
                     		
  			company: {required: true,minlength:2},
  			phone: {required: true,minlength:7},		            		
        mail: {
  				required: true,
  				email: true,
          minlength:6
  			}
  		},
  		messages: {
  		  surname: '<div class="error">Не указана фамилия</div>',		
  		  name: '<div class="error">Не указано имя</div>',	
        job: '<div class="error">Не указана должность</div>',		
  			company: '<div class="error">Не указана огранизация</div>',
  			phone: '<div class="error">Не указан контактный телефон</div>',
  			mail: '<div class="error">Введите корректный адрес электронной почты</div>'
  		},
  		success: function(label){
  		  if ($.preloadImages("/images/check_ok.gif")) label.html('&nbsp;<img src="/images/check_ok.gif" />');
      }
  }); 
}
$(".scrollto").click(function(){
$.scrollTo("#"+$(this).attr('sid'), 500 ); 
return false;
});   

$(".upload_new_file").click(function(){
$("#tr_select_"+$(this).attr('id2')).slideToggle("slow");
return false;
});   

$(".history_file").click(function(){
$("#tr_history_"+$(this).attr('id2')).slideToggle("slow");
return false;
}); 

$(".remove_file").click(function(){
	check = confirm('Удалить файл '+$(this).attr('name2')+'?');
	if (check == false) return false;
});  
   

if ( $("#feedbackform").length ) {
  $('.date_input').attachDatepicker();
  $("select[name='where']").change(function(){
    if ($(this).val() == '0') {
        $(this).after('<br><input id="other" name="other" type="text" class="text" />');    
    } else {
      if ( $("#other").length ) {
        $("#other").remove();
      }
    }
  });
  
$("#feedback").validate({
		rules: {
			company: {required: true, 
        remote: {
          url: "/feedback/form.php",
          type: "post",
          data: {
            field_len: "company",len: "4"
          }
        }
      },
			fio: {required: true, 
        remote: {
          url: "/feedback/form.php",
          type: "post",
          data: {
            field_len: "fio",len: "5"
          }
        }
      },	
			phone: {required: true, 
        remote: {
          url: "/feedback/form.php",
          type: "post",
          data: {
            field_len: "phone",len: "5"
          }
        }
      },	            		
      email: {
				required: true,
				email: true,
        remote: {
          url: "/feedback/form.php",
          type: "post",
          data: {
            field_mail: "email"
          }
        }
			},
			kol: {required: true, 
        remote: {
          url: "/feedback/form.php",
          type: "post",
          data: {
            field_len: "kol",len: "1"
          }
        }
      }
		},
		messages: {
			company: '&nbsp;<img src="/images/check_bad.png" />',
			fio: '&nbsp;<img src="/images/check_bad.png" />',		
			phone: '&nbsp;<img src="/images/check_bad.png" />',
			email: '&nbsp;<img src="/images/check_bad.png" />',
			kol: '&nbsp;<img src="/images/check_bad.png" />'
		},
  	success: function(label){
  		if ($.preloadImages("/images/check_ok.gif")) label.html('&nbsp;<img src="/images/check_ok.png" />');
    }
	});
	
	$("#doform").click(function(){
    	var options = {
        url: "/feedback/form.php",
        beforeSubmit: function() {
          return $("#feedback").valid();    
        },
        timeout: 3000,
        success: success_form
      }; 
    $("#feedback").ajaxSubmit(options);
    return false;
    function success_form() {
      setTimeout("$.scrollTo( 'body', 500 )", 500); 
      $("#doform2").html('<img src="/images/loading.gif" alt="идет загрузка">');
      $("#feedbackform").fadeOut(1500, function(){
      $("#feedbackform").before('<h3>Ваше сообщение было успешно отправлено!</h3><p><b>Благодарим за использование интерактивной формы - мы обязятально свяжемся с Вами.</b></p><p><a href="/feedback/">Отправить</a> еще одно сообщение?</p>');            
      return false;      
      }); 
    }
  });		


$("#calc").click(function(){
  $("#calc_div").slideToggle("slow");
  return false;
}).one('click', function() { 
  $.ajax({
  type: 'GET',
  cache: false,
  url: "/feedback/calc_count.php",
  success: function(data) {
          return false;
      }
  });
});

$("table.calc select").change(docalc);
$("table.calc input").keyup(docalc);
function docalc() {
$("#feedback_calc").validate({
		rules: {
      number: {required: true,digits: true},			
      programs: {required: true},			
      places: {required: true}		
		},
		messages: {
			programs: '<div class="error">Необходимо указать программу</div>',
			places: '<div class="error">Необходимо указать место проведения</div>',			
			number: {
           required: '<div class="error">Укажите количество участников</div>',
           min: jQuery.format('<div class="error">Мы не организуем мероприятия с данной программой для групп менее {0} человек</div>'),
           max: jQuery.format('<div class="error">Мы не организуем мероприятия с данной программой для групп более {0} человек</div>'),
          digits: '<div class="error">Поле должно содержать только цифры</div>'
      },
			pitanie: '<div class="error">Минимальная стоимость заказа 1000€</div>'
		}
	});  
 $.getJSON(
      "/feedback/calc.php",
      {
        programs: $('#programs').val(),
        places: $('#places').val(),
        number: $("#number").val(),
        transport: $('#transport').val(),
        pitanie: $('#pitanie').val(),
        den: $('#den').val(),
        oplata: $('#oplata').val()
      },
      function(data) {
      if (data.min_number !='' && data.max_number!=''){
         $("#number").rules("add", {
         required: true,
         min: data.min_number,
         max: data.max_number
        });   
      }else{
        $("#number").rules("remove", "min max");
      }
      if (data.pitanie < 1000){
         $("#pitanie").rules("add", {
         required: false,
         minlength:10
        });   
      }else{
        $("#pitanie").rules("remove", "required minlength");
      }
      if ($("#feedback_calc").valid()) {
        $("#result_sum").html("<strong>Стоимость</strong><br /><big>"+data.rub+" руб.<br /><span>"+data.euro+" €</span></big>");
        $("#result_sum_1").html("<strong>Стоимость на участника</strong><br /><big>"+data.rub_1+" руб.<br /><span>"+data.euro_1+" €</span></big>");
      } else {
        $("#result_sum").html(" ");
        $("#result_sum_1").html(" ");
      }
    });
}
}

if ( $("#slideshow").length ) {
var page = $("#slideshow img").attr('src2');
function slideSwitch() {
 cvi_glossy.defaultRadius = 20;
 cvi_glossy.defaultColor = 0;
 cvi_glossy.defaultColor2 = 0;
 cvi_glossy.defaultGradient = 'v';
 cvi_glossy.defaultShade = 50;
 cvi_glossy.defaultShadow = 40;
 cvi_glossy.defaultNoshadow = true;
 cvi_glossy.defaultNoradius = false;
$.ajax({
type: 'GET',
cache: false,
data: 'page='+page,
url: "/include/slideshow_img.php",
success: function(data) {
    $('#slideshow').animate({opacity: 0},300,function(){
      cvi_glossy.remove(document.getElementById("slideshow_img"));
      $.preloadImages(data, function(){
        $('#slideshow img').attr("src",data);
        $('#slideshow').animate({opacity: 1},700);
         cvi_glossy.add(document.getElementById("slideshow_img"));       
      } );
    });     
    }
});
}
setInterval(slideSwitch, 5000 );
}

if ( $("div.slideshowhome").length ) {
  $('div.slideshowhome').cycle({
  fx: 'fade',
  timeout:4000,
  speed:1200 
  });
  $('div.slideshowhome').click(function(){
  window.location.href = 'http://school.teamsystems.ru/';  
  });
}
if ( $("div.slideshowhome3").length ) {
  $('div.slideshowhome3').cycle({
  fx: 'turnLeft',
  timeout:3500,
  speed:1000 
  });
}
if ( $("div.slideshowhome2").length ) {
  $('div.slideshowhome2').cycle({
  fx: 'turnLeft',
  timeout:3500,         
  speed:1000  
  });
  $("div.23and8change")
  .mouseover(function(){
  $(this).attr('style', 'padding:0 15px 15px 15px;border: green 2px dashed;background-color:#FFFFFF;');
  })
  .mouseout(function(){
  $(this).attr('style', 'padding:0 15px 15px 15px;border: gray 2px dashed;background-color:#E8E8E8;');
  });  
}

if ( $("div.CustomSlideshow").length ) {
  $('div.CustomSlideshow').slideshow({
    playframe:false,
    play:true,
    titleshow:true,
    panel:false,
    time:5000,
    width:500,
    height:80,
    imgresize:true
  });
}

if ( $("div.CustomSlideshow2").length ) {
  $('div.CustomSlideshow2').slideshow({
    playframe:false,
    play:true,
    titleshow:true,
    panel:false,
    time:5000,
    width:500,
    height:100,
    imgresize:true
  });
}

if ( $("div.CustomSlideshow3").length ) {
  $('div.CustomSlideshow3').slideshow({
    playframe:false,
    play:true,
    titleshow:true,
    panel:false,
    time:5000,
    width:200,
    height:150,
    imgresize:true
  });
}

if ( $("div.CustomSlideshow4").length ) {
  $('div.CustomSlideshow4').slideshow({
    playframe:false,
    play:true,
    titleshow:true,
    panel:false,   
    time:4000,  
    width:174,
    height:84,
    imgresize:true
  });
}

if ( $("a.partner_mes").length ) {
$("a.partner_mes").click(function(){
$().message('Презентация мероприятия доступна только партнерам!<a href="/partnersarea/" target="_blank">подробнее и вход для партнеров</a>');
return false;  
});
}
});