/******************************************
 *  Developed by Ioannis Belegrinis, 2008 *
 *  Licensed to be used only under the    *
 *  Greek Greenpeace official website     *
 ******************************************/

/* FLASH INTRO EFFECT */

// Initialise Variables and States (DOCUMENT ONLOAD)
var introQueueEmpty = false;

// Set hover colour for flash intro link
function setIntroLinkColour( obj, colour_type )
{
    if( $("flashintro").style.display == 'none' && introQueueEmpty )
    {
        switch( colour_type )
        {
            case "light":
                $(obj).setStyle({backgroundColor: '#5ad201'});
                break;
            case "dark":
                $(obj).setStyle({backgroundColor: '#1a7a19'});
                break;
            default:
        }
    }
}

// Toggle Intro View
function toggleIntro()
{
    // Proceed only when all effects have finished processing
    if( introQueueEmpty )
    {
        // If Flash Intro is visible
        if( $("flashintro").style.display != 'none' )
        {
            introQueueEmpty = false;

            new Effect.Fade( $('flashintro'), {duration:0.1, queue: 'end', afterFinish: function() {
                    new Effect.BlindUp( $('flashintro_wrapper'), {duration:0.5, queue: 'end', afterFinish: function() {
                            $('whoweare').morph( "background-color: #1a7a19", {duration:0.3, queue: 'end'});
                            introQueueEmpty = true;
                            $('anim_close_btn').style.display = 'none';
                        }
                    } );
                }
            } );
        }
        else
        {
            introQueueEmpty = false;

            $('whoweare').morph( "background-color: #5ad201", {duration:0.3, queue: 'end'});
            new Effect.BlindDown( $('flashintro_wrapper'), {duration:0.5, queue: 'end', afterFinish: function() {
                    new Effect.Appear( $('flashintro'), {duration:0.1, queue: 'end', afterFinish: function() {
                            introQueueEmpty = true;
                            $('anim_close_btn').style.display = '';
                        }
                    } );
                }
            } );
        }
    }
}

// Toggle Intro View
function toggleIntroIE7()
{
    // Proceed only when all effects have finished processing
    if( introQueueEmpty )
    {
        // If Flash Intro is visible
        if( $("flashintro").style.display != 'none' )
        {
            introQueueEmpty = false;

            $('flashintro').style.display = 'none';
            $('flashintro_wrapper').style.display = 'none';
            $('whoweare').morph( "background-color: #1a7a19", {duration:0.3, queue: 'end'} );
            introQueueEmpty = true;
            $('anim_close_btn').style.display = 'none';
            $('Greenpeace_Anim').style.display = 'none';
        }
        else
        {
            introQueueEmpty = false;

            $('whoweare').morph( "background-color: #5ad201", {duration:0.3, queue: 'end'});
            $('flashintro_wrapper').style.display = '';
            $('flashintro').style.display = '';
            introQueueEmpty = true;
            $('anim_close_btn').style.display = '';
            $('Greenpeace_Anim').style.display = '';
        }
    }
}

function vIE() {
    return (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):-1;
}

// Execute when DOM has loaded
document.observe('dom:loaded', function() {
    // Insert the link for the flash intro (WhoWeAre layer)
    var whoWeAreDiv = new Element('div', {id: 'whoweare'});
    whoWeAreDiv.setStyle({
        background: '#1a7a19 url(http://www.greenpeace.org/resources/gcms/assets/graphics/navigation-arrow.png) 6px 4px no-repeat',
        paddingLeft: '24px',
        color: '#fff',
        height: '20px',
        width: '406px',
        'clear': 'both',
        marginTop: '5px',
        marginBottom: '-5px',
        lineHeight: '18px',
        cursor: 'pointer'
    });
    whoWeAreDiv.update( "<b><a href='#' style='color:#fff; text-decoration: none'>Γνωρίστε τη Greenpeace <img id='anim_close_btn' style='display:none; margin-left: 160px;' src='http://www.greenpeace.org/greece/assets/graphics/closebtn' alt='[x] close' align='top'/></a></b>" );
    $$('div.Content > div')[0].insert({before:whoWeAreDiv});
    
    // Add event listeners on the WhoWeAre layer
    if( vIE() == 7 ) {
        Event.observe( $('whoweare'), 'mouseup', toggleIntroIE7 );
    } else {
        Event.observe( $('whoweare'), 'mouseup', toggleIntro );
    }

    Event.observe( $('whoweare'), 'mouseover', function () { setIntroLinkColour(this,'light'); } );
    Event.observe( $('whoweare'), 'mouseout', function () { setIntroLinkColour(this,'dark'); } );

    introQueueEmpty = true;
    $('flashintro_wrapper').style.display = 'none';
    $('flashintro').style.display = 'none';
});
