function moveLeft(){
  imageWidth = $('#farm_fg').outerWidth();
  currentLeft = $('#farm_image').css('left');
  currentLeft = parseFloat(currentLeft, 10);
  newLeft = currentLeft + 600;
  newLeft = Math.min(newLeft, 0);            
  $('#farm_image').animate({ left: newLeft + 'px'}, 500);
}

function moveRight(){
  imageWidth = $('#farm_fg').outerWidth();
  currentLeft = $('#farm_image').css('left');
  currentLeft = parseFloat(currentLeft, 10);
  newLeft = currentLeft - 600;
  newLeft = Math.max(newLeft, -imageWidth + 800);          
  $('#farm_image').animate({ left: newLeft + 'px'}, 500);
}

function farmtour() {
  $('#left').click(moveLeft);
  $('#right').click(moveRight);
  /* $('#field').hover(onImage, offImage); */
  return false;
}

function onImage(objid) {
  $('#' + objid).fadeIn(500);
}

function offImage(objid) {
  $('#' + objid).fadeOut(500);
}

function growIcon(){
  $(this).animate({
    height: "55px",
    paddingTop: "5px"
    }, 200);
}

function shrinkIcon(){
  $(this).animate({
    height: "45px",
    paddingTop: "10px"
	}, 200);
}

function growButton(){
  $(this).animate({
    height: "70px",
    paddingTop: "10px"
    }, 200);
}

function shrinkButton(){
  $(this).animate({
    height: "60px",
    paddingTop: "20px"
	}, 200);
}

function fadeOutHomeAnim() {
  frameHeight=$('#inner_frame').outerHeight();
  homeAnimHeight=$('#home_anim').outerHeight();
  homeContentHeight=$('#right_content').outerHeight();
  
  $('#home_anim').fadeOut( 250, function() {
    if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 4) {
      $('#inner_frame_grass').animate({ 
	    height: frameHeight - homeAnimHeight + homeContentHeight
		}, 500, function(){});
    }
  });
  $('#inner_frame').animate({ 
    height: frameHeight - homeAnimHeight + homeContentHeight }, 1000, function() {
    $('#right_content').show('fast');
    $('#home_cloud').show('fast');
	$('#home_menu').show('fast');
    $('#left_content').show('fast');
    $('#footer_image img').supersleight({shim: 'uploads/images/skin/x.gif'});
    $('#footer_image img').show('fast');
    $('#hmenu').show('fast');
	$('#hmenu img').show('fast');
  });
  
}

function animateLogo() {	  
 $('.contact_text').fadeIn( 250, function(){
    // Animation complete.
  });

  $('#logo_wrap img.logo').animate({
    width:220,
    height:60,
    top:20,
    left:20
    }, 2000, function() {
    // Animation complete.
  });
  
  $('#logo_wrap').animate({
    height:100
    }, 2000, function() {
    // Animation complete.
  });
  
  setTimeout('fadeOutHomeAnim()',4000);
}

function animateEggs() {
  $('#egg1').fadeIn( 250, function(){  
    $('#egg2').fadeIn( 250, function(){  
      $('#egg3').fadeIn( 250, function(){  
        $('#egg4').fadeIn( 250, function(){  
          $('#egg5').fadeIn( 250, function(){  
            $('#egg6').fadeIn( 250, function(){
			  $('#chicken2').fadeIn( 250, function(){
  			    animateLogo();
			  });
			});
          });
        });
      });
    });
  });
}

function animateHomePage() {
  $('#logo1').fadeIn( 1000, function(){
    $('#logo3').supersleight({shim: 'uploads/images/skin/x.gif'});
    $('#logo3').fadeIn( 1000, function(){
	  $('#logo4').supersleight({shim: 'uploads/images/skin/x.gif'});
	  $('#logo4').fadeIn( 750, function(){
        $('#beef').fadeIn( 250, function(){
		  niftyplayer('sound_cow').play();
          $('#sheep').fadeIn( 250, function(){
		    niftyplayer('sound_sheep').play();
            $('#pig').fadeIn( 250, function(){
		      niftyplayer('sound_pig').play();
              $('#chicken').fadeIn( 250, function(){
			  	niftyplayer('sound_rooster').play();
                $('#dash').fadeIn( 250, function() { 
				  niftyplayer('sound_background1').play();
				  animateEggs();
                });
              });
            });
          });
        });
      });
    });
  });
}
