var SCROLLING = false;


function adjustDiv(){
       offset = 0;
      (scrollOffset()-294 < 0) ? value = 20 : value = scrollOffset()-294;
       $('flash').morph('margin-top:'+value+'px',{ duration:1, transition:Effect.Transitions.EaseFromTo });
}

function afterScroll(){
        var baseId = 0;
        var scrollId = new Date().getTime();
        var checkdelay = 500;

        if(!SCROLLING) {
                SCROLLING=true;
                setTimeout(
                        function(){
                                if(scrollId == baseId){
                                        SCROLLING = false;
                                        //DO THE FOLLOWING
                                        adjustDiv();
                                }
                                else{
                                        //RECURSIVE RUNCTION CALL
                                        baseId=scrollId;
                                        setTimeout(arguments.callee, checkdelay)
                                }
                        },
                        checkdelay
                );
        }
}
function scrollOffset(){
        if(window.pageYOffset){
                return window.pageYOffset;
        }
        else if (document.documentElement && document.documentElement.scrollTop){
                return document.documentElement.scrollTop;
        }
        else if (document.body){
                return document.body.scrollTop;
        }
}

function viewPort(dimension){
        var x, y;
        if (self.innerHeight) // all except Explorer
        {
                y = self.innerHeight;
                x = self.innerWidth;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
                // Explorer 6 Strict Mode
        {
                y = document.documentElement.clientHeight;
                x = document.documentElement.clientWidth;
        }
        else if (document.body) // other Explorers
        {
                y = document.body.clientHeight;
                x = document.body.clientWidth;
        }
        if (dimension == 'height'){
                return y;
        }
        if (dimension == 'width'){
                return x;
        }
}

