$(document).ready(function(){

	slide(".hmenu", 10, 0, 150, .8);
	//slide(".menublocco1", 30, 20, 150, .8);
   
   $('#ones').growfield({
      animate: false
   });
   $('#ones1').growfield({
      animate: false
   });
   $('#ones2').growfield({
      animate: false
   });
   $(function(){
      $('.form-left input:checkbox').checkBox();
   });
   $(function(){
      $('.form-left input:radio').checkBox();
   });

   $(".project").each( function() {
		$(this).hover(
         function() {
			   $(this).addClass('act');
		   },		
		   function() {
			    $(this).removeClass('act');
         }
      );
   });
   
   $('div.form-block form').ajaxForm({
      beforeSubmit: requestProgress,
      success: requestSuccess,
      clearForm: true
   });
   
   
   // Главная страница: инициализация слайд-шоу работ
   /*
   if( $('.works1').length ) {
      $('.works1').append( '<img src="/pub/start/10.jpg" style="display: none;">');
		$('.works1').append( '<img src="/pub/start/1.jpg" style="display: none;">');
      $('.works1').append( '<img src="/pub/start/3.jpg" style="display: none;">');
      $('.works1').append( '<img src="/pub/start/4.jpg" style="display: none;">');
      $('.works1').append( '<img src="/pub/start/5.jpg" style="display: none;">');
      $('.works1').append( '<img src="/pub/start/6.jpg" style="display: none;">');
      $('.works1').append( '<img src="/pub/start/7.jpg" style="display: none;">');
      $('.works1').append( '<img src="/pub/start/8.jpg" style="display: none;">');
		$('.works1').append('<div class="btn"><a href="javascript://" class="activ"></a><a href="javascript://"></a><a href="javascript://"></a>'+
			'<a href="javascript://"></a><a href="javascript://"></a><a href="javascript://"></a>'+
			'<a href="javascript://"></a><a href="javascript://"></a><a href="javascript://"></a></div>');
			
		$('.works1').append( '<!--<div class="blue-work-link1"><img width="7" height="22" class="corner" src="/i/blank-left.png"><div class="link-obl">  = &nbsp;<a href="/services/">Закажите наши услуги</a></div></div>-->' );

      //$('.works1 img').slideShow();
		$('.works1').sgal();
   } // End if
   */
   // Разработка: галерея работ
   $("#gallery-control").gal();
      
   // Разработка: ротация менеджеров
   $('.else-excerpt').click( function () { 
      var excerpts = $(".excerpt");
      var cur = excerpts.filter(':visible');
      cur.fadeOut('fast', function() {
         if( excerpts.index(cur) + 2 > excerpts.length ) {
            excerpts.first().fadeIn();
         } else {
            cur.next().fadeIn();
         }
      });
   });  
   
   $("img.fadein").fadeIn(2000);

});

// Галерея работ
$.fn.gal=function() {
   var _gal = this;
   _gal._buttons = $(this).find(".pics > a");
   
   _gal._next = function () {
      _gal._cur = _gal._buttons.filter('.activ');
      if( _gal._buttons.index(_gal._cur) + 2 <= _gal._buttons.length ) {
         _gal._cur.next().click(); _gal._nextTimeout();
      } else {
         _gal.timeout_id = setTimeout( function() { if( _gal._buttons.length ) { _gal._buttons.first().click(); _gal._nextTimeout(); } }, 3000 );
      }
      
   }
   
   _gal._nextTimeout = function () {
      _gal.timeout_id = setTimeout( function() { _gal._next();}, 5000 );
   }
   _gal._nextTimeout();
   
   _gal._pic=$("#gallery-box div"); _gal._flag=true;
   $(_gal._buttons[0]).addClass("activ");
   
   return this.each(function() {
      _gal._buttons.bind("click",function() {
         clearTimeout( _gal.timeout_id );
         if( !$(this).hasClass("activ") && _gal._flag ) {
            _gal._flag = false;
            $(".pics > .activ").removeClass("activ"); $(this).addClass("activ");
            x=-928*$(this).index();
            _gal._pic.animate({left:x},1000,"easeOutCubic",function() { _gal._flag=true; });
         }
      });
   });
};


function showSEO() {
   $('.seo').fadeIn('slow');
   $('#zakaz-dev').css('display', 'none');
   $('#idn').css('display', 'block');
   return false;
}


function showDEV() {
   $('.dev').fadeIn('slow');
   $('#zakaz-seo').css('display', 'none');
   $('#idn').css('display', 'block');
   return false;
}




function slide(navigation_id, pad_out, pad_in, time, multiplier) {
	// creates the target paths
	var list_elements = navigation_id + " li.sliding-element";
	var link_elements = list_elements + " a";
	
	// initiates the timer used for the sliding animation
	var timer = 0;
	
	// creates the slide animation for all list elements 
	$( list_elements ).each( function( i ) { 
		// updates timer
		timer = (timer*multiplier + time);
      
		// margin left = - ([width of element] + [total vertical padding of element])
		$( this ).css("margin-left","-180px");
		$( this ).css("display","block");
      
		$( this ).animate( { marginLeft: "0" }, timer )
		        .animate( { marginLeft: "15px" }, timer )
		        .animate( { marginLeft: "0" }, timer );
      
	});

	// creates the hover-slide effect for all link elements 		
	$( link_elements ).each( function(i) {
		$(this).hover(
         function() {
			   $(this).animate({ paddingLeft: pad_out }, 150);
		   },		
		   function() {
            $(this).animate({ paddingLeft: pad_in }, 150);
         }
      );
	});
}


function showad(number) {
	$('#white-pos-ad' + number).css('display', 'block');
}
function hidead(number) {
	$('#white-pos-ad' + number).css('display', 'none');
}

var progressDiv, successDiv;

function requestProgress(formData, jqForm, options){
   if( !$(jqForm).valid() ) return false;
   var container = $('div.form-block:visible');
   if( !progressDiv ){
      progressDiv = $('<div class="progress"><div><img src="/i/progress.gif"></div></div>').hide().appendTo( $('body') );
   }
   progressDiv.css({
      left:   $(container).offset().left,
      top:    $(container).offset().top,
      width:  $(container).css( 'width' ),
      height: $(container).css( 'height' )
   }).show();
}

function requestSuccess( par1, par2, formObj ){ 
   var container = $('div.form-block:visible');
   if( progressDiv ){
      $(progressDiv).hide();
   }
   if( !successDiv ){
      successDiv = $('<div class="progress"><div>Ваша заявка отправлена</div></div>').hide().appendTo( $('body') );
   }
   successDiv.css({
      left:   $(container).offset().left,
      top:    $(container).offset().top,
      width:  $(container).css( 'width' ),
      height: $(container).css( 'height' )
   }).show();
   $( 'body' ).one('click', function(){
      successDiv.fadeOut(1000);
      $('#idn').fadeOut(1000);
   });
   
   // Добавляем отслеживание GoogleAnalytics
   //pageTracker._setVar( "Order" );
   pageTracker._setCustomVar(
      1,             // This custom var is set to slot #1
     "Order",       // The name of the custom varaible
      $(formObj).attr('id'),      // Sets the value
      1             // Sets the scope to visitor-level  
   );
   //pageTracker._trackPageview();
   
   pageTracker._trackEvent(
      "SendForm", // category of activity
      "SendForm-" + $(formObj).attr('id') // Action
   );
   pageTracker._trackPageview("/sendform/" + $(formObj).attr('id') ); 

   setTimeout( '$("body").click();', 5000 );
}

$(document).ready(function() { 
/* Toggle Effect Function */
	$('.inside').hide(); 
	$('.togle a.togglea').toggle(
		function() {
			$(this).addClass('togled');
			$(this).next('.inside').slideToggle(450, 'easeInQuart');
			return false;
		},
	   function() {
	      $(this).removeClass('togled');
	      $(this).next('.inside').hide(400, 'easeInQuart');
	      return false;
	   }
 	);
});

(function($) {
	$.fn.rabbit=function() {
		var obj=$(this); var summ=$(this).find(".bag .bag-summ"); var bagTitle=$(this).find(".bag .bag-title");
		var pic=$(this).find(".rabbit-pic"); var inp=$(this).find(".gift-form .txt input");
		var btn=$(obj).find(".rabbit-btn"); var pos="0px 0px";
		return this.each(function() {
			$(inp).keyup(function(event) { chNum(this,event); })
									.keypress(function(event) { chNum(this,event); })
									.change(function(event) { chNum(this,event); })
									.click(function() { $(this).select(); });
			$(btn).click(function() {
				if ($(inp).val()>=30000&&$(inp).val()<50000) { pos="0px -176px"; }
				else if ($(inp).val()>=50000&&$(inp).val()<90000) { pos="0px -352px"; }
				else if ($(inp).val()>=90000) { pos="0px -528px"; }
				else { pos="0px 0px"; }
				$(pic).css({backgroundPosition:pos});
			});
		});
	}
	chNum=function(e,k) { $(e).val($(e).val().replace(/\D/,'')); }
	
	$.fn.sgal=function() {
		var obj=$(this); var btn=$(obj).find(".btn a"); var img=$(obj).find("img"); var flag=true; var tnum=0;
		var num;
		return this.each(function() {
			$(btn).click(function() {
				if (!$(this).hasClass("activ")&&flag) {
					$(btn).filter(".activ").removeClass("activ"); $(this).addClass("activ");
					num=$(this).index(); flag=false;
					$(img[tnum]).animate({opacity:0},500,function() {
						$(this).css({display:"none"});
						$(img[num]).css({display:"block",opacity:0}).animate({opacity:1},500,function() { tnum=num; flag=true; });
					})
				}
			});
		});
	}
	
})(jQuery);

// Листалка со стрелочками в середине страницы
$(function(){
   $('.charg:first').attr('new_cur', true);

   $('.new-next a').click(function(){
      if( $('.charg[new_cur="true"]').length == 0 ) return;

      var old_e = $('.charg[new_cur="true"]');
      if( old_e.next('.charg').length == 0 ) return;

      var new_e = old_e.next('.charg');
      old_e.removeAttr('new_cur');
      old_e.fadeOut()
      new_e.fadeIn();
      new_e.attr('new_cur', true);

      $('.new-prev').show();
      if( new_e.next('.charg').length == 0 ) {
         $('.new-next').hide();
      }
   });
   $('.new-prev a').click(function(){
      if( $('.charg[new_cur="true"]').length == 0 ) return;

      var old_e = $('.charg[new_cur="true"]');
      if( old_e.prev('.charg').length == 0 ) return;

      var new_e = old_e.prev('.charg');
      old_e.removeAttr('new_cur');
      old_e.fadeOut()
      new_e.fadeIn();
      new_e.attr('new_cur', true);

      $('.new-next').show();
      if( new_e.prev('.charg').length == 0 ) {
         $('.new-prev').hide();
      }
   });
});



/*
 * jQuery viformcaptions plug-in 0.1 beta 
*/
(function($) { 

	var jqPluginName = 'viformcaptions';
		
	var demoPlugin = function(element, options) {

		var settings = $.extend({}, options||{});
	
		settings.context = element;
      
      // Добавление названий полей
      function add_form_field_descr() {
         $( settings.context ).find( 'input, textarea').each( function (i) {
            if( this.value == '' && settings[this.name] ) { 
               this.value = settings[this.name];
            }
         });
      }      
      
      add_form_field_descr();
      
      // Возвращаем название поля
      settings.context.find( 'input, textarea').focusout( function(){
         if( this.value == '' && settings[this.name] ) { this.value = settings[this.name];}
      });
      
      // Убираем название поля
      settings.context.find( 'input, textarea').click( function(){
         if( settings[this.name] && this.value == settings[this.name] ) { this.value = '';}
      });  
          
      this.Reload = function() {
         add_form_field_descr();
      }

      this.Clean = function() {
      
         settings.context.find( 'input, textarea').each( function (i) {
            if( settings[this.name] && this.value == settings[this.name] ) { this.value = '';}
         });
      }

		settings.context.data(jqPluginName, this);
	}
		
	$.fn[jqPluginName] = function(options) {		
		return this.each(function () {
			var _this = $(this);			
			if (!_this.data(jqPluginName))
			{
				new demoPlugin(_this, options);
			}
		});	
	}

})(jQuery);



$(function(){

   $('#form11, #form12, #form13').ajaxForm({
      beforeSubmit: function(formData, jqForm, options){
         
         if( jqForm.data('viformcaptions') ) { jqForm.data('viformcaptions').Clean(); }
         
         if( !$(jqForm).valid() ) {
            
            if( jqForm.data('viformcaptions') ) { jqForm.data('viformcaptions').Reload(); }
            alert( 'Необходимо заполнить выделенные поля формы' );
            return false;
         }
         
         jqForm.find( '.submit' ).attr( 'disabled', true );
         
      },
      success: function( par1, par2, formObj ){ 

         alert( 'Ваше сообщение успешно отправлено' );
         
         if( formObj.data('viformcaptions') ) { formObj.data('viformcaptions').Reload(); }
         
         formObj.find( 'input, textarea').removeClass( 'index-red' ).removeClass( 'index-green' );
         
         // Добавляем отслеживание GoogleAnalytics
         pageTracker._setCustomVar(
            1,             // This custom var is set to slot #1
           "Order",       // The name of the custom varaible
            $(formObj).attr('id'),      // Sets the value
            1             // Sets the scope to visitor-level  
         );
         
         pageTracker._trackEvent(
            "SendForm", // category of activity
            "SendForm-" + $(formObj).attr('id') // Action
         );
         pageTracker._trackPageview( "/sendform/" + $(formObj).attr('id') ); 

         setTimeout( '$("body").click();', 5000 );
         
         formObj.find( '.submit' ).removeAttr( 'disabled' );
         
      },
      clearForm: true
   });
});



