// sticky footer
(function($) {
  var footer;
 
  $.fn.extend({
    stickyFooter: function(options) {
      footer = this;
       
      positionFooter();
 
      $(window)
        .scroll(positionFooter)
        .resize(positionFooter);
 
      function positionFooter() {
        var docHeight = $(document.body).height() - $("#sticky-footer-push").height();
        if(docHeight < $(window).height()){
          var diff = $(window).height() - docHeight;
          if (!$("#sticky-footer-push").length > 0) {
            $(footer).before('<div id="sticky-footer-push"></div>');
          }
          $("#sticky-footer-push").height(diff);
        }
      }
    }
  });
})(jQuery);

// GENERAL SCRIPT
$(document).ready(function() {
	
	// sticky footer
	$('.footer-wrapper').stickyFooter();

	// news related stuff items
	$('.news-carousel').jCarouselLite({
		btnNext: '.next',
		btnPrev: '.prev'
	});

	// footer area
	$('.partners-carousel').jCarouselLite({
		btnNext: '.partners-next',
		btnPrev: '.partners-prev',
		visible: 1,
		auto: 1000,
		speed: 1000
	});
	
	// only numbers in calc input
	$("#f").keypress(function(e) {
		if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)) {
			$("#errmsg").html("только цифры").show().fadeOut("slow");
			return false;
		}
	});
	
	// animated hover effect for cont-menu-list (modal window fixed)
	$('.cont-menu-list a').hover(
		function() {
			$(this).parent().children('span').stop().animate(
				{top: '-115px'},
				{duration: 400})
			},
		function() {
			$(this).parent().children('span').stop().animate(
				{top: '0'},
				{duration: 300})
		})
	
	// contact form toggle
	var conForm = $('.contactus').children('.wpcf7').children('form')
	
	$('.contactus').css({width: '32px'});
	$('.toggle').toggle(
	function() {
		$('.contactus').animate(
			{width: '273px'},
			{duration: 400});
		$(this).css({
			cursor: 'default',
			background: 'url(http://erp.it-develope.ru/wp-content/themes/organic/img/btn-toggle.png) no-repeat -32px 0'
		});
		$(conForm).show();
		$(this).children('span').css({display: 'block'})
	},
	function() {
		$(conForm).hide();
		$('.contactus').animate(
			{width: '32px'},
			{duration: 400})
		$(this).css({
			cursor: 'pointer',
			background: 'url(http://erp.it-develope.ru/wp-content/themes/organic/img/btn-toggle.png) no-repeat 0 0'
		})
		$(this).children('span').hide();
	})
	
	//
	$('select').selectBox({
		'menuTransition': 'fade',
		'menuSpeed': 'slow'
	})
	
	// modal window picture
	$(".example5").colorbox();
	
	// 
	$('.start-test').colorbox();
	
	//$( "#accordion" ).accordion({
	//	autoHeight: false
	//});
	
	//hidden blocks
	$('.hidden-block h3').append('<span></span>');
	$('.hidden-block span').each(function() {
		var trigger = $(this), el = trigger.parent().next('.hidden-block-text');
		trigger.click(function(){
			el.slideToggle();
			trigger.parent().parent().toggleClass('inactive');
		});
	}); 
	
});

// dynamic jQuery text hidden



//lite-box

