﻿// JWPlayer VideoControl Script, Version 1.01
//
// Script created by Peter Avram
// Integrates with swfobject.js and allows simpler control over 
// creation and control of the JWPlayer embedded swf player.
//
// Changelog
// Version 1.02 (11/11/09)
// * Updating to Javascript playlist
// Version 1.01 (17/09/09)
// * Changed PlayerID and PlayerScriptID to be based off each other.
// * Changed PlayerID to be defined when creating the player (no longer global static variable)
//   This will allow Multiple players to coexist on the same page. (Theoretically - Untested)
//
// Version 1
// * First working version.  Released to www.foleys.com.au, 
//   also planned (but not deployed) for www.vicbar.com.au

// Load Required Javascript Libraries from Google.
//
//google.load("jquery", "1.3.2");
//google.load("swfobject", "2.2");
//google.load("yui", "2.8.0r4");
//google.load("ext-core", "3.0.0");
//google.load("jqueryui", "1.7.2");
//google.load("prototype", "1.6.1.0");
//google.load("scriptaculous", "1.8.3");
//google.load("mootools", "1.2.4");
//google.load("dojo", "1.3.2");


MediaPlayerConfig = function() { }
MediaPlayerConfig.prototype = {
    PlayerPlaceholderID: "",
    BaseURL: "/",
    PlayerURL: "/WebUserControls/VideoPlayer/player.swf",
    DefaultMediaURL: "",
    AutoPlay: false,
    Repeat: "none",
    Playlist: "none",
    PlaylistSize: 0,
    Height: 400, // 20 for audio, 400 for video - defaults.
    Width: 545,
    PlayerScriptID: function() { return "Script_" + this.PlayerPlaceholderID; }
}

function SwitchMedia(PlayerConfig, NewMediaURL) {
    var NewURL = PlayerConfig.BaseURL + NewMediaURL;
    // Make the player play the newURL.
    player = getFlashMovieObject(PlayerConfig.PlayerScriptID());
    if (player) {
        player.sendEvent('LOAD', NewURL);
        player.sendEvent('PLAY', PlayerConfig.AutoPlay);
    }
    else {
        alert("Oh Sausage!");
    }
}
function getFlashMovieObject(PlayerName) {
    if (document.embeds[PlayerName])
        return document.embeds[PlayerName];
    if (window.document[PlayerName])
        return window.document[PlayerName];
    if (window[PlayerName])
        return window[PlayerName];
    if (document[PlayerName])
        return document[PlayerName];
    return null;
}
function CreateNewAudioPlayer(PlayerConfig) {
    PlayerConfig.Height = 20; // always 20 for audio player
    CreatePlayer(PlayerConfig);

}
function CreateNewVideoPlayer(PlayerConfig) {
    CreatePlayer(PlayerConfig);
}
function CreatePlayer(PlayerConfig) {
    // 512 x 320
    window[PlayerConfig.PlayerScriptID()] = new Object();
    var s = new SWFObject(PlayerConfig.PlayerURL, PlayerConfig.PlayerScriptID(), PlayerConfig.Width, PlayerConfig.Height, "9", "#777777");
    s.addParam('allowfullscreen', 'true');
    s.addParam('allowscriptaccess', 'always');
    s.addParam('wmode', 'opaque');
//    s.addVariable('width', PlayerConfig.Width);
//    s.addVariable('height', PlayerConfig.Height);
//    s.addVariable('displayheight', PlayerConfig.Height);
//    s.addVariable('overstretch', 'fill');
    s.addVariable('playlist', 'none'); // always none
    s.addVariable('playlistsize', 0); // always 0
    s.addVariable('repeat', PlayerConfig.Repeat);
    s.addVariable('file', PlayerConfig.BaseURL + PlayerConfig.DefaultMediaURL);
    s.addVariable('lightcolor', '#ff0000'); // highlite colour (Text colour for selected, background colour for hover)
    s.addVariable('frontcolor', '#000000'); // Text colour (when not highlited)
    s.addVariable('backcolor', '#FFFFFF'); // foreground colour (also text colour when highlited)
    s.write(PlayerConfig.PlayerPlaceholderID);
    // Attach the config to the player!
    getFlashMovieObject(PlayerConfig.PlayerScriptID()).Config = PlayerConfig;
}
////window.onload = CreateNewVideoPlayer;

