$(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 a:first').append( '<img src="/pub/start/3.jpg" style="display: none;">');
      $('.works1 a:first').append( '<img src="/pub/start/4.jpg" style="display: none;">');
      //$('.works1 a:first').append( '<img src="/pub/start/5.jpg" style="display: none;">');
      $('.works1 a:first').append( '<img src="/pub/start/6.jpg" style="display: none;">');
      $('.works1 a:first').append( '<img src="/pub/start/7.jpg" style="display: none;">');
      $('.works1 a:first').append( '<img src="/pub/start/8.jpg" style="display: none;">');
      $('.works1 a:first').append( '<img src="/pub/start/9.jpg" style="display: none;">');
      $('.works1 a:first').append( '<img src="/pub/start/10.jpg" style="display: none;">');
      $('.works1 a:first').append( '<img src="/pub/start/11.jpg" style="display: none;">');
      $('.works1 a:first img').slideShow();
   } // End if

   
   // Портфолио: инициализация слайд-шоу работ
   if( $('.dev-img').length || $('.style-img').length ) {
      $.getScript( '/js/jquery.slideShow.js', function(){ 
         $('.dev-img').slideShow({
            play: false,
            speed: 1000,
            forward: '#dev-arrow-forward',
            back: '#dev-arrow-back'
         });
         
         $('.style-img').slideShow({
            play: false,
            speed: 1000,
            forward: '#style-arrow-forward',
            back: '#style-arrow-back'
         });

      }); // End $.getScript

   } // End if

   
   // Портфолио: инициализация кнопок листания работ
   $('#dev-arrow-forward, #style-arrow-forward').mouseover(function(){
      $(this).attr('src', '/i/link-right-on.jpg');
   });

   $('#dev-arrow-back, #style-arrow-back').mouseover(function(){
      $(this).attr('src', '/i/link-left-on.jpg');
   });
   
   $('#dev-arrow-forward, #style-arrow-forward').mouseout(function(){
      $(this).attr('src', '/i/link-right.jpg');
   });

   $('#dev-arrow-back, #style-arrow-back').mouseout(function(){
      $(this).attr('src', '/i/link-left.jpg');
   });


});


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(){
   $("img.fadein").fadeIn(2000);
});
