(function(f){function p(a,b,c){var h=c.relative?a.position().top:a.offset().top,d=c.relative?a.position().left:a.offset().left,i=c.position[0];h-=b.outerHeight()-c.offset[0];d+=a.outerWidth()+c.offset[1];if(/iPad/i.test(navigator.userAgent))h-=f(window).scrollTop();var j=b.outerHeight()+a.outerHeight();if(i=="center")h+=j/2;if(i=="bottom")h+=j;i=c.position[1];a=b.outerWidth()+a.outerWidth();if(i=="center")d-=a/2;if(i=="left")d-=a;return{top:h,left:d}}function u(a,b){var c=this,h=a.add(c),d,i=0,j=
0,m=a.attr("title"),q=a.attr("data-tooltip"),r=o[b.effect],l,s=a.is(":input"),v=s&&a.is(":checkbox, :radio, select, :button, :submit"),t=a.attr("type"),k=b.events[t]||b.events[s?v?"widget":"input":"def"];if(!r)throw'Nonexistent effect "'+b.effect+'"';k=k.split(/,\s*/);if(k.length!=2)throw"Tooltip: bad events configuration for "+t;a.bind(k[0],function(e){clearTimeout(i);if(b.predelay)j=setTimeout(function(){c.show(e)},b.predelay);else c.show(e)}).bind(k[1],function(e){clearTimeout(j);if(b.delay)i=
setTimeout(function(){c.hide(e)},b.delay);else c.hide(e)});if(m&&b.cancelDefault){a.removeAttr("title");a.data("title",m)}f.extend(c,{show:function(e){if(!d){if(q)d=f(q);else if(b.tip)d=f(b.tip).eq(0);else if(m)d=f(b.layout).addClass(b.tipClass).appendTo(document.body).hide().append(m);else{d=a.next();d.length||(d=a.parent().next())}if(!d.length)throw"Cannot find tooltip for "+a;}if(c.isShown())return c;d.stop(true,true);var g=p(a,d,b);b.tip&&d.html(a.data("title"));e=e||f.Event();e.type="onBeforeShow";
h.trigger(e,[g]);if(e.isDefaultPrevented())return c;g=p(a,d,b);d.css({position:"absolute",top:g.top,left:g.left});l=true;r[0].call(c,function(){e.type="onShow";l="full";h.trigger(e)});g=b.events.tooltip.split(/,\s*/);if(!d.data("__set")){d.bind(g[0],function(){clearTimeout(i);clearTimeout(j)});g[1]&&!a.is("input:not(:checkbox, :radio), textarea")&&d.bind(g[1],function(n){n.relatedTarget!=a[0]&&a.trigger(k[1].split(" ")[0])});d.data("__set",true)}return c},hide:function(e){if(!d||!c.isShown())return c;
e=e||f.Event();e.type="onBeforeHide";h.trigger(e);if(!e.isDefaultPrevented()){l=false;o[b.effect][1].call(c,function(){e.type="onHide";h.trigger(e)});return c}},isShown:function(e){return e?l=="full":l},getConf:function(){return b},getTip:function(){return d},getTrigger:function(){return a}});f.each("onHide,onBeforeShow,onShow,onBeforeHide".split(","),function(e,g){f.isFunction(b[g])&&f(c).bind(g,b[g]);c[g]=function(n){n&&f(c).bind(g,n);return c}})}f.tools=f.tools||{version:"1.2.5"};f.tools.tooltip=
{conf:{effect:"toggle",fadeOutSpeed:"fast",predelay:0,delay:30,opacity:1,tip:0,position:["top","center"],offset:[0,0],relative:false,cancelDefault:true,events:{def:"mouseenter,mouseleave",input:"focus,blur",widget:"focus mouseenter,blur mouseleave",tooltip:"mouseenter,mouseleave"},layout:"<div/>",tipClass:"tooltip"},addEffect:function(a,b,c){o[a]=[b,c]}};var o={toggle:[function(a){var b=this.getConf(),c=this.getTip();b=b.opacity;b<1&&c.css({opacity:b});c.show();a.call()},function(a){this.getTip().hide();
a.call()}],fade:[function(a){var b=this.getConf();this.getTip().fadeTo(b.fadeInSpeed,b.opacity,a)},function(a){this.getTip().fadeOut(this.getConf().fadeOutSpeed,a)}]};f.fn.tooltip=function(a){var b=this.data("tooltip");if(b)return b;a=f.extend(true,{},f.tools.tooltip.conf,a);if(typeof a.position=="string")a.position=a.position.split(/,?\s/);this.each(function(){b=new u(f(this),a);f(this).data("tooltip",b)});return a.api?b:this}})(jQuery);

var setTime = function() {
  var date = new Date();
  var hours = date.getHours();
  var minutes = date.getMinutes();
  
  if (hours < 10) {
    hours = '0' + hours;
  }
  
  if (minutes < 10) {
    minutes = '0' + minutes;
  }
  
  var time = hours + ':' + minutes;
  
  $('p.time').html(time);
  
  window.setTimeout(arguments.callee, 1000);
};

var checkWidth = function() {
	if ($(window).width() < 1275) {
		$('body').removeClass('body-wide');
	}
	else {
		$('body').addClass('body-wide');
	}
};

var checkForm = function(form){
  var result = true;
  
  if (form) {
    form = $(form);
    form.find('.error_list').hide();
    
    var formName = form.find('#form_name').val();
    var fieldObject = {};
    var fieldName = '';
    var fields = ['name', 'email', 'phone', 'text'];

    for (index in fields) {
      fieldName = formName + '_' + fields[index];
      fieldObject = $('#' + fieldName);

      if (fieldObject.length > 0 && ! fieldObject.val()) {
        fieldObject.prev('.error_list').fadeIn('slow');
        result = false;
      }
    }

    return result;
  }
};

$(function() {
  $('.about *:last, .about1 *:last, .produkcia .produkcia-bit:nth-child(3n)').addClass('last');

  // Только на главной странице
  var services = $('.produkcia .produkcia-bit');
  
  /* if (services.length > 0) {
    services.equalHeights();
  } */

  setTime();
  	
	checkWidth();
  
  $(window).resize(function() {
	  checkWidth();
  });
  
  $('.scrollable-inner, .scrollable').scrollable();

  $('a.fancy').fancybox({
		'hideOnContentClick': false,
		'showNavArrows': true
  });
  
  $('#consultant').popupwindow();
  
  var triggers = $('.modalInput, .modalInput1, .modalInput2').overlay({
		mask: {
  		color: 'none',
  		loadSpeed: 200,
  		opacity: 1
  	},
	  closeOnClick: false
	});

	$('.slidetabs').tabs('.images > div', {
		effect:       'fade',
		fadeOutSpeed: 'slow',
		autoplay:     true,
		interval:     300,
		rotate:       true
  }).slideshow({
    autoplay: true
  });

  // крутилка на главной клиентов
	var div = $('.client-hscroll'),
	    ul = $('.client-hscroll2'),
      ulPadding = 0;

	var divWidth = div.width();

	div.css({overflow: 'hidden'});

	var lastLi = ul.find('li:last-child');

	div.mousemove(function(e){
	  var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
	  var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
	  div.scrollLeft(left);
	});
  
  // крутилка на главной проектов
	var xdiv = $('.obj-hscroll'),
	    xul = $('.obj-hscroll2'),
      xulPadding = 0;

	var xdivWidth = xdiv.width();

	xdiv.css({overflow: 'hidden'});

	var xlastLi = xul.find('li:last-child');

	xdiv.mousemove(function(e){
		var xulWidth = xlastLi[0].offsetLeft + xlastLi.outerWidth() + xulPadding;
		var xleft = (e.pageX - xdiv.offset().left) * (xulWidth-xdivWidth) / xdivWidth;
		xdiv.scrollLeft(xleft);
	});
  
  // подсказки у скроллера проектов на главной
	$(".hscroll a[title]").tooltip({ position: "bottom center"});
});

function do_anket()
{

$('#anketa').toggle("slow");


};




