
function playerReady(obj) {
    addListeners();
};

function addListeners() {
    playlist = document.getElementById('mpl').getPlaylist();

    if (playlist.length > 0) {
        document.getElementById('mpl').addModelListener('STATE', 'stateMonitor');
    }
    else {
        setTimeout("addListeners();", 100);
    }
};

function stateMonitor(obj) {
    if (obj.newstate == 'COMPLETED') {
        // drop out of fullscreen
        this.window.focus();
        heroclose();
    }
};

function heroclose() {
    var options = {};
    $('#hero-control-close').hide();
    $('#hero-control-open').show();
    $('#hero-title-text').toggleClass("blackout");
    $('#hero-section-wrapper').hide("blind", options, 1000);
}

function heroopen() {
    var options = {};
    $('#hero-control-close').show();
    $('#hero-control-open').hide();
    $('#hero-title-text').toggleClass("blackout");
    $('#hero-section-wrapper').show("blind", options, 1000);
    setTimeout("kickoffplayer();", 2000);
    
}

function kickoffplayer() {
    //document.getElementById('mpl').sendEvent("PLAY", "true");
}

$(document).ready(function() {

    if ($('#term').length > 0) {
        $('#term').watermark("enter search text...");
    }

    if ($('#hero-player-wrapper').length > 0) {
        var so = new SWFObject('/Content/flash/player.swf', 'mpl', '700', '394', '9');
        so.addParam('allowscriptaccess', 'always');
        so.addParam('allowfullscreen', 'true');
        so.addParam("wmode", "transparent");
        so.useExpressInstall('/Content/flash/expressinstall.swf');
        so.addParam('flashvars', '&file=http://media.massarelli.com.asp1-12.websitetestlink.com/Assets/Hero/hero_animation2_x700nologo.f4v&dock=false&autostart=true&controlbar=over&skin=/Content/flash/bekle.swf');
        so.write('hero-player-wrapper');
    }

    if ($('#featured-player-wrapper').length > 0) {
        $('#slider').s3Slider({
            timeOut: 8000
        });
    }

    if ($('#hero-control-close').length > 0) {
        //$('#hero-control-close').hide();

        $('#hero-control-close').click(function() {
            heroclose();
        });
    }

    if ($('#hero-welcome-control-close').length > 0) {
        //$('#hero-control-close').hide();

        $('#hero-welcome-control-close').click(function() {
            heroclose();
        });
    }


    if ($('#hero-control-open').length > 0) {
        $('#hero-control-open').hide();

        $('#hero-control-open').click(function() {
            heroopen();
        });
    }
});
