setInterval ("rotateImage()", 10000 );

function rotateImage(){
	var curSlide = parseInt($('#currentSlide').html());
  var maxSlide = parseInt($('#maxSlide').html());
	$('#homepagePromoTrack').css('width',(maxSlide*756)+'px');
	if((curSlide)==maxSlide){
		$('#currentSlide').html(1);
		var distance = 0;
	}else{
		$('#currentSlide').html((curSlide+1));
		var distance = (-1*(curSlide*756));
	}
	
  $('#homepagePromoTrack').animate({ 
  	marginLeft: distance+"px",
    easing: 'swing'
    }, 900 );
	
}

$(document).ready(function(){
	
  
  
	/* AJAX homepage newsletter signup */
  $('.getSubcategories').live('mouseover',function(){
  	var categoryId = $(this).attr('id');
  	$('#subcategoryContainer').fadeIn(300,function() {
	  	$.post("/js/xhr/subcategoryMenu.php", {
        parentCat: categoryId,
        baseUrl: '/nfs/c03/h07/mnt/81244/domains/smithyoungpartnership.co.uk/html/'
      }, function(response){
				$('#subcategoryContainer').html(response);
    	});
   	});
    	return false;
	});
  
  $('#subcategoryContainer').live('mouseleave',function(){
  	$('#subcategoryContainer').fadeOut(300,function() {
    	$('#subcategoryContainer').html('');
    });
	});
 
  
  $('.standard').focus(function ()
  {
    $('.standard').css('border', 'solid 1px #CCCCCC');
    $(this).css('border', 'solid 1px #909599');
  });
  
  $('.serviceName').live('click',function(){
  	$('.serviceDescription').slideUp(500);
    $('.serviceNameOn').removeClass('serviceNameOn').addClass('serviceName');
    nextDiv = $(this).next('div');
    nextDiv.slideDown(500);
    $(this).removeClass('serviceName').addClass('serviceNameOn');
  });
  
  $('#sendButton').click(function(){
		$('#sendButton').fadeOut(1000,function(){
    	$('#ajax-loader').show();
        $.post("/js/xhr/enquiry.php", {
        spacer: 'spacer',
      	firstName: $('#firstName').val(),
      	surname: $('#surname').val(),
				company: $('#company').val(),
				website: $('#website').val(),
      	email: $('#email').val(),
      	telephone: $('#telephone').val(),
				subject: $('#subject').val(),
      	message: $('#message').val(),
      	baseUrl: '/nfs/c03/h07/mnt/81244/domains/smithyoungpartnership.co.uk/html/'
    	}, function(response){
    		if(response==1){
      		$('#formContainer').fadeOut(1000,function(){
        		$('#thankyou-message').fadeIn(1000);
      		});
      	}else{
      		$('#formContainer').fadeOut(1000,function(){
      			$('#failure-message').fadeIn(1000);
        	});
      	}
        $('#ajax-loader').hide();
    	});
    });
    return false;
	});

  $('#statementLeft').click(function(){
  		
      scrollDistance = 490;

			curGalleryPosition = parseInt($('#currentGallerySlide').html());
			if(curGalleryPosition==1){
				qtySlides = parseInt($('#maxGallerySlide').html());
				toPosition = (-1*((qtySlides-1)*scrollDistance));
				$('#currentGallerySlide').html(qtySlides);
				
			}else{
				toPosition = (-1*((curGalleryPosition-2)*scrollDistance));
				$('#currentGallerySlide').html(curGalleryPosition-1);
			}
			
			$("#homepageStatementScroller").animate({ 
    		marginLeft: parseInt(toPosition)+'px'
  			}, 2000 );
		});
		
		$('#statementRight').click(function(){
    	
      scrollDistance = 490;
      
			curGalleryPosition = parseInt($('#currentGallerySlide').html());
			qtySlides = parseInt($('#maxGallerySlide').html());
			if(curGalleryPosition==qtySlides){
				toPosition = (0);
				$('#currentGallerySlide').html(1);
			}else{
				toPosition = (-1*((curGalleryPosition)*scrollDistance));
				$('#currentGallerySlide').html(curGalleryPosition+1);
			}
			
			$("#homepageStatementScroller").animate({ 
    		marginLeft: parseInt(toPosition)+'px'
  			}, 2000 );
		});

  
  
});


