var hp_images = $('hp_image_wrapper').select('img');
var hp_images_length = hp_images.length;
var counter = 0;

function rotateHpImages(){
    hp_images[counter].appear({
        afterFinish:function(){
            counter ++;
            if( counter < (hp_images_length) ){
                rotateHpImages.delay(4);
            } else {
                endRotation.delay(4);
            }
        }
    });
}

function endRotation(){
    $('image_homepage').fade({
        afterFinish:function(){
            skipHP();
        }
    });
}

function checkSkip(){
    if( readCookie('skip') == 1 ){
        skipHP();
    }
}
function skipHP(){
    //drop cookie to skip on next visit
    createCookie('skip',1);

    //hide image_homepage
    $('image_homepage').hide();

    //display text_homepage
    $('text_homepage').show();

    return false;
}
Event.observe(document,'dom:loaded', checkSkip);
Event.observe(window,'load', rotateHpImages);
