function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

$( document ).ready( function() {
    var isTextOnly = getCookie( "textOnly" );
	
	if( isTextOnly != "true" ) {
        $( ".step" ).hide();
        
        $( "#animation li" ).hide().css( "opacity", 0 );//.css( "margin-left", "200px" ).;
        
        $( "#animation" ).css( "top", "200px" );
        
    	$( "#animation_link" ).show().click( function() {
            $( "#animation" ).show().animate( { top: 0 }, openSpeed, 'easeOutCubic', function() {
                $( "#animation_link" ).hide();
                
                startAnimation();
            } );
            
            return false;
        } );
        
        $( ".close" ).hide().click( function() {
            $( "#animation_link" ).show();
                
            $( "#animation" ).animate( { top: 200 }, openSpeed, 'easeOutCubic', function() {
                $( "#animation" ).hide();
            } );
            
            return false;
        } );
        
        var whichStep = 0;
        var numSteps = 3;
        
        var openSpeed = 800;
        var stepSpeed = 3000;
        var fadeSpeed = 1000;
        
        function startAnimation() {
            whichStep++;
            
            if( whichStep > numSteps ) {
                lastStep();
                
                return;
            }
            
            setTimeout( function() { startAnimation() }, stepSpeed );
            
            
            $( "#animation div.step" + whichStep ).fadeIn( fadeSpeed, function() {
                if( whichStep > 1 ) {
                    $( "#animation div.step" + ( whichStep - 1 ) ).hide();        
                }
            } );
            $( "#animation li.step" + whichStep ).show().animate( { marginLeft: 0, opacity: 1 }, fadeSpeed, 'easeOutCubic' );
        }
        
        function lastStep() {
            $( "#animation .close" ).fadeIn( fadeSpeed );
            
            $( "#animation div.step" + numSteps ).fadeOut( fadeSpeed, function() {
                $( "#animation div.last-step" ).fadeIn( fadeSpeed );
            } );
        }
    }
} );