﻿/*
VideoJS - HTML5 Video Player
v2.0.2

This file is part of VideoJS. Copyright 2010 Zencoder, Inc.

VideoJS is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

VideoJS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with VideoJS.  If not, see <http://www.gnu.org/licenses/>.
*/

// Self-executing function to prevent global vars and help with minification
(function (window, undefined) {
    var document = window.document;

    // Using jresig's Class implementation http://ejohn.org/blog/simple-javascript-inheritance/
    (function () { var initializing = false, fnTest = /xyz/.test(function () { xyz; }) ? /\b_super\b/ : /.*/; this.JRClass = function () { }; JRClass.extend = function (prop) { var _super = this.prototype; initializing = true; var prototype = new this(); initializing = false; for (var name in prop) { prototype[name] = typeof prop[name] == "function" && typeof _super[name] == "function" && fnTest.test(prop[name]) ? (function (name, fn) { return function () { var tmp = this._super; this._super = _super[name]; var ret = fn.apply(this, arguments); this._super = tmp; return ret; }; })(name, prop[name]) : prop[name]; } function JRClass() { if (!initializing && this.init) this.init.apply(this, arguments); } JRClass.prototype = prototype; JRClass.constructor = JRClass; JRClass.extend = arguments.callee; return JRClass; }; })();

    // Video JS Player Class
    var VideoJS = JRClass.extend({

        // Initialize the player for the supplied video tag element
        // element: video tag
        init: function (element, setOptions) {

            // Allow an ID string or an element
            if (typeof element == 'string') {
                this.video = document.getElementById(element);
            } else {
                this.video = element;
            }
            // Store reference to player on the video element.
            // So you can acess the player later: document.getElementById("video_id").player.play();
            if (!this.video) return;
            this.video.player = this;
            this.values = {}; // Cache video values.
            this.elements = {}; // Store refs to controls elements.
            this.hasStarted = false;
            this.hasCompleted = false;

            // Default Options
            this.options = {
                autoplay: false,
                preload: true,
                useBuiltInControls: false, // Use the browser's controls (iPhone)
                controlsBelow: false, // Display control bar below video vs. in front of
                controlsAtStart: false, // Make controls visible when page loads
                controlsHiding: true, // Hide controls when not over the video
                defaultVolume: 0.85, // Will be overridden by localStorage volume if available
                playerFallbackOrder: ["html5", "flash", "links"], // Players and order to use them
                flashPlayer: "htmlObject",
                flashPlayerVersion: false, // Required flash version for fallback
                shareButton: true,
                shareLabel: "Share",
                onStart: function () { },
                onComplete: function () { }
            };

            this.progressBar = null;
            // Override default options with global options
            if (typeof VideoJS.options == "object") { _V_.merge(this.options, VideoJS.options); }
            // Override default & global options with options specific to this player
            if (typeof setOptions == "object") { _V_.merge(this.options, setOptions); }
            // Override preload & autoplay with video attributes
            if (this.getPreloadAttribute() !== undefined) { this.options.preload = this.getPreloadAttribute(); }
            if (this.getAutoplayAttribute() !== undefined) { this.options.autoplay = this.getAutoplayAttribute(); }

            // Store reference to embed code pieces
            this.box = this.video.parentNode;
            this.linksFallback = this.getLinksFallback();
            this.hideLinksFallback(); // Will be shown again if "links" player is used

            // Loop through the player names list in options, "html5" etc.
            // For each player name, initialize the player with that name under VideoJS.players
            // If the player successfully initializes, we're done
            // If not, try the next player in the list
            this.each(this.options.playerFallbackOrder, function (playerType) {
                if (this[playerType + "Supported"]()) { // Check if player type is supported
                    this[playerType + "Init"](); // Initialize player type
                    return true; // Stop looping though players
                }
            });

            // Start Global Listeners - API doesn't exist before now
            this.activateElement(this, "player");
            this.activateElement(this.box, "box");

            this.updateVolumeDisplays();
        },
        /* Behaviors
        ================================================================================ */
        behaviors: {},
        newBehavior: function (name, activate, functions) {
            this.behaviors[name] = activate;
            this.extend(functions);
        },
        activateElement: function (element, behavior) {
            // Allow passing and ID string
            if (typeof element == "string") { element = document.getElementById(element); }
            this.behaviors[behavior].call(this, element);
        },
        /* Errors/Warnings
        ================================================================================ */
        errors: [], // Array to track errors
        warnings: [],
        warning: function (warning) {
            this.warnings.push(warning);
            this.log(warning);
        },
        /* History of errors/events (not quite there yet)
        ================================================================================ */
        history: [],
        log: function (event) {
            if (!event) { return; }
            if (typeof event == "string") { event = { type: event }; }
            if (event.type) { this.history.push(event.type); }
            if (this.history.length >= 50) { this.history.shift(); }
            try { console.log(event.type); } catch (e) { try { opera.postError(event.type); } catch (e) { } }
        },
        /* Local Storage
        ================================================================================ */
        setLocalStorage: function (key, value) {
            if (!localStorage) { return; }
            try {
                localStorage[key] = value;
            } catch (e) {
                if (e.code == 22 || e.code == 1014) { // Webkit == 22 / Firefox == 1014
                    this.warning(VideoJS.warnings.localStorageFull);
                }
            }
        },
        /* Helpers
        ================================================================================ */
        getPreloadAttribute: function () {
            if (typeof this.video.hasAttribute == "function" && this.video.hasAttribute("preload")) {
                var preload = this.video.getAttribute("preload");
                // Only included the attribute, thinking it was boolean
                if (preload === "" || preload === "true") { return "auto"; }
                if (preload === "false") { return "none"; }
                return preload;
            }
        },
        getAutoplayAttribute: function () {
            if (typeof this.video.hasAttribute == "function" && this.video.hasAttribute("autoplay")) {
                var autoplay = this.video.getAttribute("autoplay");
                if (autoplay === "false") { return false; }
                return true;
            }
        },
        // Calculates amoutn of buffer is full
        bufferedPercent: function () { return (this.duration()) ? this.buffered()[1] / this.duration() : 0; },
        // Each that maintains player as context
        // Break if true is returned
        each: function (arr, fn) {
            if (!arr || arr.length === 0) { return; }
            for (var i = 0, j = arr.length; i < j; i++) {
                if (fn.call(this, arr[i], i)) { break; }
            }
        },
        extend: function (obj) {
            for (var attrname in obj) {
                if (obj.hasOwnProperty(attrname)) { this[attrname] = obj[attrname]; }
            }
        }
    });
    VideoJS.player = VideoJS.prototype;

    ////////////////////////////////////////////////////////////////////////////////
    // Player Types
    ////////////////////////////////////////////////////////////////////////////////

    /* Flash Object Fallback (Player Type)
    ================================================================================ */
    VideoJS.player.extend({
        flashSupported: function () {
            if (!this.flashElement) { this.flashElement = this.getFlashElement(); }
            // Check if object exists & Flash Player version is supported
            if (this.flashElement && this.flashPlayerVersionSupported()) {
                return true;
            } else {
                return false;
            }
        },
        flashInit: function () {
            this.replaceWithFlash();
            this.element = this.flashElement;
            this.video.src = ""; // Stop video from downloading if HTML5 is still supported
            var flashPlayerType = VideoJS.flashPlayers[this.options.flashPlayer];
            this.extend(VideoJS.flashPlayers[this.options.flashPlayer].api);
            (flashPlayerType.init.context(this))();
        },
        // Get Flash Fallback object element from Embed Code
        getFlashElement: function () {
            var children = this.video.children;
            for (var i = 0, j = children.length; i < j; i++) {
                if (children[i].className == "vjs-flash-fallback") {
                    return children[i];
                }
            }
        },
        // Used to force a browser to fall back when it's an HTML5 browser but there's no supported sources
        replaceWithFlash: function () {
            // this.flashElement = this.video.removeChild(this.flashElement);
            if (this.flashElement) {
                this.box.insertBefore(this.flashElement, this.video);
                this.video.style.display = "none"; // Removing it was breaking later players
            }
        },
        // Check if browser can use this flash player
        flashPlayerVersionSupported: function () {
            var playerVersion = (this.options.flashPlayerVersion) ? this.options.flashPlayerVersion : VideoJS.flashPlayers[this.options.flashPlayer].flashPlayerVersion;
            return VideoJS.getFlashVersion() >= playerVersion;
        }
    });
    VideoJS.flashPlayers = {};
    VideoJS.flashPlayers.htmlObject = {
        flashPlayerVersion: 9,
        init: function () { return true; },
        api: { // No video API available with HTML Object embed method
            width: function (width) {
                if (width !== undefined) {
                    this.element.width = width;
                    this.box.style.width = width + "px";
                    this.triggerResizeListeners();
                    return this;
                }
                return this.element.width;
            },
            height: function (height) {
                if (height !== undefined) {
                    this.element.height = height;
                    this.box.style.height = height + "px";
                    this.triggerResizeListeners();
                    return this;
                }
                return this.element.height;
            }
        }
    };


    /* Download Links Fallback (Player Type)
    ================================================================================ */
    VideoJS.player.extend({
        linksSupported: function () { return true; },
        linksInit: function () {
            this.showLinksFallback();
            this.element = this.video;
        },
        // Get the download links block element
        getLinksFallback: function () { return this.box.getElementsByTagName("P")[0]; },
        // Hide no-video download paragraph
        hideLinksFallback: function () {
            if (this.linksFallback) { this.linksFallback.style.display = "none"; }
        },
        // Hide no-video download paragraph
        showLinksFallback: function () {
            if (this.linksFallback) { this.linksFallback.style.display = "block"; }
        }
    });

    ////////////////////////////////////////////////////////////////////////////////
    // Class Methods
    // Functions that don't apply to individual videos.
    ////////////////////////////////////////////////////////////////////////////////

    // Combine Objects - Use "safe" to protect from overwriting existing items
    VideoJS.merge = function (obj1, obj2, safe) {
        for (var attrname in obj2) {
            if (obj2.hasOwnProperty(attrname) && (!safe || !obj1.hasOwnProperty(attrname))) { obj1[attrname] = obj2[attrname]; }
        }
        return obj1;
    };
    VideoJS.extend = function (obj) { this.merge(this, obj, true); };

    VideoJS.extend({
        // Add VideoJS to all video tags with the video-js class when the DOM is ready
        setupAllWhenReady: function (options) {
            // Options is stored globally, and added ot any new player on init
            VideoJS.options = options;
            VideoJS.DOMReady(VideoJS.setup);
        },

        // Run the supplied function when the DOM is ready
        DOMReady: function (fn) {
            VideoJS.addToDOMReady(fn);
        },

        // Set up a specific video or array of video elements
        // "video" can be:
        //    false, undefined, or "All": set up all videos with the video-js class
        //    A video tag ID or video tag element: set up one video and return one player
        //    An array of video tag elements/IDs: set up each and return an array of players
        setup: function (videos, options) {
            var returnSingular = false,
    playerList = [],
    videoElement;
            // If videos is undefined or "All", set up all videos with the video-js class
            if (!videos || videos == "All") {
                videos = VideoJS.getVideoJSTags();
                // If videos is not an array, add to an array
            } else if (typeof videos != 'object' || videos.nodeType == 1) {
                videos = [videos];
                returnSingular = true;
            }

            // Loop through videos and create players for them
            for (var i = 0; i < videos.length; i++) {
                if (typeof videos[i] == 'string') {
                    videoElement = document.getElementById(videos[i]);
                } else { // assume DOM object
                    videoElement = videos[i];
                }
                playerList.push(new VideoJS(videoElement, options));
            }

            // Return one or all depending on what was passed in
            return (returnSingular) ? playerList[0] : playerList;
        },

        // Find video tags with the video-js class
        getVideoJSTags: function () {
            var videoTags = document.getElementsByTagName("video"),
    videoJSTags = [], videoTag;

            for (var i = 0, j = videoTags.length; i < j; i++) {
                videoTag = videoTags[i];
                if (videoTag.className.indexOf("video-js") != -1) {
                    videoJSTags.push(videoTag);
                }
            }
            return videoJSTags;
        },

        // Check if the browser supports video.
        browserSupportsVideo: function () {
            if (typeof VideoJS.videoSupport != "undefined") { return VideoJS.videoSupport; }
            VideoJS.videoSupport = !!document.createElement('video').canPlayType;

            if ($j('html').hasClass('mot_ie')) VideoJS.videoSupport = false; // forces IE9 to use flowplayer

            return VideoJS.videoSupport;
        },

        getFlashVersion: function () {
            // Cache Version
            if (typeof VideoJS.flashVersion != "undefined") { return VideoJS.flashVersion; }
            var version = 0, desc;
            if (typeof navigator.plugins != "undefined" && typeof navigator.plugins["Shockwave Flash"] == "object") {
                desc = navigator.plugins["Shockwave Flash"].description;
                if (desc && !(typeof navigator.mimeTypes != "undefined" && navigator.mimeTypes["application/x-shockwave-flash"] && !navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin)) {
                    version = parseInt(desc.match(/^.*\s+([^\s]+)\.[^\s]+\s+[^\s]+$/)[1], 10);
                }
            } else if (typeof window.ActiveXObject != "undefined") {
                try {
                    var testObject = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
                    if (testObject) {
                        version = parseInt(testObject.GetVariable("$version").match(/^[^\s]+\s(\d+)/)[1], 10);
                    }
                }
                catch (e) { }
            }
            VideoJS.flashVersion = version;
            return VideoJS.flashVersion;
        },

        // Browser & Device Checks
        isIE: function () { return ! +"\v1"; },
        isIPad: function () { return navigator.userAgent.match(/iPad/i) !== null; },
        isIPhone: function () { return navigator.userAgent.match(/iPhone/i) !== null; },
        isIOS: function () { return VideoJS.isIPhone() || VideoJS.isIPad(); },
        iOSVersion: function () {
            var match = navigator.userAgent.match(/OS (\d+)_/i);
            if (match && match[1]) { return match[1]; }
        },
        isAndroid: function () { return navigator.userAgent.match(/Android/i) !== null; },
        androidVersion: function () {
            var match = navigator.userAgent.match(/Android (\d+)\./i);
            if (match && match[1]) { return match[1]; }
        },

        warnings: {
            // Safari errors if you call functions on a video that hasn't loaded yet
            videoNotReady: "Video is not ready yet (try playing the video first).",
            // Getting a QUOTA_EXCEEDED_ERR when setting local storage occasionally
            localStorageFull: "Local Storage is Full"
        }
    });

    // Shim to make Video tag valid in IE
    if (VideoJS.isIE()) { document.createElement("video"); }

    // Expose to global
    window.VideoJS = window._V_ = VideoJS;

    /* HTML5 Player Type
    ================================================================================ */
    VideoJS.player.extend({
        html5Supported: function () {
            if (VideoJS.browserSupportsVideo() && this.canPlaySource()) {
                return true;
            } else {
                return false;
            }
        },
        html5Init: function () {
            this.element = this.video;

            this.fixPreloading(); // Support old browsers that used autobuffer
            this.supportProgressEvents(); // Support browsers that don't use 'buffered'

            // Set to stored volume OR 85%
            this.volume((localStorage && localStorage.volume) || this.options.defaultVolume);

            // Update interface for device needs
            if (VideoJS.isIOS()) {
                this.options.useBuiltInControls = true;
                this.iOSInterface();
            } else if (VideoJS.isAndroid()) {
                this.options.useBuiltInControls = true;
                this.androidInterface();
            }

            // Add VideoJS Controls
            if (!this.options.useBuiltInControls) {
                this.video.controls = false;

                if (this.options.controlsBelow) { _V_.addClass(this.box, "vjs-controls-below"); }

                // Make a click on th video act as a play button
                this.activateElement(this.video, "playToggle");


                // Build Interface
                this.buildStylesCheckDiv(); // Used to check if style are loaded
                this.buildAndActivatePoster();
                this.buildBigPlayButton();
                this.buildAndActivateSpinner();
                this.buildAndActivateControlBar();
                this.loadInterface(); // Show everything once styles are loaded
                this.getSubtitles();
            }
        },
        /* Source Managemet
        ================================================================================ */
        canPlaySource: function () {
            // Cache Result
            if (this.canPlaySourceResult) { return this.canPlaySourceResult; }
            // Loop through sources and check if any can play
            var children = this.video.children;
            for (var i = 0, j = children.length; i < j; i++) {
                if (children[i].tagName.toUpperCase() == "SOURCE") {
                    return true;
                    var canPlay = this.video.canPlayType(children[i].type) || this.canPlayExt(children[i].src);
                    if (canPlay == "probably" || canPlay == "maybe") {
                        this.firstPlayableSource = children[i];
                        this.canPlaySourceResult = true;
                        return true;
                    }
                }
            }
            this.canPlaySourceResult = false;
            return false;
        },
        // Check if the extention is compatible, for when type won't work
        canPlayExt: function (src) {
            if (!src) { return ""; }
            var match = src.match(/\.([^\.]+)$/);
            if (match && match[1]) {
                var ext = match[1].toLowerCase();
                // Android canPlayType doesn't work
                if (VideoJS.isAndroid()) {
                    if (ext == "mp4" || ext == "m4v") { return "maybe"; }
                    // Allow Apple HTTP Streaming for iOS
                } else if (VideoJS.isIOS()) {
                    if (ext == "m3u8") { return "maybe"; }
                }
            }
            return "";
        },
        // Force the video source - Helps fix loading bugs in a handful of devices, like the iPad/iPhone poster bug
        // And iPad/iPhone javascript include location bug. And Android type attribute bug
        forceTheSource: function () {
            this.video.src = this.firstPlayableSource.src; // From canPlaySource()
            this.video.load();
        },
        /* Device Fixes
        ================================================================================ */
        // Support older browsers that used "autobuffer"
        fixPreloading: function () {
            if (typeof this.video.hasAttribute == "function" && this.video.hasAttribute("preload") && this.video.preload != "none") {
                this.video.autobuffer = true; // Was a boolean
            } else {
                this.video.autobuffer = false;
                this.video.preload = "none";
            }
        },

        // Listen for Video Load Progress (currently does not if html file is local)
        // Buffered does't work in all browsers, so watching progress as well
        supportProgressEvents: function (e) {
            _V_.addListener(this.video, 'progress', this.playerOnVideoProgress.context(this));
        },
        playerOnVideoProgress: function (event) {
            this.setBufferedFromProgress(event);
        },
        setBufferedFromProgress: function (event) { // HTML5 Only
            if (event.total > 0) {
                var newBufferEnd = (event.loaded / event.total) * this.duration();
                if (newBufferEnd > this.values.bufferEnd) { this.values.bufferEnd = newBufferEnd; }
            }
        },

        iOSInterface: function () {
            if (VideoJS.iOSVersion() < 4) { this.forceTheSource(); } // Fix loading issues
            if (VideoJS.isIPad()) { // iPad could work with controlsBelow
                this.buildAndActivateSpinner(); // Spinner still works well on iPad, since iPad doesn't have one
            }
        },

        // Fix android specific quirks
        // Use built-in controls, but add the big play button, since android doesn't have one.
        androidInterface: function () {
            this.forceTheSource(); // Fix loading issues
            _V_.addListener(this.video, "click", function () { this.play(); }); // Required to play
            this.buildBigPlayButton(); // But don't activate the normal way. Pause doesn't work right on android.
            _V_.addListener(this.bigPlayButton, "click", function () { this.play(); } .context(this));
            this.positionBox();
            this.showBigPlayButtons();
        },
        /* Wait for styles (TODO: move to _V_)
        ================================================================================ */
        loadInterface: function () {
            if (!this.stylesHaveLoaded()) {
                // Don't want to create an endless loop either.
                if (!this.positionRetries) { this.positionRetries = 1; }
                if (this.positionRetries++ < 100) {
                    setTimeout(this.loadInterface.context(this), 10);
                    return;
                }
            }
            this.hideStylesCheckDiv();
            //this.showPoster();
            if (this.video.paused !== false) { this.showPoster(); }
            if (this.video.paused !== false) { this.showBigPlayButtons(); }
            if (this.options.controlsAtStart) { this.showControlBars(); }
            this.positionAll();
        },
        /* Control Bar
        ================================================================================ */
        buildAndActivateControlBar: function () {
            /* Creating this HTML
            <div class="vjs-controls">
            <div class="vjs-play-control">
            <span></span>
            </div>
            <div class="vjs-progress-control">
            <div class="vjs-progress-holder">
            <div class="vjs-load-progress"></div>
            <div class="vjs-play-progress"></div>
            </div>
            </div>
            <div class="vjs-time-control">
            <span class="vjs-current-time-display">00:00</span><span> / </span><span class="vjs-duration-display">00:00</span>
            </div>
            <div class="vjs-volume-control">
            <div>
            <span></span><span></span><span></span><span></span><span></span><span></span>
            </div>
            </div>
            <div class="vjs-fullscreen-control">
            <div>
            <span></span><span></span><span></span><span></span>
            </div>
            </div>
            </div>
            */

            // Create a div to hold the different controls
            $j('.vjs-controls').remove();
            this.controls = _V_.createElement("div", { className: "vjs-controls" });
            // Add the controls to the video's container
            this.box.appendChild(this.controls);
            this.activateElement(this.controls, "controlBar");
            this.activateElement(this.controls, "mouseOverVideoReporter");

            // Build the play control
            this.playControl = _V_.createElement("div", { className: "vjs-play-control", innerHTML: "<span></span>" });
            this.controls.appendChild(this.playControl);
            this.activateElement(this.playControl, "playToggle");

            // Build the video title display
            this.playControl = _V_.createElement("div", { className: "vjs-video-title", innerHTML: "<span id='mot-video-title'>" + this.video.title + "</span>" });
            this.controls.appendChild(this.playControl);
            this.video.title = "";

            // Build the share video button
            if (this.options.shareButton) {


                var shareLink = document.createElement('a');
                shareLink.innerHTML = this.options.shareLabel;

                this.playControl = _V_.createElement("div", { className: "vjs-video-share" });
                this.controls.appendChild(this.playControl);
                this.playControl.appendChild(shareLink);
            }
            // Build the progress control
            this.progressControl = _V_.createElement("div", { className: "vjs-progress-control", width: "100px" });
            this.controls.appendChild(this.progressControl);

            //this.video.width



            // Create a holder for the progress bars
            this.progressHolder = _V_.createElement("div", { className: "vjs-progress-holder" });
            this.progressControl.appendChild(this.progressHolder);
            this.activateElement(this.progressHolder, "currentTimeScrubber");

            // Create the loading progress display
            this.loadProgressBar = _V_.createElement("div", { className: "vjs-load-progress" });
            this.progressHolder.appendChild(this.loadProgressBar);
            this.activateElement(this.loadProgressBar, "loadProgressBar");

            // Create the playing progress display
            this.playProgressBar = _V_.createElement("div", { className: "vjs-play-progress" });
            this.progressHolder.appendChild(this.playProgressBar);
            this.activateElement(this.playProgressBar, "playProgressBar");

            // Create the progress time display (00:00 / 00:00)
            this.timeControl = _V_.createElement("div", { className: "vjs-time-control" });
            this.controls.appendChild(this.timeControl);

            // Create the current play time display
            this.currentTimeDisplay = _V_.createElement("span", { className: "vjs-current-time-display", innerHTML: "00:00" });
            this.timeControl.appendChild(this.currentTimeDisplay);
            this.activateElement(this.currentTimeDisplay, "currentTimeDisplay");

            // Add time separator
            this.timeSeparator = _V_.createElement("span", { innerHTML: " / " });
            this.timeControl.appendChild(this.timeSeparator);

            // Create the total duration display
            this.durationDisplay = _V_.createElement("span", { className: "vjs-duration-display", innerHTML: "00:00" });
            this.timeControl.appendChild(this.durationDisplay);
            this.activateElement(this.durationDisplay, "durationDisplay");

            // Create the volumne control
            this.volumeControl = _V_.createElement("div", {
                className: "vjs-volume-control",
                innerHTML: "<div><span></span><span></span><span></span><span></span><span></span><span></span></div>"
            });
            this.controls.appendChild(this.volumeControl);
            this.activateElement(this.volumeControl, "volumeScrubber");

            this.volumeDisplay = this.volumeControl.children[0];
            this.activateElement(this.volumeDisplay, "volumeDisplay");

            // Create the fullscreen control
            this.fullscreenControl = _V_.createElement("div", {
                className: "vjs-fullscreen-control",
                innerHTML: "<div><span></span><span></span><span></span><span></span></div>"
            });
            this.controls.appendChild(this.fullscreenControl);
            this.activateElement(this.fullscreenControl, "fullscreenToggle");
        },
        /* Poster Image
        ================================================================================ */
        buildAndActivatePoster: function () {
            this.updatePosterSource();
            if (this.video.poster) {
                this.poster = document.createElement("img");
                // Add poster to video box
                this.box.appendChild(this.poster);

                // Add poster image data
                this.poster.src = this.video.poster;
                // Add poster styles
                this.poster.className = "vjs-poster";
                this.activateElement(this.poster, "poster");
            } else {
                this.poster = false;
            }
        },
        /* Big Play Button
        ================================================================================ */
        buildBigPlayButton: function () {
            /* Creating this HTML
            <div class="vjs-big-play-button"><span></span></div>
            */
            this.bigPlayButton = _V_.createElement("div", {
                className: "vjs-big-play-button",
                innerHTML: "<span></span>"
            });
            this.box.appendChild(this.bigPlayButton);
            this.activateElement(this.bigPlayButton, "bigPlayButton");
        },
        /* Spinner (Loading)
        ================================================================================ */
        buildAndActivateSpinner: function () {
            this.spinner = _V_.createElement("div", {
                className: "vjs-spinner",
                innerHTML: "<div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div>"
            });
            this.box.appendChild(this.spinner);
            this.activateElement(this.spinner, "spinner");
        },
        /* Styles Check - Check if styles are loaded (move ot _V_)
        ================================================================================ */
        // Sometimes the CSS styles haven't been applied to the controls yet
        // when we're trying to calculate the height and position them correctly.
        // This causes a flicker where the controls are out of place.
        buildStylesCheckDiv: function () {
            this.stylesCheckDiv = _V_.createElement("div", { className: "vjs-styles-check" });
            this.stylesCheckDiv.style.position = "absolute";
            this.box.appendChild(this.stylesCheckDiv);
        },
        hideStylesCheckDiv: function () { this.stylesCheckDiv.style.display = "none"; },
        stylesHaveLoaded: function () {
            if (this.stylesCheckDiv.offsetHeight != 5) {
                return false;
            } else {
                return true;
            }
        },
        /* VideoJS Box - Holds all elements
        ================================================================================ */
        positionAll: function () {
            this.positionBox();
            this.positionControlBars();
            this.positionPoster();
        },
        positionBox: function () {
            // Set width based on fullscreen or not.
            if (this.videoIsFullScreen) {
                this.box.style.width = "";
                this.element.style.height = "";
                if (this.options.controlsBelow) {
                    this.box.style.height = "";
                    this.element.style.height = (this.box.offsetHeight - this.controls.offsetHeight) + "px";
                }
            } else {
                this.box.style.width = this.width() + "px";
                this.element.style.height = this.height() + "px";
                if (this.options.controlsBelow) {
                    this.element.style.height = "";
                    // this.box.style.height = this.video.offsetHeight + this.controls.offsetHeight + "px";
                }
            }
        },
        /* Subtitles
        ================================================================================ */
        getSubtitles: function () {
            var tracks = this.video.getElementsByTagName("TRACK");
            for (var i = 0, j = tracks.length; i < j; i++) {
                if (tracks[i].getAttribute("kind") == "subtitles" && tracks[i].getAttribute("src")) {
                    this.subtitlesSource = tracks[i].getAttribute("src");
                    this.loadSubtitles();
                    this.buildSubtitles();
                }
            }
        },
        loadSubtitles: function () { _V_.get(this.subtitlesSource, this.parseSubtitles.context(this)); },
        parseSubtitles: function (subText) {
            var lines = subText.split("\n"),
        line = "",
        subtitle, time, text;
            this.subtitles = [];
            this.currentSubtitle = false;
            this.lastSubtitleIndex = 0;

            for (var i = 0; i < lines.length; i++) {
                line = _V_.trim(lines[i]); // Trim whitespace and linebreaks
                if (line) { // Loop until a line with content

                    // First line - Number
                    subtitle = {
                        id: line, // Subtitle Number
                        index: this.subtitles.length // Position in Array
                    };

                    // Second line - Time
                    line = _V_.trim(lines[++i]);
                    time = line.split(" --> ");
                    subtitle.start = this.parseSubtitleTime(time[0]);
                    subtitle.end = this.parseSubtitleTime(time[1]);

                    // Additional lines - Subtitle Text
                    text = [];
                    for (var j = i; j < lines.length; j++) { // Loop until a blank line or end of lines
                        line = _V_.trim(lines[++i]);
                        if (!line) { break; }
                        text.push(line);
                    }
                    subtitle.text = text.join('<br/>');

                    // Add this subtitle
                    this.subtitles.push(subtitle);
                }
            }
        },

        parseSubtitleTime: function (timeText) {
            var parts = timeText.split(':'),
        time = 0;
            // hours => seconds
            time += parseFloat(parts[0]) * 60 * 60;
            // minutes => seconds
            time += parseFloat(parts[1]) * 60;
            // get seconds
            var seconds = parts[2].split(/\.|,/); // Either . or ,
            time += parseFloat(seconds[0]);
            // add miliseconds
            ms = parseFloat(seconds[1]);
            if (ms) { time += ms / 1000; }
            return time;
        },

        buildSubtitles: function () {
            /* Creating this HTML
            <div class="vjs-subtitles"></div>
            */
            this.subtitlesDisplay = _V_.createElement("div", { className: 'vjs-subtitles' });
            this.box.appendChild(this.subtitlesDisplay);
            this.activateElement(this.subtitlesDisplay, "subtitlesDisplay");
        },

        /* Player API - Translate functionality from player to video
        ================================================================================ */
        addVideoListener: function (type, fn) { _V_.addListener(this.video, type, fn.rEvtContext(this)); },

        play: function () {
            if (this.video) {
                this.video.play();
                if (!this.hasStarted) {
                    this.options.onStart();
                    this.hasStarted = true;
                }
            }
            return this;
        },
        onPlay: function (fn) { this.addVideoListener("play", fn); return this; },

        pause: function () {
            this.video.pause();
            return this;
        },
        onPause: function (fn) { this.addVideoListener("pause", fn); return this; },
        paused: function () { return this.video.paused; },

        currentTime: function (seconds) {
            if (seconds !== undefined) {
                try { this.video.currentTime = seconds; }
                catch (e) { this.warning(VideoJS.warnings.videoNotReady); }
                this.values.currentTime = seconds;
                return this;
            }
            return this.video.currentTime;
        },
        onCurrentTimeUpdate: function (fn) {
            this.currentTimeListeners.push(fn);
        },

        duration: function () {
            return this.video.duration;
        },

        buffered: function () {
            // Storing values allows them be overridden by setBufferedFromProgress
            if (this.values.bufferStart === undefined) {
                this.values.bufferStart = 0;
                this.values.bufferEnd = 0;
            }
            if (this.video.buffered && this.video.buffered.length > 0) {
                var newEnd = this.video.buffered.end(0);
                if (newEnd > this.values.bufferEnd) { this.values.bufferEnd = newEnd; }
            }
            return [this.values.bufferStart, this.values.bufferEnd];
        },

        volume: function (percentAsDecimal) {
            if (percentAsDecimal !== undefined) {
                // Force value to between 0 and 1
                this.values.volume = Math.max(0, Math.min(1, parseFloat(percentAsDecimal)));
                try {
                    this.video.volume = this.values.volume;
                } catch (e) { }
                this.setLocalStorage("volume", this.values.volume);
                return this;
            }
            if (this.values.volume) { return this.values.volume; }
            return this.video.volume;
        },
        onVolumeChange: function (fn) { _V_.addListener(this.video, 'volumechange', fn.rEvtContext(this)); },

        width: function (width) {
            if (width !== undefined) {
                this.video.width = width; // Not using style so it can be overridden on fullscreen.
                this.box.style.width = width + "px";
                this.triggerResizeListeners();
                return this;
            }
            return this.video.offsetWidth;
        },
        height: function (height) {
            if (height !== undefined) {
                this.video.height = height;
                this.box.style.height = height + "px";
                this.triggerResizeListeners();
                return this;
            }
            return this.video.offsetHeight;
        },

        supportsFullScreen: function () {
            if (typeof this.video.webkitEnterFullScreen == 'function') {
                // Seems to be broken in Chromium/Chrome
                if (!navigator.userAgent.match("Chrome") && !navigator.userAgent.match("Mac OS X 10.5")) {
                    return true;
                }
            }
            return false;
        },

        html5EnterNativeFullScreen: function () {
            try {
                this.video.webkitEnterFullScreen();
            } catch (e) {
                if (e.code == 11) { this.warning(VideoJS.warnings.videoNotReady); }
            }
            return this;
        },

        // Turn on fullscreen (window) mode
        // Real fullscreen isn't available in browsers quite yet.
        enterFullScreen: function () {
            if (this.supportsFullScreen()) {
                this.html5EnterNativeFullScreen();
                $j(document).unbind('webkitfullscreenchange', _checkWebkitFullscreenChange);
                $j(document).bind('webkitfullscreenchange', _checkWebkitFullscreenChange);
            } else {
                this.enterFullWindow();
            }
            $j(document).motPopup('disableEscapeKey');

        },

        exitFullScreen: function () {
            if (this.supportsFullScreen()) {
                // Shouldn't be called
            } else {
                this.exitFullWindow();
            }
            setTimeout(function () { $j(document).motPopup('enableEscapeKey'); }, 400);

            setTimeout($j.proxy(function () { $j(window).trigger('scroll'); }, this), 200);
            setTimeout($j.proxy(function () { $j(window).trigger('scroll'); }, this), 450);
            setTimeout($j.proxy(function () { $j(window).trigger('scroll'); }, this), 800);
        },
        _checkWebkitFullscreenChange: function () {
            if (document.webkitIsFullScreen) {
                $j(document).motPopup('disableEscapeKey');
            } else {
                $j(document).motPopup('enableEscapeKey');
            }
        },
        enterFullWindow: function () {
            this.videoIsFullScreen = true;
            // Stores the original popup width before fullscreen is set
            this.origPopupWidth = $j(this.box).parent().width();
            // Storing original doc overflow value to return to when fullscreen is off
            this.docOrigOverflow = document.documentElement.style.overflow;
            //if (this.docOrigOverflow == "") this.docOrigOverflow = "auto";
            // Add listener for esc key to exit fullscreen
            _V_.addListener(document, "keydown", this.fullscreenOnEscKey.rEvtContext(this));
            // Add listener for a window resize
            _V_.addListener(window, "resize", this.fullscreenOnWindowResize.rEvtContext(this));
            // Hide any scroll bars
            document.documentElement.style.overflow = 'hidden';
            // Apply fullscreen styles
            _V_.addClass(this.box, "vjs-fullscreen");
            $j(".vjs-fullscreen-control div").addClass('fullscreenOn');
            // Resize the box, controller, and poster
            this.positionAll();

            //alert($j('.vjs-controls').width() + " - " + $j('.vjs-progress-control').width() + " = " + ($j('.vjs-controls').width() - $j('.vjs-progress-control').width()));
            var controlElementsWidth = 300;
            var trackbarW = $j('.vjs-controls').width() - controlElementsWidth;
            if (this.options.shareButton) {
                $j('.vjs-progress-control').width(trackbarW - 100);
            } else {
                $j('.vjs-progress-control').width(trackbarW);
            }
        },

        // Turn off fullscreen (window) mode
        exitFullWindow: function () {
            this.videoIsFullScreen = false;
            document.removeEventListener("keydown", this.fullscreenOnEscKey, false);
            window.removeEventListener("resize", this.fullscreenOnWindowResize, false);
            // Unhide scroll bars.
            document.documentElement.style.overflow = this.docOrigOverflow;
            // Restores original popup width before fullscreen
            $j(this.box).parent().width(this.origPopupWidth);
            // Remove fullscreen styles
            _V_.removeClass(this.box, "vjs-fullscreen");
            $j(".vjs-fullscreen-control div").removeClass('fullscreenOn');
            // Resize the box, controller, and poster to original sizes
            this.positionAll();
            // Adjusts popup to be centered
            setTimeout($j.proxy(function () { $j("body").trigger('scroll'); }, this), 200);
        },

        onError: function (fn) { this.addVideoListener("error", fn); return this; },
        onEnded: function (fn) {
            this.addVideoListener("ended", fn); return this;
        }
    });

    ////////////////////////////////////////////////////////////////////////////////
    // Element Behaviors
    // Tell elements how to act or react
    ////////////////////////////////////////////////////////////////////////////////

    /* Player Behaviors - How VideoJS reacts to what the video is doing.
    ================================================================================ */
    VideoJS.player.newBehavior("player", function (player) {
        this.onError(this.playerOnVideoError);
        // Listen for when the video is played
        this.onPlay(this.playerOnVideoPlay);
        this.onPlay(this.trackCurrentTime);
        // Listen for when the video is paused
        this.onPause(this.playerOnVideoPause);
        this.onPause(this.stopTrackingCurrentTime);
        // Listen for when the video ends
        this.onEnded(this.playerOnVideoEnded);
        // Set interval for load progress using buffer watching method
        // this.trackCurrentTime();
        this.trackBuffered();
        // Buffer Full
        this.onBufferedUpdate(this.isBufferFull);
    }, {
        playerOnVideoError: function (event) {
            this.log(event);
            this.log(this.video.error);
        },
        playerOnVideoPlay: function (event) { this.hasPlayed = true; },
        playerOnVideoPause: function (event) { },
        playerOnVideoEnded: function (event) {
            this.currentTime(0);
            this.pause();
            if (!this.hasCompleted) {
                this.options.onComplete();
                this.hasCompleted = true;
            }
        },

        /* Load Tracking -------------------------------------------------------------- */
        // Buffer watching method for load progress.
        // Used for browsers that don't support the progress event
        trackBuffered: function () {
            this.bufferedInterval = setInterval(this.triggerBufferedListeners.context(this), 500);
        },
        stopTrackingBuffered: function () { clearInterval(this.bufferedInterval); },
        bufferedListeners: [],
        onBufferedUpdate: function (fn) {
            this.bufferedListeners.push(fn);
        },
        triggerBufferedListeners: function () {
            this.isBufferFull();
            this.each(this.bufferedListeners, function (listener) {
                (listener.context(this))();
            });
        },
        isBufferFull: function () {
            if (this.bufferedPercent() == 1) { this.stopTrackingBuffered(); }
        },

        /* Time Tracking -------------------------------------------------------------- */
        trackCurrentTime: function () {
            if (this.currentTimeInterval) { clearInterval(this.currentTimeInterval); }
            this.currentTimeInterval = setInterval(this.triggerCurrentTimeListeners.context(this), 100); // 42 = 24 fps
            this.trackingCurrentTime = true;
        },
        // Turn off play progress tracking (when paused or dragging)
        stopTrackingCurrentTime: function () {
            clearInterval(this.currentTimeInterval);
            this.trackingCurrentTime = false;
        },
        currentTimeListeners: [],
        // onCurrentTimeUpdate is in API section now
        triggerCurrentTimeListeners: function (late, newTime) { // FF passes milliseconds late as the first argument
            this.each(this.currentTimeListeners, function (listener) {
                (listener.context(this))(newTime || this.currentTime());
            });
        },

        /* Resize Tracking -------------------------------------------------------------- */
        resizeListeners: [],
        onResize: function (fn) {
            this.resizeListeners.push(fn);
        },
        // Trigger anywhere the video/box size is changed.
        triggerResizeListeners: function () {
            this.each(this.resizeListeners, function (listener) {
                (listener.context(this))();
            });
        }
    }
);
    /* Mouse Over Video Reporter Behaviors - i.e. Controls hiding based on mouse location
    ================================================================================ */
    VideoJS.player.newBehavior("mouseOverVideoReporter", function (element) {
        // Listen for the mouse move the video. Used to reveal the controller.
        _V_.addListener(element, "mousemove", this.mouseOverVideoReporterOnMouseMove.context(this));
        // Listen for the mouse moving out of the video. Used to hide the controller.
        _V_.addListener(element, "mouseout", this.mouseOverVideoReporterOnMouseOut.context(this));
    }, {
        mouseOverVideoReporterOnMouseMove: function () {
            this.showControlBars();
            clearInterval(this.mouseMoveTimeout);
            this.mouseMoveTimeout = setTimeout(this.hideControlBars.context(this), 4000);
        },
        mouseOverVideoReporterOnMouseOut: function (event) {
            // Prevent flicker by making sure mouse hasn't left the video
            var parent = event.relatedTarget;
            while (parent && parent !== this.box) {
                parent = parent.parentNode;
            }
            if (parent !== this.box) {
                this.hideControlBars();
            }
        }
    }
);
    /* Mouse Over Video Reporter Behaviors - i.e. Controls hiding based on mouse location
    ================================================================================ */
    VideoJS.player.newBehavior("box", function (element) {
        this.positionBox();
        _V_.addClass(element, "vjs-paused");
        this.activateElement(element, "mouseOverVideoReporter");
        this.onPlay(this.boxOnVideoPlay);
        this.onPause(this.boxOnVideoPause);
    }, {
        boxOnVideoPlay: function () {
            _V_.removeClass(this.box, "vjs-paused");
            _V_.addClass(this.box, "vjs-playing");
        },
        boxOnVideoPause: function () {
            _V_.removeClass(this.box, "vjs-playing");
            _V_.addClass(this.box, "vjs-paused");
        }
    }
);
    /* Poster Image Overlay
    ================================================================================ */
    VideoJS.player.newBehavior("poster", function (element) {
        this.activateElement(element, "mouseOverVideoReporter");
        this.activateElement(element, "playButton");
        this.onPlay(this.hidePoster);
        this.onEnded(this.showPoster);
        this.onResize(this.positionPoster);
    }, {
        showPoster: function () {
            if (!this.poster) { return; }
            this.poster.style.display = "block";
            this.positionPoster();
        },
        positionPoster: function () {
            // Only if the poster is visible
            if (!this.poster || this.poster.style.display == 'none') { return; }
            this.poster.style.height = this.height() + "px"; // Need incase controlsBelow
            this.poster.style.width = this.width() + "px"; // Could probably do 100% of box
        },
        hidePoster: function () {
            if (!this.poster) { return; }
            this.poster.style.display = "none";
        },
        // Update poster source from attribute or fallback image
        // iPad breaks if you include a poster attribute, so this fixes that
        updatePosterSource: function () {
            if (!this.video.poster) {
                var images = this.video.getElementsByTagName("img");
                if (images.length > 0) { this.video.poster = images[0].src; }
            }
        }
    }
);
    /* Control Bar Behaviors
    ================================================================================ */
    VideoJS.player.newBehavior("controlBar", function (element) {
        if (!this.controlBars) {
            this.controlBars = [];
            this.onResize(this.positionControlBars);
        }
        this.controlBars.push(element);
        _V_.addListener(element, "mousemove", this.onControlBarsMouseMove.context(this));
        _V_.addListener(element, "mouseout", this.onControlBarsMouseOut.context(this));
    }, {
        showControlBars: function () {
            if (!this.options.controlsAtStart && !this.hasPlayed) { return; }
            this.each(this.controlBars, function (bar) {
                bar.style.display = "block";
            });
        },
        // Place controller relative to the video's position (now just resizing bars)
        positionControlBars: function () {
            this.updatePlayProgressBars();
            this.updateLoadProgressBars();
        },
        hideControlBars: function () {
            if (this.options.controlsHiding && !this.mouseIsOverControls) {
                this.each(this.controlBars, function (bar) {
                    bar.style.display = "none";
                });
            }
        },
        // Block controls from hiding when mouse is over them.
        onControlBarsMouseMove: function () { this.mouseIsOverControls = true; },
        onControlBarsMouseOut: function (event) {
            this.mouseIsOverControls = false;
        }
    }
);
    /* PlayToggle, PlayButton, PauseButton Behaviors
    ================================================================================ */
    // Play Toggle
    VideoJS.player.newBehavior("playToggle", function (element) {
        if (!this.elements.playToggles) {
            this.elements.playToggles = [];
            this.onPlay(this.playTogglesOnPlay);
            this.onPause(this.playTogglesOnPause);
        }
        this.elements.playToggles.push(element);
        _V_.addListener(element, "click", this.onPlayToggleClick.context(this));
    }, {
        onPlayToggleClick: function (event) {
            if (this.paused()) {
                this.hideBigPlayButtons();
                this.play();
            } else {
                this.pause();
            }
        },
        playTogglesOnPlay: function (event) {
            this.each(this.elements.playToggles, function (toggle) {
                _V_.removeClass(toggle, "vjs-paused");
                _V_.addClass(toggle, "vjs-playing");
            });
        },
        playTogglesOnPause: function (event) {
            this.each(this.elements.playToggles, function (toggle) {
                _V_.removeClass(toggle, "vjs-playing");
                _V_.addClass(toggle, "vjs-paused");
            });
        }
    }
);
    // Play
    VideoJS.player.newBehavior("playButton", function (element) {
        _V_.addListener(element, "click", this.onPlayButtonClick.context(this));
    }, {
        onPlayButtonClick: function (event) { this.play(); }
    }
);
    // Pause
    VideoJS.player.newBehavior("pauseButton", function (element) {
        _V_.addListener(element, "click", this.onPauseButtonClick.context(this));
    }, {
        onPauseButtonClick: function (event) { this.pause(); }
    }
);
    /* Play Progress Bar Behaviors
    ================================================================================ */
    VideoJS.player.newBehavior("playProgressBar", function (element) {
        if (!this.playProgressBars) {
            this.playProgressBars = [];
            this.onCurrentTimeUpdate(this.updatePlayProgressBars);
        }
        this.playProgressBars.push(element);
    }, {
        // Ajust the play progress bar's width based on the current play time
        updatePlayProgressBars: function (newTime) {
            var progress = (newTime !== undefined) ? newTime / this.duration() : this.currentTime() / this.duration();
            if (isNaN(progress)) { progress = 0; }
            this.each(this.playProgressBars, function (bar) {
                // auto-adjusts the progress bar width according to the video width
                var barWidth;
                if (this.videoIsFullScreen) {
                    barWidth = document.width - 325; // subtract the width of the controls
                } else {
                    barWidth = this.video.width - 300; // subtract the width of the controls
                }
                if (this.options.shareButton) {
                    barWidth = barWidth - 100;
                }
                bar.parentNode.parentNode.style.width = barWidth + "px";
                this.progressBar = bar.parentNode.parentNode;
                if (bar.style) { bar.style.width = _V_.round(progress * 100, 2) + "%"; }
            });
        }
    }
);
    /* Load Progress Bar Behaviors
    ================================================================================ */
    VideoJS.player.newBehavior("loadProgressBar", function (element) {
        if (!this.loadProgressBars) { this.loadProgressBars = []; }
        this.loadProgressBars.push(element);
        this.onBufferedUpdate(this.updateLoadProgressBars);
    }, {
        updateLoadProgressBars: function () {
            this.each(this.loadProgressBars, function (bar) {
                if (bar.style) { bar.style.width = _V_.round(this.bufferedPercent() * 100, 2) + "%"; }
            });
        }
    }
);

    /* Current Time Display Behaviors
    ================================================================================ */
    VideoJS.player.newBehavior("currentTimeDisplay", function (element) {
        if (!this.currentTimeDisplays) {
            this.currentTimeDisplays = [];
            this.onCurrentTimeUpdate(this.updateCurrentTimeDisplays);
        }
        this.currentTimeDisplays.push(element);
    }, {
        // Update the displayed time (00:00)
        updateCurrentTimeDisplays: function (newTime) {
            if (!this.currentTimeDisplays) { return; }
            // Allows for smooth scrubbing, when player can't keep up.
            var time = (newTime) ? newTime : this.currentTime();
            this.each(this.currentTimeDisplays, function (dis) {
                dis.innerHTML = _V_.formatTime(time);
                // auto-adjusts the timecode if there is a share button
                if (this.options.shareButton) {
                    dis.parentNode.style.right = "200px";
                }
            });
        }
    }
);

    /* Duration Display Behaviors
    ================================================================================ */
    VideoJS.player.newBehavior("durationDisplay", function (element) {
        if (!this.durationDisplays) {
            this.durationDisplays = [];
            this.onCurrentTimeUpdate(this.updateDurationDisplays);
        }
        this.durationDisplays.push(element);
    }, {
        updateDurationDisplays: function () {
            if (!this.durationDisplays) { return; }
            this.each(this.durationDisplays, function (dis) {
                if (this.duration()) { dis.innerHTML = _V_.formatTime(this.duration()); }
            });
        }
    }
);

    /* Current Time Scrubber Behaviors
    ================================================================================ */
    VideoJS.player.newBehavior("currentTimeScrubber", function (element) {
        _V_.addListener(element, "mousedown", this.onCurrentTimeScrubberMouseDown.rEvtContext(this));
    }, {
        // Adjust the play position when the user drags on the progress bar
        onCurrentTimeScrubberMouseDown: function (event, scrubber) {
            event.preventDefault();
            this.currentScrubber = scrubber;

            this.stopTrackingCurrentTime(); // Allows for smooth scrubbing

            this.videoWasPlaying = !this.paused();
            this.pause();

            _V_.blockTextSelection();
            this.setCurrentTimeWithScrubber(event);
            _V_.addListener(document, "mousemove", this.onCurrentTimeScrubberMouseMove.rEvtContext(this));
            _V_.addListener(document, "mouseup", this.onCurrentTimeScrubberMouseUp.rEvtContext(this));
        },
        onCurrentTimeScrubberMouseMove: function (event) { // Removeable
            this.setCurrentTimeWithScrubber(event);
        },
        onCurrentTimeScrubberMouseUp: function (event) { // Removeable
            _V_.unblockTextSelection();
            document.removeEventListener("mousemove", this.onCurrentTimeScrubberMouseMove, false);
            document.removeEventListener("mouseup", this.onCurrentTimeScrubberMouseUp, false);
            if (this.videoWasPlaying) {
                this.play();
                this.trackCurrentTime();
            }
        },
        setCurrentTimeWithScrubber: function (event) {
            var newProgress = _V_.getRelativePosition(event.pageX, this.currentScrubber);
            var newTime = newProgress * this.duration();
            this.triggerCurrentTimeListeners(0, newTime); // Allows for smooth scrubbing
            // Don't let video end while scrubbing.
            if (newTime == this.duration()) { newTime = newTime - 0.1; }
            this.currentTime(newTime);
        }
    }
);
    /* Volume Display Behaviors
    ================================================================================ */
    VideoJS.player.newBehavior("volumeDisplay", function (element) {
        if (!this.volumeDisplays) {
            this.volumeDisplays = [];
            this.onVolumeChange(this.updateVolumeDisplays);
        }
        this.volumeDisplays.push(element);
        this.updateVolumeDisplay(element); // Set the display to the initial volume
    }, {
        // Update the volume control display
        // Unique to these default controls. Uses borders to create the look of bars.
        updateVolumeDisplays: function () {
            // mute implementation
            var element = this.volumeDisplays[0];
            if (this.volume() == 0) {
                element.className = "muted";
            } else {
                element.className = "";
            }
            return;

            // default implementation
            if (!this.volumeDisplays) { return; }
            this.each(this.volumeDisplays, function (dis) {
                this.updateVolumeDisplay(dis);
            });
        },
        updateVolumeDisplay: function (display) {
            return; //removes volume display bar

            var volNum = Math.ceil(this.volume() * 6);
            this.each(display.children, function (child, num) {
                if (num < volNum) {
                    _V_.addClass(child, "vjs-volume-level-on");
                } else {
                    _V_.removeClass(child, "vjs-volume-level-on");
                }
            });
        }
    }
);
    /* Volume Scrubber Behaviors
    ================================================================================ */
    VideoJS.player.newBehavior("volumeScrubber", function (element) {
        _V_.addListener(element, "mousedown", this.onVolumeScrubberMouseDown.rEvtContext(this));
    }, {
        // Adjust the volume when the user drags on the volume control
        onVolumeScrubberMouseDown: function (event, scrubber) {
            // mute implementation
            _V_.addListener(document, "mouseup", this.onVolumeScrubberMouseUp.rEvtContext(this));
            return;

            // default implementation
            // event.preventDefault();
            _V_.blockTextSelection();
            this.currentScrubber = scrubber;
            this.setVolumeWithScrubber(event);
            _V_.addListener(document, "mousemove", this.onVolumeScrubberMouseMove.rEvtContext(this));
            _V_.addListener(document, "mouseup", this.onVolumeScrubberMouseUp.rEvtContext(this));
        },
        onVolumeScrubberMouseMove: function (event) {
            return;
            this.setVolumeWithScrubber(event);
        },
        onVolumeScrubberMouseUp: function (event) {
            // mute implementation
            if (this.volume() == 1) {
                this.volume(0);
                //vjs-volume-control div
            } else {
                this.volume(1);
            }
            document.removeEventListener("mouseup", this.onVolumeScrubberMouseUp, false);
            return;

            // default implementation
            this.setVolumeWithScrubber(event);
            _V_.unblockTextSelection();
            document.removeEventListener("mousemove", this.onVolumeScrubberMouseMove, false);
            document.removeEventListener("mouseup", this.onVolumeScrubberMouseUp, false);
        },
        setVolumeWithScrubber: function (event) {
            var newVol = _V_.getRelativePosition(event.pageX, this.currentScrubber);
            this.volume(newVol);
        }
    }
);
    /* Fullscreen Toggle Behaviors
    ================================================================================ */
    VideoJS.player.newBehavior("fullscreenToggle", function (element) {
        _V_.addListener(element, "click", this.onFullscreenToggleClick.context(this));
    }, {
        // When the user clicks on the fullscreen button, update fullscreen setting
        onFullscreenToggleClick: function (event) {
            if (!this.videoIsFullScreen) {
                this.enterFullScreen();
            } else {
                this.exitFullScreen();
            }
        },

        fullscreenOnWindowResize: function (event) { // Removeable
            this.positionControlBars();
        },
        // Create listener for esc key while in full screen mode
        fullscreenOnEscKey: function (event) { // Removeable
            if (event.keyCode == 27) {
                this.exitFullScreen();
            }
        }
    }
);
    /* Big Play Button Behaviors
    ================================================================================ */
    VideoJS.player.newBehavior("bigPlayButton", function (element) {
        if (!this.elements.bigPlayButtons) {
            this.elements.bigPlayButtons = [];
            this.onPlay(this.bigPlayButtonsOnPlay);
            this.onEnded(this.bigPlayButtonsOnEnded);
        }
        this.elements.bigPlayButtons.push(element);
        this.activateElement(element, "playButton");
    }, {
        bigPlayButtonsOnPlay: function (event) { this.hideBigPlayButtons(); },
        bigPlayButtonsOnEnded: function (event) { this.showBigPlayButtons(); this.exitFullScreen(); },
        showBigPlayButtons: function () {
            this.each(this.elements.bigPlayButtons, function (element) {
                element.style.display = "block";
            });
        },
        hideBigPlayButtons: function () {
            this.each(this.elements.bigPlayButtons, function (element) {
                element.style.display = "none";
            });
        }
    }
);
    /* Spinner
    ================================================================================ */
    VideoJS.player.newBehavior("spinner", function (element) {
        if (!this.spinners) {
            this.spinners = [];
            _V_.addListener(this.video, "loadeddata", this.spinnersOnVideoLoadedData.context(this));
            _V_.addListener(this.video, "loadstart", this.spinnersOnVideoLoadStart.context(this));
            _V_.addListener(this.video, "seeking", this.spinnersOnVideoSeeking.context(this));
            _V_.addListener(this.video, "seeked", this.spinnersOnVideoSeeked.context(this));
            _V_.addListener(this.video, "canplay", this.spinnersOnVideoCanPlay.context(this));
            _V_.addListener(this.video, "canplaythrough", this.spinnersOnVideoCanPlayThrough.context(this));
            _V_.addListener(this.video, "waiting", this.spinnersOnVideoWaiting.context(this));
            _V_.addListener(this.video, "stalled", this.spinnersOnVideoStalled.context(this));
            _V_.addListener(this.video, "suspend", this.spinnersOnVideoSuspend.context(this));
            _V_.addListener(this.video, "playing", this.spinnersOnVideoPlaying.context(this));
            _V_.addListener(this.video, "timeupdate", this.spinnersOnVideoTimeUpdate.context(this));
        }
        this.spinners.push(element);
    }, {
        showSpinners: function () {
            this.each(this.spinners, function (spinner) {
                spinner.style.display = "block";
            });
            clearInterval(this.spinnerInterval);
            this.spinnerInterval = setInterval(this.rotateSpinners.context(this), 100);
        },
        hideSpinners: function () {
            this.each(this.spinners, function (spinner) {
                spinner.style.display = "none";
            });
            clearInterval(this.spinnerInterval);
        },
        spinnersRotated: 0,
        rotateSpinners: function () {
            this.each(this.spinners, function (spinner) {
                // spinner.style.transform =       'scale(0.5) rotate('+this.spinnersRotated+'deg)';
                spinner.style.WebkitTransform = 'scale(0.5) rotate(' + this.spinnersRotated + 'deg)';
                spinner.style.MozTransform = 'scale(0.5) rotate(' + this.spinnersRotated + 'deg)';
            });
            if (this.spinnersRotated == 360) { this.spinnersRotated = 0; }
            this.spinnersRotated += 45;
        },
        spinnersOnVideoLoadedData: function (event) { this.hideSpinners(); },
        spinnersOnVideoLoadStart: function (event) { this.showSpinners(); },
        spinnersOnVideoSeeking: function (event) { /* this.showSpinners(); */ },
        spinnersOnVideoSeeked: function (event) { /* this.hideSpinners(); */ },
        spinnersOnVideoCanPlay: function (event) { /* this.hideSpinners(); */ },
        spinnersOnVideoCanPlayThrough: function (event) { this.hideSpinners(); },
        spinnersOnVideoWaiting: function (event) {
            // Safari sometimes triggers waiting inappropriately
            // Like after video has played, any you play again.
            this.showSpinners();
        },
        spinnersOnVideoStalled: function (event) { },
        spinnersOnVideoSuspend: function (event) { },
        spinnersOnVideoPlaying: function (event) { this.hideSpinners(); },
        spinnersOnVideoTimeUpdate: function (event) {
            // Safari sometimes calls waiting and doesn't recover
            if (this.spinner.style.display == "block") { this.hideSpinners(); }
        }
    }
);
    /* Subtitles
    ================================================================================ */
    VideoJS.player.newBehavior("subtitlesDisplay", function (element) {
        if (!this.subtitleDisplays) {
            this.subtitleDisplays = [];
            this.onCurrentTimeUpdate(this.subtitleDisplaysOnVideoTimeUpdate);
            this.onEnded(function () { this.lastSubtitleIndex = 0; } .context(this));
        }
        this.subtitleDisplays.push(element);
    }, {
        subtitleDisplaysOnVideoTimeUpdate: function (time) {
            // Assuming all subtitles are in order by time, and do not overlap
            if (this.subtitles) {
                // If current subtitle should stay showing, don't do anything. Otherwise, find new subtitle.
                if (!this.currentSubtitle || this.currentSubtitle.start >= time || this.currentSubtitle.end < time) {
                    var newSubIndex = false,
                    // Loop in reverse if lastSubtitle is after current time (optimization)
                    // Meaning the user is scrubbing in reverse or rewinding
              reverse = (this.subtitles[this.lastSubtitleIndex].start > time),
                    // If reverse, step back 1 becase we know it's not the lastSubtitle
              i = this.lastSubtitleIndex - (reverse) ? 1 : 0;
                    while (true) { // Loop until broken
                        if (reverse) { // Looping in reverse
                            // Stop if no more, or this subtitle ends before the current time (no earlier subtitles should apply)
                            if (i < 0 || this.subtitles[i].end < time) { break; }
                            // End is greater than time, so if start is less, show this subtitle
                            if (this.subtitles[i].start < time) {
                                newSubIndex = i;
                                break;
                            }
                            i--;
                        } else { // Looping forward
                            // Stop if no more, or this subtitle starts after time (no later subtitles should apply)
                            if (i >= this.subtitles.length || this.subtitles[i].start > time) { break; }
                            // Start is less than time, so if end is later, show this subtitle
                            if (this.subtitles[i].end > time) {
                                newSubIndex = i;
                                break;
                            }
                            i++;
                        }
                    }

                    // Set or clear current subtitle
                    if (newSubIndex !== false) {
                        this.currentSubtitle = this.subtitles[newSubIndex];
                        this.lastSubtitleIndex = newSubIndex;
                        this.updateSubtitleDisplays(this.currentSubtitle.text);
                    } else if (this.currentSubtitle) {
                        this.currentSubtitle = false;
                        this.updateSubtitleDisplays("");
                    }
                }
            }
        },
        updateSubtitleDisplays: function (val) {
            this.each(this.subtitleDisplays, function (disp) {
                disp.innerHTML = val;
            });
        }
    }
);

    ////////////////////////////////////////////////////////////////////////////////
    // Convenience Functions (mini library)
    // Functions not specific to video or VideoJS and could probably be replaced with a library like jQuery
    ////////////////////////////////////////////////////////////////////////////////

    VideoJS.extend({

        addClass: function (element, classToAdd) {
            if ((" " + element.className + " ").indexOf(" " + classToAdd + " ") == -1) {
                element.className = element.className === "" ? classToAdd : element.className + " " + classToAdd;
            }
        },
        removeClass: function (element, classToRemove) {
            if (element.className.indexOf(classToRemove) == -1) { return; }
            var classNames = element.className.split(/\s+/);
            classNames.splice(classNames.lastIndexOf(classToRemove), 1);
            element.className = classNames.join(" ");
        },
        createElement: function (tagName, attributes) {
            return this.merge(document.createElement(tagName), attributes);
        },

        // Attempt to block the ability to select text while dragging controls
        blockTextSelection: function () {
            document.body.focus();
            document.onselectstart = function () { return false; };
        },
        // Turn off text selection blocking
        unblockTextSelection: function () { document.onselectstart = function () { return true; }; },

        // Return seconds as MM:SS
        formatTime: function (secs) {
            var seconds = Math.round(secs);
            var minutes = Math.floor(seconds / 60);
            minutes = (minutes >= 10) ? minutes : "0" + minutes;
            seconds = Math.floor(seconds % 60);
            seconds = (seconds >= 10) ? seconds : "0" + seconds;
            return minutes + ":" + seconds;
        },

        // Return the relative horizonal position of an event as a value from 0-1
        getRelativePosition: function (x, relativeElement) {
            return Math.max(0, Math.min(1, (x - this.findPosX(relativeElement)) / relativeElement.offsetWidth));
        },
        // Get an objects position on the page
        findPosX: function (obj) {
            var curleft = obj.offsetLeft;
            while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft;
            }
            return curleft;
        },
        getComputedStyleValue: function (element, style) {
            return window.getComputedStyle(element, null).getPropertyValue(style);
        },

        round: function (num, dec) {
            if (!dec) { dec = 0; }
            return Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
        },

        addListener: function (element, type, handler) {
            if (element.addEventListener) {
                element.addEventListener(type, handler, false);
            } else if (element.attachEvent) {
                element.attachEvent("on" + type, handler);
            }
        },
        removeListener: function (element, type, handler) {
            if (element.removeEventListener) {
                element.removeEventListener(type, handler, false);
            } else if (element.attachEvent) {
                element.detachEvent("on" + type, handler);
            }
        },

        get: function (url, onSuccess) {
            if (typeof XMLHttpRequest == "undefined") {
                XMLHttpRequest = function () {
                    try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e) { }
                    try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (f) { }
                    try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (g) { }
                    //Microsoft.XMLHTTP points to Msxml2.XMLHTTP.3.0 and is redundant
                    throw new Error("This browser does not support XMLHttpRequest.");
                };
            }
            var request = new XMLHttpRequest();
            request.open("GET", url);
            request.onreadystatechange = function () {
                if (request.readyState == 4 && request.status == 200) {
                    onSuccess(request.responseText);
                }
            } .context(this);
            request.send();
        },

        trim: function (string) { return string.toString().replace(/^\s+/, "").replace(/\s+$/, ""); },

        // DOM Ready functionality adapted from jQuery. http://jquery.com/
        bindDOMReady: function () {
            if (document.readyState === "complete") {
                return VideoJS.onDOMReady();
            }
            if (document.addEventListener) {
                document.addEventListener("DOMContentLoaded", VideoJS.DOMContentLoaded, false);
                window.addEventListener("load", VideoJS.onDOMReady, false);
            } else if (document.attachEvent) {
                document.attachEvent("onreadystatechange", VideoJS.DOMContentLoaded);
                window.attachEvent("onload", VideoJS.onDOMReady);
            }
        },

        DOMContentLoaded: function () {
            if (document.addEventListener) {
                document.removeEventListener("DOMContentLoaded", VideoJS.DOMContentLoaded, false);
                VideoJS.onDOMReady();
            } else if (document.attachEvent) {
                if (document.readyState === "complete") {
                    document.detachEvent("onreadystatechange", VideoJS.DOMContentLoaded);
                    VideoJS.onDOMReady();
                }
            }
        },

        // Functions to be run once the DOM is loaded
        DOMReadyList: [],
        addToDOMReady: function (fn) {
            if (VideoJS.DOMIsReady) {
                fn.call(document);
            } else {
                VideoJS.DOMReadyList.push(fn);
            }
        },

        DOMIsReady: false,
        onDOMReady: function () {
            if (VideoJS.DOMIsReady) { return; }
            if (!document.body) { return setTimeout(VideoJS.onDOMReady, 13); }
            VideoJS.DOMIsReady = true;
            if (VideoJS.DOMReadyList) {
                for (var i = 0; i < VideoJS.DOMReadyList.length; i++) {
                    VideoJS.DOMReadyList[i].call(document);
                }
                VideoJS.DOMReadyList = null;
            }
        }
    });
    VideoJS.bindDOMReady();

    // Allows for binding context to functions
    // when using in event listeners and timeouts
    Function.prototype.context = function (obj) {
        var method = this,
  temp = function () {
      return method.apply(obj, arguments);
  };
        return temp;
    };

    // Like context, in that it creates a closure
    // But insteaad keep "this" intact, and passes the var as the second argument of the function
    // Need for event listeners where you need to know what called the event
    // Only use with event callbacks
    Function.prototype.evtContext = function (obj) {
        var method = this,
  temp = function () {
      var origContext = this;
      return method.call(obj, arguments[0], origContext);
  };
        return temp;
    };

    // Removeable Event listener with Context
    // Replaces the original function with a version that has context
    // So it can be removed using the original function name.
    // In order to work, a version of the function must already exist in the player/prototype
    Function.prototype.rEvtContext = function (obj, funcParent) {
        if (this.hasContext === true) { return this; }
        if (!funcParent) { funcParent = obj; }
        for (var attrname in funcParent) {
            if (funcParent[attrname] == this) {
                funcParent[attrname] = this.evtContext(obj);
                funcParent[attrname].hasContext = true;
                return funcParent[attrname];
            }
        }
        return this.evtContext(obj);
    };

    // jQuery Plugin
    if (window.jQuery) {
        (function ($) {
            $.fn.VideoJS = function (options) {
                this.each(function () {
                    VideoJS.setup(this, options);
                });
                return this;
            };
            $.fn.player = function () {
                return this[0].player;
            };
        })(jQuery);
    }


    // Expose to global
    window.VideoJS = window._V_ = VideoJS;

    // End self-executing function
})(window);


/** 
* flowplayer.js 3.2.6. The Flowplayer API
* 
* Copyright 2009 Flowplayer Oy
* 
* This file is part of Flowplayer.
* 
* Flowplayer is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* Flowplayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with Flowplayer.  If not, see <http://www.gnu.org/licenses/>.
* 
* Date: 2010-08-25 12:48:46 +0000 (Wed, 25 Aug 2010)
* Revision: 575 
*/
(function () {

    /* 
    FEATURES 
    --------
    - $f() and flowplayer() functions	
    - handling multiple instances 
    - Flowplayer programming API 
    - Flowplayer event model	
    - player loading / unloading	
    - jQuery support
    */


    /*jslint glovar: true, browser: true */
    /*global flowplayer, $f */

    // {{{ private utility methods

    function log(args) {
        console.log("$f.fireEvent", [].slice.call(args));
    }


    // thanks: http://keithdevens.com/weblog/archive/2007/Jun/07/javascript.clone
    function clone(obj) {
        if (!obj || typeof obj != 'object') { return obj; }
        var temp = new obj.constructor();
        for (var key in obj) {
            if (obj.hasOwnProperty(key)) {
                temp[key] = clone(obj[key]);
            }
        }
        return temp;
    }

    // stripped from jQuery, thanks John Resig 
    function each(obj, fn) {
        if (!obj) { return; }

        var name, i = 0, length = obj.length;

        // object
        if (length === undefined) {
            for (name in obj) {
                if (fn.call(obj[name], name, obj[name]) === false) { break; }
            }

            // array
        } else {
            for (var value = obj[0];
				i < length && fn.call(value, i, value) !== false; value = obj[++i]) {
            }
        }

        return obj;
    }


    // convenience
    function el(id) {
        return document.getElementById(id);
    }


    // used extensively. a very simple implementation. 
    function extend(to, from, skipFuncs) {
        if (typeof from != 'object') { return to; }

        if (to && from) {
            each(from, function (name, value) {
                if (!skipFuncs || typeof value != 'function') {
                    to[name] = value;
                }
            });
        }

        return to;
    }

    // var arr = select("elem.className"); 
    function select(query) {
        var index = query.indexOf(".");
        if (index != -1) {
            var tag = query.slice(0, index) || "*";
            var klass = query.slice(index + 1, query.length);
            var els = [];
            each(document.getElementsByTagName(tag), function () {
                if (this.className && this.className.indexOf(klass) != -1) {
                    els.push(this);
                }
            });
            return els;
        }
    }

    // fix event inconsistencies across browsers
    function stopEvent(e) {
        e = e || window.event;

        if (e.preventDefault) {
            e.stopPropagation();
            e.preventDefault();

        } else {
            e.returnValue = false;
            e.cancelBubble = true;
        }
        return false;
    }

    // push an event listener into existing array of listeners
    function bind(to, evt, fn) {
        to[evt] = to[evt] || [];
        to[evt].push(fn);
    }


    // generates an unique id
    function makeId() {
        return "_" + ("" + Math.random()).slice(2, 10);
    }

    //}}}	


    // {{{ Clip

    var Clip = function (json, index, player) {

        // private variables
        var self = this,
			 cuepoints = {},
			 listeners = {};

        self.index = index;

        // instance variables
        if (typeof json == 'string') {
            json = { url: json };
        }

        extend(this, json, true);

        // event handling 
        each(("Begin*,Start,Pause*,Resume*,Seek*,Stop*,Finish*,LastSecond,Update,BufferFull,BufferEmpty,BufferStop").split(","),
			function () {

			    var evt = "on" + this;

			    // before event
			    if (evt.indexOf("*") != -1) {
			        evt = evt.slice(0, evt.length - 1);
			        var before = "onBefore" + evt.slice(2);

			        self[before] = function (fn) {
			            bind(listeners, before, fn);
			            return self;
			        };
			    }

			    self[evt] = function (fn) {
			        bind(listeners, evt, fn);
			        return self;
			    };


			    // set common clip event listeners to player level
			    if (index == -1) {
			        if (self[before]) {
			            player[before] = self[before];
			        }
			        if (self[evt]) {
			            player[evt] = self[evt];
			        }
			    }

			});

        extend(this, {

            onCuepoint: function (points, fn) {

                // embedded cuepoints
                if (arguments.length == 1) {
                    cuepoints.embedded = [null, points];
                    return self;
                }

                if (typeof points == 'number') {
                    points = [points];
                }

                var fnId = makeId();
                cuepoints[fnId] = [points, fn];

                if (player.isLoaded()) {
                    player._api().fp_addCuepoints(points, index, fnId);
                }

                return self;
            },

            update: function (json) {
                extend(self, json);

                if (player.isLoaded()) {
                    player._api().fp_updateClip(json, index);
                }
                var conf = player.getConfig();
                var clip = (index == -1) ? conf.clip : conf.playlist[index];
                extend(clip, json, true);
            },


            // internal event for performing clip tasks. should be made private someday
            _fireEvent: function (evt, arg1, arg2, target) {
                if (evt == 'onLoad') {
                    each(cuepoints, function (key, val) {
                        if (val[0]) {
                            player._api().fp_addCuepoints(val[0], index, key);
                        }
                    });
                    return false;
                }

                // target clip we are working against
                target = target || self;

                if (evt == 'onCuepoint') {
                    var fn = cuepoints[arg1];
                    if (fn) {
                        return fn[1].call(player, target, arg2);
                    }
                }

                // 1. clip properties, 2-3. metadata, 4. updates, 5. resumes from nested clip
                if (arg1 && "onBeforeBegin,onMetaData,onStart,onUpdate,onResume".indexOf(evt) != -1) {
                    // update clip properties
                    extend(target, arg1);

                    if (arg1.metaData) {
                        if (!target.duration) {
                            target.duration = arg1.metaData.duration;
                        } else {
                            target.fullDuration = arg1.metaData.duration;
                        }
                    }
                }


                var ret = true;
                each(listeners[evt], function () {
                    ret = this.call(player, target, arg1, arg2);
                });
                return ret;
            }

        });


        // get cuepoints from config
        if (json.onCuepoint) {
            var arg = json.onCuepoint;
            self.onCuepoint.apply(self, typeof arg == 'function' ? [arg] : arg);
            delete json.onCuepoint;
        }

        // get other events
        each(json, function (key, val) {

            if (typeof val == 'function') {
                bind(listeners, key, val);
                delete json[key];
            }

        });


        // setup common clip event callbacks for Player object too (shortcuts)
        if (index == -1) {
            player.onCuepoint = this.onCuepoint;
        }

    };

    //}}}


    // {{{ Plugin

    var Plugin = function (name, json, player, fn) {

        var self = this,
			 listeners = {},
			 hasMethods = false;

        if (fn) {
            extend(listeners, fn);
        }

        // custom callback functions in configuration
        each(json, function (key, val) {
            if (typeof val == 'function') {
                listeners[key] = val;
                delete json[key];
            }
        });

        // core plugin methods		
        extend(this, {

            // speed and fn are optional
            animate: function (props, speed, fn) {
                if (!props) {
                    return self;
                }

                if (typeof speed == 'function') {
                    fn = speed;
                    speed = 500;
                }

                if (typeof props == 'string') {
                    var key = props;
                    props = {};
                    props[key] = speed;
                    speed = 500;
                }

                if (fn) {
                    var fnId = makeId();
                    listeners[fnId] = fn;
                }

                if (speed === undefined) { speed = 500; }
                json = player._api().fp_animate(name, props, speed, fnId);
                return self;
            },

            css: function (props, val) {
                if (val !== undefined) {
                    var css = {};
                    css[props] = val;
                    props = css;
                }
                json = player._api().fp_css(name, props);
                extend(self, json);
                return self;
            },

            show: function () {
                this.display = 'block';
                player._api().fp_showPlugin(name);
                return self;
            },

            hide: function () {
                this.display = 'none';
                player._api().fp_hidePlugin(name);
                return self;
            },

            // toggle between visible / hidden state
            toggle: function () {
                this.display = player._api().fp_togglePlugin(name);
                return self;
            },

            fadeTo: function (o, speed, fn) {

                if (typeof speed == 'function') {
                    fn = speed;
                    speed = 500;
                }

                if (fn) {
                    var fnId = makeId();
                    listeners[fnId] = fn;
                }
                this.display = player._api().fp_fadeTo(name, o, speed, fnId);
                this.opacity = o;
                return self;
            },

            fadeIn: function (speed, fn) {
                return self.fadeTo(1, speed, fn);
            },

            fadeOut: function (speed, fn) {
                return self.fadeTo(0, speed, fn);
            },

            getName: function () {
                return name;
            },

            getPlayer: function () {
                return player;
            },

            // internal method. should be made private some day
            _fireEvent: function (evt, arg, arg2) {

                // update plugins properties & methods
                if (evt == 'onUpdate') {
                    var json = player._api().fp_getPlugin(name);
                    if (!json) { return; }

                    extend(self, json);
                    delete self.methods;

                    if (!hasMethods) {
                        each(json.methods, function () {
                            var method = "" + this;

                            self[method] = function () {
                                var a = [].slice.call(arguments);
                                var ret = player._api().fp_invoke(name, method, a);
                                return ret === 'undefined' || ret === undefined ? self : ret;
                            };
                        });
                        hasMethods = true;
                    }
                }

                // plugin callbacks
                var fn = listeners[evt];

                if (fn) {
                    var ret = fn.apply(self, arg);

                    // "one-shot" callback
                    if (evt.slice(0, 1) == "_") {
                        delete listeners[evt];
                    }

                    return ret;
                }

                return self;
            }

        });

    };


    //}}}


    function Player(wrapper, params, conf) {

        // private variables (+ arguments)
        var self = this,
		api = null,
		isUnloading = false,
		html,
		commonClip,
		playlist = [],
		plugins = {},
		listeners = {},
		playerId,
		apiId,

        // n'th player on the page
		playerIndex,

        // active clip's index number
		activeIndex,

		swfHeight,
		wrapperHeight;


        // {{{ public methods 

        extend(self, {

            id: function () {
                return playerId;
            },

            isLoaded: function () {
                return (api !== null && api.fp_play !== undefined && !isUnloading);
            },

            getParent: function () {
                return wrapper;
            },

            hide: function (all) {
                if (all) { wrapper.style.height = "0px"; }
                if (self.isLoaded()) { api.style.height = "0px"; }
                return self;
            },

            show: function () {
                wrapper.style.height = wrapperHeight + "px";
                if (self.isLoaded()) { api.style.height = swfHeight + "px"; }
                return self;
            },

            isHidden: function () {
                return self.isLoaded() && parseInt(api.style.height, 10) === 0;
            },

            load: function (fn) {
                if (!self.isLoaded() && self._fireEvent("onBeforeLoad") !== false) {
                    var onPlayersUnloaded = function () {
                        html = wrapper.innerHTML;

                        // do not use splash as alternate content for flashembed
                        if (html && !flashembed.isSupported(params.version)) {
                            wrapper.innerHTML = "";
                        }

                        // onLoad listener given as argument
                        if (fn) {
                            fn.cached = true;
                            bind(listeners, "onLoad", fn);
                        }

                        // install Flash object inside given container
                        flashembed(wrapper, params, { config: conf });
                    };


                    // unload all instances
                    var unloadedPlayersNb = 0;
                    each(players, function () {
                        this.unload(function (wasUnloaded) {
                            if (++unloadedPlayersNb == players.length) {
                                onPlayersUnloaded();
                            }
                        });
                    });
                }

                return self;
            },

            unload: function (fn) {


                // if we are fullscreen on safari, we can't unload as it would crash the PluginHost, sorry
                if (this.isFullscreen() && /WebKit/i.test(navigator.userAgent)) {
                    if (fn) { fn(false); }
                    return self;
                }


                // unload only if in splash state
                if (html.replace(/\s/g, '') !== '') {

                    if (self._fireEvent("onBeforeUnload") === false) {
                        if (fn) { fn(false); }
                        return self;
                    }

                    isUnloading = true;
                    // try closing
                    try {
                        if (api) {
                            api.fp_close();

                            // fire unload only when API is present
                            self._fireEvent("onUnload");
                        }
                    } catch (error) { }

                    var clean = function () {
                        api = null;
                        wrapper.innerHTML = html;
                        isUnloading = false;

                        if (fn) { fn(true); }
                    };

                    setTimeout(clean, 50);
                }
                else if (fn) { fn(false); }

                return self;

            },

            getClip: function (index) {
                if (index === undefined) {
                    index = activeIndex;
                }
                return playlist[index];
            },


            getCommonClip: function () {
                return commonClip;
            },

            getPlaylist: function () {
                return playlist;
            },

            getPlugin: function (name) {
                var plugin = plugins[name];

                // create plugin if nessessary
                if (!plugin && self.isLoaded()) {
                    var json = self._api().fp_getPlugin(name);
                    if (json) {
                        plugin = new Plugin(name, json, self);
                        plugins[name] = plugin;
                    }
                }
                return plugin;
            },

            getScreen: function () {
                return self.getPlugin("screen");
            },

            getControls: function () {
                return self.getPlugin("controls")._fireEvent("onUpdate");
            },

            // 3.2
            getLogo: function () {
                try {
                    return self.getPlugin("logo")._fireEvent("onUpdate");
                } catch (ignored) { }
            },

            // 3.2
            getPlay: function () {
                return self.getPlugin("play")._fireEvent("onUpdate");
            },


            getConfig: function (copy) {
                return copy ? clone(conf) : conf;
            },

            getFlashParams: function () {
                return params;
            },

            loadPlugin: function (name, url, props, fn) {

                // properties not supplied			
                if (typeof props == 'function') {
                    fn = props;
                    props = {};
                }

                // if fn not given, make a fake id so that plugin's onUpdate get's fired
                var fnId = fn ? makeId() : "_";
                self._api().fp_loadPlugin(name, url, props, fnId);

                // create new plugin
                var arg = {};
                arg[fnId] = fn;
                var p = new Plugin(name, null, self, arg);
                plugins[name] = p;
                return p;
            },


            getState: function () {
                return self.isLoaded() ? api.fp_getState() : -1;
            },

            // "lazy" play
            play: function (clip, instream) {

                var p = function () {
                    if (clip !== undefined) {
                        self._api().fp_play(clip, instream);
                    } else {
                        self._api().fp_play();
                    }
                };

                if (self.isLoaded()) {
                    p();
                } else if (isUnloading) {
                    setTimeout(function () {
                        self.play(clip, instream);
                    }, 50);

                } else {
                    self.load(function () {
                        p();
                    });
                }

                return self;
            },

            getVersion: function () {
                var js = "flowplayer.js 3.2.6";
                if (self.isLoaded()) {
                    var ver = api.fp_getVersion();
                    ver.push(js);
                    return ver;
                }
                return js;
            },

            _api: function () {
                if (!self.isLoaded()) {
                    throw "Flowplayer " + self.id() + " not loaded when calling an API method";
                }
                return api;
            },

            setClip: function (clip) {
                self.setPlaylist([clip]);
                return self;
            },

            getIndex: function () {
                return playerIndex;
            },

            _swfHeight: function () {
                return api.clientHeight;
            }

        });


        // event handlers
        each(("Click*,Load*,Unload*,Keypress*,Volume*,Mute*,Unmute*,PlaylistReplace,ClipAdd,Fullscreen*,FullscreenExit,Error,MouseOver,MouseOut").split(","),
		function () {
		    var name = "on" + this;

		    // before event
		    if (name.indexOf("*") != -1) {
		        name = name.slice(0, name.length - 1);
		        var name2 = "onBefore" + name.slice(2);
		        self[name2] = function (fn) {
		            bind(listeners, name2, fn);
		            return self;
		        };
		    }

		    // normal event
		    self[name] = function (fn) {
		        bind(listeners, name, fn);
		        return self;
		    };
		}
	);


        // core API methods
        each(("pause,resume,mute,unmute,stop,toggle,seek,getStatus,getVolume,setVolume,getTime,isPaused,isPlaying,startBuffering,stopBuffering,isFullscreen,toggleFullscreen,reset,close,setPlaylist,addClip,playFeed,setKeyboardShortcutsEnabled,isKeyboardShortcutsEnabled").split(","),
		function () {
		    var name = this;

		    self[name] = function (a1, a2) {
		        if (!self.isLoaded()) { return self; }
		        var ret = null;

		        // two arguments
		        if (a1 !== undefined && a2 !== undefined) {
		            ret = api["fp_" + name](a1, a2);

		        } else {
		            ret = (a1 === undefined) ? api["fp_" + name]() : api["fp_" + name](a1);

		        }

		        return ret === 'undefined' || ret === undefined ? self : ret;
		    };
		}
	);

        //}}}


        // {{{ public method: _fireEvent

        self._fireEvent = function (a) {

            if (typeof a == 'string') { a = [a]; }

            var evt = a[0], arg0 = a[1], arg1 = a[2], arg2 = a[3], i = 0;
            if (conf.debug) { log(a); }

            // internal onLoad
            if (!self.isLoaded() && evt == 'onLoad' && arg0 == 'player') {

                api = api || el(apiId);
                swfHeight = self._swfHeight();

                each(playlist, function () {
                    this._fireEvent("onLoad");
                });

                each(plugins, function (name, p) {
                    p._fireEvent("onUpdate");
                });

                commonClip._fireEvent("onLoad");
            }

            // other onLoad events are skipped
            if (evt == 'onLoad' && arg0 != 'player') { return; }


            // "normalize" error handling
            if (evt == 'onError') {
                if (typeof arg0 == 'string' || (typeof arg0 == 'number' && typeof arg1 == 'number')) {
                    arg0 = arg1;
                    arg1 = arg2;
                }
            }


            if (evt == 'onContextMenu') {
                each(conf.contextMenu[arg0], function (key, fn) {
                    fn.call(self);
                });
                return;
            }

            if (evt == 'onPluginEvent' || evt == 'onBeforePluginEvent') {
                var name = arg0.name || arg0;
                var p = plugins[name];

                if (p) {
                    p._fireEvent("onUpdate", arg0);
                    return p._fireEvent(arg1, a.slice(3));
                }
                return;
            }

            // replace whole playlist
            if (evt == 'onPlaylistReplace') {
                playlist = [];
                var index = 0;
                each(arg0, function () {
                    playlist.push(new Clip(this, index++, self));
                });
            }

            // insert new clip to the playlist. arg0 = clip, arg1 = index 
            if (evt == 'onClipAdd') {

                // instream clip additions are ignored at this point
                if (arg0.isInStream) { return; }

                // add new clip into playlist			
                arg0 = new Clip(arg0, arg1, self);
                playlist.splice(arg1, 0, arg0);

                // increment index variable for the rest of the clips on playlist 
                for (i = arg1 + 1; i < playlist.length; i++) {
                    playlist[i].index++;
                }
            }


            var ret = true;

            // clip event
            if (typeof arg0 == 'number' && arg0 < playlist.length) {

                activeIndex = arg0;
                var clip = playlist[arg0];

                if (clip) {
                    ret = clip._fireEvent(evt, arg1, arg2);
                }

                if (!clip || ret !== false) {
                    // clip argument is given for common clip, because it behaves as the target
                    ret = commonClip._fireEvent(evt, arg1, arg2, clip);
                }
            }


            // trigger player event
            each(listeners[evt], function () {
                ret = this.call(self, arg0, arg1);

                // remove cached entry
                if (this.cached) {
                    listeners[evt].splice(i, 1);
                }

                // break loop
                if (ret === false) { return false; }
                i++;

            });

            return ret;
        };

        //}}}


        // {{{ init

        function init() {
            // replace previous installation 
            if ($f(wrapper)) {
                $f(wrapper).getParent().innerHTML = "";
                playerIndex = $f(wrapper).getIndex();
                players[playerIndex] = self;

                // register this player into global array of instances
            } else {
                players.push(self);
                playerIndex = players.length - 1;
            }

            wrapperHeight = parseInt(wrapper.style.height, 10) || wrapper.clientHeight;

            // playerId	
            playerId = wrapper.id || "fp" + makeId();
            apiId = params.id || playerId + "_api";
            params.id = apiId;
            conf.playerId = playerId;


            // plain url is given as config
            if (typeof conf == 'string') {
                conf = { clip: { url: conf} };
            }

            if (typeof conf.clip == 'string') {
                conf.clip = { url: conf.clip };
            }

            // common clip is always there
            conf.clip = conf.clip || {};


            // wrapper href as common clip's url
            if (wrapper.getAttribute("href", 2) && !conf.clip.url) {
                conf.clip.url = wrapper.getAttribute("href", 2);
            }

            commonClip = new Clip(conf.clip, -1, self);

            // playlist
            conf.playlist = conf.playlist || [conf.clip];

            var index = 0;

            each(conf.playlist, function () {

                var clip = this;

                /* sometimes clip is given as array. this is not accepted. */
                if (typeof clip == 'object' && clip.length) {
                    clip = { url: "" + clip };
                }

                // populate common clip properties to each clip
                each(conf.clip, function (key, val) {
                    if (val !== undefined && clip[key] === undefined && typeof val != 'function') {
                        clip[key] = val;
                    }
                });

                // modify playlist in configuration
                conf.playlist[index] = clip;

                // populate playlist array
                clip = new Clip(clip, index, self);
                playlist.push(clip);
                index++;
            });

            // event listeners
            each(conf, function (key, val) {
                if (typeof val == 'function') {

                    // common clip event
                    if (commonClip[key]) {
                        commonClip[key](val);

                        // player event
                    } else {
                        bind(listeners, key, val);
                    }

                    // no need to supply for the Flash component
                    delete conf[key];
                }
            });


            // plugins
            each(conf.plugins, function (name, val) {
                if (val) {
                    plugins[name] = new Plugin(name, val, self);
                }
            });


            // setup controlbar plugin if not explicitly defined
            if (!conf.plugins || conf.plugins.controls === undefined) {
                plugins.controls = new Plugin("controls", null, self);
            }

            // setup canvas as plugin
            plugins.canvas = new Plugin("canvas", null, self);

            html = wrapper.innerHTML;

            // click function
            function doClick(e) {

                // ipad/iPhone --> follow the link if plugin not installed
                var hasiPadSupport = self.hasiPadSupport && self.hasiPadSupport();
                if (/iPad|iPhone|iPod/i.test(navigator.userAgent) && !/.flv$/i.test(playlist[0].url) && !hasiPadSupport) {
                    return true;
                }

                if (!self.isLoaded() && self._fireEvent("onBeforeClick") !== false) {
                    self.load();
                }
                return stopEvent(e);
            }

            function installPlayer() {
                // defer loading upon click
                if (html.replace(/\s/g, '') !== '') {

                    if (wrapper.addEventListener) {
                        wrapper.addEventListener("click", doClick, false);

                    } else if (wrapper.attachEvent) {
                        wrapper.attachEvent("onclick", doClick);
                    }

                    // player is loaded upon page load 
                } else {

                    // prevent default action from wrapper. (fixes safari problems)
                    if (wrapper.addEventListener) {
                        wrapper.addEventListener("click", stopEvent, false);
                    }
                    // load player
                    self.load();
                }
            }

            // now that the player is initialized, wait for the plugin chain to finish
            // before actually changing the dom
            setTimeout(installPlayer, 0);
        }

        // possibly defer initialization until DOM get's loaded
        if (typeof wrapper == 'string') {
            var node = el(wrapper);
            if (!node) { throw "Flowplayer cannot access element: " + wrapper; }
            wrapper = node;
            init();

            // we have a DOM element so page is already loaded
        } else {
            init();
        }


        //}}}


    }


    // {{{ flowplayer() & statics 

    // container for player instances
    var players = [];


    // this object is returned when multiple player's are requested 
    function Iterator(arr) {

        this.length = arr.length;

        this.each = function (fn) {
            each(arr, fn);
        };

        this.size = function () {
            return arr.length;
        };
    }

    // these two variables are the only global variables
    window.flowplayer = window.$f = function () {
        var instance = null;
        var arg = arguments[0];

        // $f()
        if (!arguments.length) {
            each(players, function () {
                if (this.isLoaded()) {
                    instance = this;
                    return false;
                }
            });

            return instance || players[0];
        }

        if (arguments.length == 1) {

            // $f(index);
            if (typeof arg == 'number') {
                return players[arg];


                // $f(wrapper || 'containerId' || '*');
            } else {

                // $f("*");
                if (arg == '*') {
                    return new Iterator(players);
                }

                // $f(wrapper || 'containerId');
                each(players, function () {
                    if (this.id() == arg.id || this.id() == arg || this.getParent() == arg) {
                        instance = this;
                        return false;
                    }
                });

                return instance;
            }
        }

        // instance builder 
        if (arguments.length > 1) {

            // flashembed parameters
            var params = arguments[1],
			 conf = (arguments.length == 3) ? arguments[2] : {};


            if (typeof params == 'string') {
                params = { src: params };
            }

            params = extend({
                bgcolor: "#000000",
                version: [9, 0],
                expressInstall: "http://static.flowplayer.org/swf/expressinstall.swf",
                cachebusting: false

            }, params);

            if (typeof arg == 'string') {

                // select arg by classname
                if (arg.indexOf(".") != -1) {
                    var instances = [];

                    each(select(arg), function () {
                        instances.push(new Player(this, clone(params), clone(conf)));
                    });

                    return new Iterator(instances);

                    // select node by id
                } else {
                    var node = el(arg);
                    return new Player(node !== null ? node : arg, params, conf);
                }


                // arg is a DOM element
            } else if (arg) {
                return new Player(arg, params, conf);
            }

        }

        return null;
    };

    extend(window.$f, {

        // called by Flash External Interface 		
        fireEvent: function () {
            var a = [].slice.call(arguments);
            var p = $f(a[0]);
            return p ? p._fireEvent(a.slice(1)) : null;
        },


        // create plugins by modifying Player's prototype
        addPlugin: function (name, fn) {
            Player.prototype[name] = fn;
            return $f;
        },

        // utility methods for plugin developers
        each: each,

        extend: extend
    });


    //}}}


    //{{{ jQuery support

    if (typeof jQuery == 'function') {

        jQuery.fn.flowplayer = function (params, conf) {

            // select instances
            if (!arguments.length || typeof arguments[0] == 'number') {
                var arr = [];
                this.each(function () {
                    var p = $f(this);
                    if (p) {
                        arr.push(p);
                    }
                });
                return arguments.length ? arr[arguments[0]] : new Iterator(arr);
            }

            // create flowplayer instances
            return this.each(function () {
                $f(this, clone(params), conf ? clone(conf) : {});
            });

        };

    }

    //}}}


})();
/**
* @license 
* jQuery Tools 3.2.6 / Flashembed - New wave Flash embedding
* 
* NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
* 
* http://flowplayer.org/tools/toolbox/flashembed.html
*
* Since : March 2008
* Date  : @DATE 
*/
(function () {

    var IE = document.all,
		 URL = 'http://www.adobe.com/go/getflashplayer',
		 JQUERY = typeof jQuery == 'function',
		 RE = /(\d+)[^\d]+(\d+)[^\d]*(\d*)/,
		 GLOBAL_OPTS = {
		     // very common opts
		     width: '100%',
		     height: '100%',
		     id: "_" + ("" + Math.random()).slice(9),

		     // flashembed defaults
		     allowfullscreen: true,
		     allowscriptaccess: 'always',
		     quality: 'high',

		     // flashembed specific options
		     version: [3, 0],
		     onFail: null,
		     expressInstall: null,
		     w3c: false,
		     cachebusting: false
		 };

    // version 9 bugfix: (http://blog.deconcept.com/2006/07/28/swfobject-143-released/)
    if (window.attachEvent) {
        window.attachEvent("onbeforeunload", function () {
            __flash_unloadHandler = function () { };
            __flash_savedUnloadHandler = function () { };
        });
    }

    // simple extend
    function extend(to, from) {
        if (from) {
            for (var key in from) {
                if (from.hasOwnProperty(key)) {
                    to[key] = from[key];
                }
            }
        }
        return to;
    }

    // used by asString method	
    function map(arr, func) {
        var newArr = [];
        for (var i in arr) {
            if (arr.hasOwnProperty(i)) {
                newArr[i] = func(arr[i]);
            }
        }
        return newArr;
    }

    window.flashembed = function (root, opts, conf) {

        // root must be found / loaded	
        if (typeof root == 'string') {
            root = document.getElementById(root.replace("#", ""));
        }

        // not found
        if (!root) { return; }

        if (typeof opts == 'string') {
            opts = { src: opts };
        }

        return new Flash(root, extend(extend({}, GLOBAL_OPTS), opts), conf);
    };

    // flashembed "static" API
    var f = extend(window.flashembed, {

        conf: GLOBAL_OPTS,

        getVersion: function () {
            var fo, ver;

            try {
                ver = navigator.plugins["Shockwave Flash"].description.slice(16);
            } catch (e) {

                try {
                    fo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
                    ver = fo && fo.GetVariable("$version");

                } catch (err) {
                    try {
                        fo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
                        ver = fo && fo.GetVariable("$version");
                    } catch (err2) { }
                }
            }

            ver = RE.exec(ver);
            return ver ? [ver[1], ver[3]] : [0, 0];
        },

        asString: function (obj) {

            if (obj === null || obj === undefined) { return null; }
            var type = typeof obj;
            if (type == 'object' && obj.push) { type = 'array'; }

            switch (type) {

                case 'string':
                    obj = obj.replace(new RegExp('(["\\\\])', 'g'), '\\$1');

                    // flash does not handle %- characters well. transforms "50%" to "50pct" (a dirty hack, I admit)
                    obj = obj.replace(/^\s?(\d+\.?\d+)%/, "$1pct");
                    return '"' + obj + '"';

                case 'array':
                    return '[' + map(obj, function (el) {
                        return f.asString(el);
                    }).join(',') + ']';

                case 'function':
                    return '"function()"';

                case 'object':
                    var str = [];
                    for (var prop in obj) {
                        if (obj.hasOwnProperty(prop)) {
                            str.push('"' + prop + '":' + f.asString(obj[prop]));
                        }
                    }
                    return '{' + str.join(',') + '}';
            }

            // replace ' --> "  and remove spaces
            return String(obj).replace(/\s/g, " ").replace(/\'/g, "\"");
        },

        getHTML: function (opts, conf) {

            opts = extend({}, opts);

            /******* OBJECT tag and it's attributes *******/
            var html = '<object width="' + opts.width +
				'" height="' + opts.height +
				'" id="' + opts.id +
				'" name="' + opts.id + '"';

            if (opts.cachebusting) {
                opts.src += ((opts.src.indexOf("?") != -1 ? "&" : "?") + Math.random());
            }

            if (opts.w3c || !IE) {
                html += ' data="' + opts.src + '" type="application/x-shockwave-flash"';
            } else {
                html += ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
            }

            html += '>';

            /******* nested PARAM tags *******/
            if (opts.w3c || IE) {
                html += '<param name="movie" value="' + opts.src + '" />';
            }

            // not allowed params
            opts.width = opts.height = opts.id = opts.w3c = opts.src = null;
            opts.onFail = opts.version = opts.expressInstall = null;

            for (var key in opts) {
                if (opts[key]) {
                    html += '<param name="' + key + '" value="' + opts[key] + '" />';
                }
            }

            /******* FLASHVARS *******/
            var vars = "";

            if (conf) {
                for (var k in conf) {
                    if (conf[k]) {
                        var val = conf[k];
                        vars += k + '=' + (/function|object/.test(typeof val) ? f.asString(val) : val) + '&';
                    }
                }
                vars = vars.slice(0, -1);
                html += '<param name="flashvars" value=\'' + vars + '\' />';
            }

            html += "</object>";

            return html;
        },

        isSupported: function (ver) {
            return VERSION[0] > ver[0] || VERSION[0] == ver[0] && VERSION[1] >= ver[1];
        }

    });

    var VERSION = f.getVersion();

    function Flash(root, opts, conf) {

        // version is ok
        if (f.isSupported(opts.version)) {
            root.innerHTML = f.getHTML(opts, conf);

            // express install
        } else if (opts.expressInstall && f.isSupported([6, 65])) {
            root.innerHTML = f.getHTML(extend(opts, { src: opts.expressInstall }), {
                MMredirectURL: location.href,
                MMplayerType: 'PlugIn',
                MMdoctitle: document.title
            });

        } else {

            // fail #2.1 custom content inside container
            if (!root.innerHTML.replace(/\s/g, '')) {
                //alert('$MM.config.get("flashUpgradeMsg"):' + $MM.config.get("flashUpgradeMsg"));
                if ($MM) {
                    var mesg = "<h2 class='h2_getflash'>" + String($MM.config.get("flashUpgradeMsg")) + "</h2>";
                    root.innerHTML = String(mesg);
                } else {
                    root.innerHTML =
						"<h2>Flash version " + opts.version + " or greater is required</h2>" +
						"<h3>" +
							(VERSION[0] > 0 ? "Your version is " + VERSION : "You have no flash plugin installed") +
						"</h3>" +

						(root.tagName == 'A' ? "<p>Click here to download latest version</p>" :
							"<p>Download latest version from <a href='" + URL + "'>here</a></p>");

                }
                if (root.tagName == 'A') {
                    root.onclick = function () {
                        location.href = URL;
                    };
                }
            }

            // onFail
            if (opts.onFail) {
                var ret = opts.onFail.call(this);
                if (typeof ret == 'string') { root.innerHTML = ret; }
            }
        }

        // http://flowplayer.org/forum/8/18186#post-18593
        if (IE) {
            window[opts.id] = document.getElementById(opts.id);
        }

        // API methods for callback
        extend(this, {

            getRoot: function () {
                return root;
            },

            getOptions: function () {
                return opts;
            },


            getConf: function () {
                return conf;
            },

            getApi: function () {
                return root.firstChild;
            }

        });
    }

    // setup jquery support
    if (JQUERY) {

        // tools version number
        jQuery.tools = jQuery.tools || { version: '3.2.6' };

        jQuery.tools.flashembed = {
            conf: GLOBAL_OPTS
        };

        jQuery.fn.flashembed = function (opts, conf) {
            return this.each(function () {
                jQuery(this).data("flashembed", flashembed(this, opts, conf));
            });
        };
    }

})();

/**
* flowplayer.controls 3.0.2. Flowplayer JavaScript plugin.
* 
* This file is part of Flowplayer, http://flowplayer.org
*
* Author: Tero Piirainen, <info@flowplayer.org>
* Copyright (c) 2008 Flowplayer Ltd
*
* Dual licensed under MIT and GPL 2+ licenses
* SEE: http://www.opensource.org/licenses
* 
* Date: 2008-11-25 11:29:03 -0500 (Tue, 25 Nov 2008)
* Revision: 1424 
*/
$f.addPlugin("controls", function (wrap, options) {


    //{{{ private functions

    function fixE(e) {
        if (typeof e == 'undefined') { e = window.event; }
        if (typeof e.layerX == 'undefined') { e.layerX = e.offsetX; }
        if (typeof e.layerY == 'undefined') { e.layerY = e.offsetY; }
        return e;
    }

    function w(e) {
        return e.clientWidth;
    }

    function offset(e) {
        return e.offsetLeft;
    }

    /* a generic dragger utility for hoirzontal dragging */
    function Draggable(o, min, max, offset) {

        var dragging = false;

        function foo() { }

        o.onDragStart = o.onDragStart || foo;
        o.onDragEnd = o.onDragEnd || foo;
        o.onDrag = o.onDrag || foo;

        function move(x) {
            // must be withing [min, max]
            if (x > max) { return false; }
            if (x < min) { return false; }
            o.style.left = x + "px";
            return true;
        }

        function end() {
            document.onmousemove = null;
            document.onmouseup = null;
            o.onDragEnd(parseInt(o.style.left, 10));
            dragging = false;
        }

        function drag(e) {
            e = fixE(e);
            var x = e.clientX - offset;
            if (move(x)) {
                dragging = true;
                o.onDrag(x);
            }
            return false;
        }

        o.onmousedown = function (e) {
            e = fixE(e);
            o.onDragStart(parseInt(o.style.left, 10));
            document.onmousemove = drag;
            document.onmouseup = end;
            return false;
        };

        this.dragTo = function (x) {
            if (move(x)) {
                o.onDragEnd(x);
            }
        };

        this.setMax = function (val) {
            max = val;
        };

        this.isDragging = function () {
            return dragging;
        };

        return this;
    }

    function extend(to, from) {
        if (from) {
            for (key in from) {
                if (key) {
                    to[key] = from[key];
                }
            }
        }
    }

    function byClass(name) {
        var els = wrap.getElementsByTagName("*");
        var re = new RegExp("(^|\\s)" + name + "(\\s|$)");
        for (var i = 0; i < els.length; i++) {
            if (re.test(els[i].className)) {
                return els[i];
            }
        }
    }

    // prefix integer with zero when nessessary 
    function pad(val) {
        val = parseInt(val, 10);
        return val >= 10 ? val : "0" + val;
    }

    // display seconds in hh:mm:ss format
    function toTime(sec) {

        var h = Math.floor(sec / 3600);
        var min = Math.floor(sec / 60);
        sec = sec - (min * 60);

        if (h >= 1) {
            min -= h * 60;
            return pad(h) + ":" + pad(min) + ":" + pad(sec);
        }

        return pad(min) + ":" + pad(sec);
    }

    function getTime(time, duration) {
        return "<span>" + toTime(time) + "</span> <span class='duration'> / " + toTime(duration) + "</span>";
    }

    //}}}


    var self = this;

    var opts = {
        playHeadClass: 'playhead',
        trackClass: 'track',
        playClass: 'play',
        pauseClass: 'pause',
        bufferClass: 'buffer',
        progressClass: 'progress',

        timeClass: 'time',
        muteClass: 'mute',
        unmuteClass: 'unmute',
        duration: 0,

        template: '<a class="play">play</a>' +
					 '<div class="track">' +
					 	'<div class="buffer"></div>' +
					 	'<div class="progress"></div>' +
					 	'<div class="playhead"></div>' +
					 '</div>' +
					 '<div class="time"></div>' +
					 '<a class="mute">mute</a>'
    };

    extend(opts, options);

    if (typeof wrap == 'string') {
        wrap = document.getElementById(wrap);
    }

    if (!wrap) { return; }

    // inner HTML
    if (!wrap.innerHTML.replace(/\s/g, '')) {
        wrap.innerHTML = opts.template;
    }

    // get elements 
    var ball = byClass(opts.playHeadClass);
    var bufferBar = byClass(opts.bufferClass);
    var progressBar = byClass(opts.progressClass);
    var track = byClass(opts.trackClass);
    var time = byClass(opts.timeClass);
    var mute = byClass(opts.muteClass);


    // initial time
    time.innerHTML = getTime(0, opts.duration);

    // get dimensions 
    var trackWidth = w(track);
    var ballWidth = w(ball);

    // initialize draggable playhead
    var head = new Draggable(ball, 0, 0, offset(wrap) + offset(track) + (ballWidth / 2));

    // track click moves playHead	
    track.onclick = function (e) {
        e = fixE(e);
        if (e.target == ball) { return false; }
        //alert('track to:  e.layerX: ' + e.layerX + " ballWidth: " + ballWidth + " = " + (e.layerX - ballWidth / 2));
        head.dragTo(e.layerX - ballWidth / 2);
    };

    // play/pause button
    var play = byClass(opts.playClass);

    play.onclick = function () {
        if (self.isLoaded()) {
            self.toggle();
        } else {
            self.play();
        }
    };

    // mute/unmute button
    mute.onclick = function () {
        if (self.getStatus().muted) {
            self.unmute();
        } else {
            self.mute();
        }
    };

    // setup timer
    var timer = null;

    function getMax(len, total) {
        var x = parseInt(Math.min(len / total * trackWidth, trackWidth - ballWidth / 2), 10);
        return isNaN(x) ? 0 : x;
    }

    self.onStart(function (clip) {

        var duration = clip.duration || 0;

        // clear previous timer		
        clearInterval(timer);

        // begin timer		
        timer = setInterval(function () {

            var status = self.getStatus();

            // time display
            if (status.time) {
                time.innerHTML = getTime(status.time, clip.duration);
            }

            if (status.time === undefined) {
                clearInterval(timer);
                return;
            }

            // buffer width
            var x = getMax(status.bufferEnd, duration);
            //bufferBar.style.width = x + "px";
            bufferBar.style.width = (status.bufferEnd / duration) * 100 + "%";
            head.setMax(x);

            // progress width

            //alert((status.time/duration)*100+"%");
            if (!self.isPaused() && !head.isDragging()) {
                x = getMax(status.time, duration);
                //progressBar.style.width = x + "px";
                progressBar.style.width = (status.time / duration) * 100 + "%";
                //(status.time/duration)*100+"%";

                ball.style.left = (x - ballWidth / 2) + "px";
            }

        }, 500);
    });

    self.onBegin(function () {
        play.className = opts.pauseClass;
    });


    // pause / resume states	
    self.onPause(function () {
        play.className = opts.playClass;
    });

    self.onResume(function () {
        play.className = opts.pauseClass;
    });


    // mute / unmute states	
    self.onMute(function () {
        mute.className = opts.unmuteClass;
    });

    self.onUnmute(function () {
        mute.className = opts.muteClass;
    });


    // clear timer when clip ends	
    self.onFinish(function (clip) {
        progressBar.style.width = "100%";
        time.innerHTML = getTime(clip.duration, clip.duration);
        clearInterval(timer);
    });

    self.onUnload(function () {
        time.innerHTML = getTime(0, opts.duration);
    });

    self.destroyControls = function () {
        clearInterval(timer);
        time.innerHTML = getTime(0, opts.duration);
    };

    ball.onDragEnd = function (x) {
        trackWidth = $j(".track", flowPlayerController.controlsObj).width();
        //var to = parseInt(x / trackWidth * 100, 10) + "%";
        var to = (x / trackWidth) * flowPlayerController.flowplayer.getClip().fullDuration;
        progressBar.style.width = x + "px";
        //alert('to: ' + to + "    x: " + x + "    trackWidth: " + trackWidth);
        if (self.isLoaded()) {
            flowPlayerController.flowplayer.pause();
            flowPlayerController.flowplayer.seek(parseInt(to));
            flowPlayerController.flowplayer.play();
            //console.log('seeking to: ' + parseInt(to) + "  / " + flowPlayerController.flowplayer.getClip().fullDuration);
        }
    };

    ball.onDrag = function (x) {
        progressBar.style.width = x + "px";
    };


    // return player instance to enable plugin chaining
    return self;

});



var flowPlayerController = {
    isFullScreen: false,
    controlAssetsWidth: 400,
    controlShareWidth: 100,
    playerObj: null,
    controlsObj: null,
    flowplayer: null,
    hasShare: true,
    onStart: function () { },
    onComplete: function () { },
    init: function (playerId, controlsId, share, onStart, onComplete, swfPlayer) {
        flowPlayerController.controlAssetsWidth = 400;
        flowPlayerController.onStart = onStart;
        flowPlayerController.onComplete = onComplete;
        flowPlayerController.playerObj = $j('#' + playerId);
        flowPlayerController.controlsObj = $j('#' + controlsId);
        flowPlayerController.hasShare = share;
        flowPlayerController.showShareButton(share);
        flowPlayerController.initFlowplayer(playerId, controlsId, swfPlayer);
    },
    initFlowplayer: function (playerId, controlsId, swfPlayer) {
        // flow player initialize
        $j(document).motPopup('enableEscapeKey');
        flowPlayerController.flowplayer = $f(playerId, { src: swfPlayer, wmode: "transparent" }, {
            key: '#$05ccc29ed547b7b1a05',
            plugins: { controls: null },
            clip: {
                autoPlay: true,
                autoBuffering: true,
                onStart: function () { flowPlayerController.onStart(); },
                onFinish: function () {
                    flowPlayerController.onComplete();
                }
            }
            // install HTML controls inside element
        }).controls(controlsId, {
            playHeadClass: 'playhead',
            trackClass: 'track',
            playClass: 'play',
            pauseClass: 'paused',
            bufferClass: 'buffer',
            progressClass: 'progress',
            timeClass: 'time',
            muteClass: 'mute',
            unmuteClass: 'unmute',
            duration: 0
        });

        // reset the tracking bars
        $j('.track .buffer').css('width', 0);
        $j('.track .progress').css('width', 0);

        // resize trackbar according to video width
        var playerId = flowPlayerController.playerObj.attr('id');
        pW = parseInt($j('#' + playerId).css('width'));
        if (!flowPlayerController.hasShare) {
            $j('.vjs-time-control').css('right', 100);
            flowPlayerController.controlAssetsWidth = flowPlayerController.controlAssetsWidth - flowPlayerController.controlShareWidth;
        } else {
            $j('.vjs-time-control').css('right', 200);
            flowPlayerController.controlAssetsWidth = flowPlayerController.controlAssetsWidth + flowPlayerController.controlShareWidth;
        }
        var totalTrackWidth = pW - flowPlayerController.controlAssetsWidth;
        $j('.track', flowPlayerController.controlsObj).css('width', totalTrackWidth);
        trackWidth = totalTrackWidth;
        flowPlayerController.activateFullscreenButton();

        // init control display events
        $j('#' + controlsId).hide();
        $j('div.video-js-box').mouseenter(function () {
            $j('#' + controlsId).show();
        });
        $j('div.video-js-box').mouseleave(function () {
            $j('#' + controlsId).hide();
        });
        // end flow player initialize
    },
    activateFullscreenButton: function () {
        var playerId = flowPlayerController.playerObj.attr('id');
        var controlsId = flowPlayerController.controlsObj.attr('id');
        var pW = parseInt($j('#' + playerId).css('width'));
        var pH = parseInt($j('#' + playerId).css('height'));
        $j('.vjs-fullscreen-control', flowPlayerController.controlsObj).click(fullscreenClickHandler);

        function fullscreenClickHandler() {
            if (!flowPlayerController.isFullScreen) {
                $j(document).motPopup('disableEscapeKey');

                // stores the popup to original pre-fullscreen dimensions
                this.origWidth = $j('#motPlayer').width();
                this.origHeight = $j('#motPlayer').height();

                // Stores the original popup width before fullscreen is set
                this.origPopupWidth = $j(this).parent().parent().parent().parent().width();
                // Stores the original popup background color before fullscreen is set
                $fullscreenBg = $j("<div id='video_fullscreen_background'></div>");
                $fullscreenBg.css({ 'position': 'fixed', 'top': 0, 'left': 0, 'width': 90000, 'height': 90000, 'z-index': 90000, 'background': '#000' });
                $j('body').append($fullscreenBg);
                //change the bg border color of the popup container
                this.origPopupBgColor = $j(this).parent().parent().parent().parent().css('background-color');


                $j(this).parent().parent().parent().parent().css({ 'background': '#000000' });
                // Storing original doc overflow value to return to when fullscreen is off
                this.docOrigOverflow = document.documentElement.style.overflow;
                // Hide scrolling
                document.documentElement.style.overflow = 'hidden';


                // ie8/safari5 browser maximize and video fullscreen positioning fix
                this.origBoxPosLeft = $j('.video-js-box').css('left');
                $j('.video-js-box').css('left', 0);




                pW = parseInt($j('#' + playerId).css('width'));
                pH = parseInt($j('#' + playerId).css('height'));
                var nW, nH;
                if ((($j(window).width() - pW) / pW) > (($j(window).height() - pH) / pH)) {
                    nH = $j(window).height();
                    nW = (pW / pH) * nH;
                } else {
                    nW = $j(window).width();
                    nH = (pH / pW) * nW;
                }
                $j('#' + playerId).css('width', nW).css('height', nH);
                $j('#' + playerId).parent().css('width', nW).css('height', nH);
                $j('div', this).addClass('fullscreenOn');

                var leftOffset = ($j(window).width() - nW) * .5;
                var topOffset = ($j(window).height() - nH) * .5;
                $j("div.mot-popup-close").css({ position: "fixed" });
                flowPlayerController.playerObj.parent().css({ position: 'fixed', top: topOffset, left: leftOffset, 'z-index': 9999 });

                $j(document).bind('keyup', flowPlayerController.onEscapePress);

                trackWidth = nW - flowPlayerController.controlAssetsWidth;
                $j('.track', flowPlayerController.controlsObj).css('width', trackWidth);
                
                flowPlayerController.addBackground();
                flowPlayerController.isFullScreen = true;
                $j(window).bind('resize', flowPlayerController.resizeFullscreenVideo);
            } else {
                $j(document).motPopup('enableEscapeKey');
                $j("div.mot-popup-close").css({ position: "absolute" });
                $j('#' + playerId).css('width', pW).css('height', pH);
                $j('#' + playerId).parent().css('width', pW).css('height', pH);
                $j('div', this).removeClass('fullscreenOn');
                flowPlayerController.playerObj.parent().css({ position: 'relative', top: '', left: '', 'z-index': '' });

                $j(document).unbind('keyup', flowPlayerController.onEscapePress);
                trackWidth = pW - flowPlayerController.controlAssetsWidth;
                $j('.track', flowPlayerController.controlsObj).css('width', trackWidth);
                //alert('trackWidth: ' + trackWidth);

                //alert(trackWidth + "  pW: " + pW + "   hasShare: " + flowPlayerController.hasShare);
                flowPlayerController.removeBackground();

                // Unhide scroll bars.
                document.documentElement.style.overflow = this.docOrigOverflow;
                // Restores original popup width before fullscreen 
                $j(this).parent().parent().parent().parent().width(this.origPopupWidth);

                //change the bg border color of the popup container
                $j(this).parent().parent().parent().parent().css({ 'background': this.origPopupBgColor });
                //remove fullscreen black background
                $fullscreenBg = $j("#video_fullscreen_background").remove();


                // ie8/safari5 browser maximize and video fullscreen positioning fix
                if (this.origBoxPosLeft) $j('.video-js-box').css('left', this.origBoxPosLeft);


                flowPlayerController.isFullScreen = false;

                $j(window).unbind('resize', flowPlayerController.resizeFullscreenVideo);
                // resizes popup to original pre-fullscreen dimensions
                $j('#motPlayer').width(this.origWidth).height(this.origHeight);
                $j('#motPlayer').parent().width(this.origWidth).height(this.origHeight);
                //setTimeout(function () { $(window).trigger('resize'); }, 200);

                setTimeout($j.proxy(function () { $j(window).trigger('scroll'); }, this), 200);
                setTimeout($j.proxy(function () { $j(window).trigger('scroll'); }, this), 450);
                setTimeout($j.proxy(function () { $j(window).trigger('scroll'); }, this), 800);
            }
        };
    },
    resizeFullscreenVideo: function () {
        var playerId = flowPlayerController.playerObj.attr('id');
        var pW = parseInt($j('#' + playerId).css('width'));
        var pH = parseInt($j('#' + playerId).css('height'));

        var nW, nH;
        if ((($j(window).width() - pW) / pW) > (($j(window).height() - pH) / pH)) {
            nH = $j(window).height();
            nW = (pW / pH) * nH;
        } else {
            nW = $j(window).width();
            nH = (pH / pW) * nW;
        }
        $j('#' + playerId).css('width', nW).css('height', nH);
        $j('#' + playerId).parent().css('width', nW).css('height', nH);

        var leftOffset = ($j(window).width() - nW) * .5;
        var topOffset = ($j(window).height() - nH) * .5;
        flowPlayerController.playerObj.parent().css({ position: 'fixed', top: topOffset, left: leftOffset, 'z-index': 9999 });


        trackWidth = nW - flowPlayerController.controlAssetsWidth;
        $j('.track', flowPlayerController.controlsObj).css('width', trackWidth);

    },
    addBackground: function () {
        var bg = document.createElement('div');
        bg.setAttribute('id', 'fpFullscreenBackground');
        bg.setAttribute('class', 'fpFullscreenBg');
        $j(bg).css('width', '99999px').css('height', '99999px').css('background', '#000').css('position', 'absolute').css('top', 0).css('left', 0);
        $j('body').append(bg);
    },
    removeBackground: function () {
        var bg = document.getElementById('fpFullscreenBackground');
        if (bg) document.body.removeChild(bg);
        // $j('.fpFullscreenBg').remove();
    },
    showShareButton: function (value) {
        if (flowPlayerController.controlsObj) {
            if (value) {
                $j(".vjs-video-share", flowPlayerController.controlsObj).show();
            } else {
                $j(".vjs-video-share", flowPlayerController.controlsObj).hide();
            }
        }
    },
    destroyPlayer: function () {
        if (flowPlayerController.flowplayer) {
            flowPlayerController.flowplayer.pause().stop().unmute();
            flowPlayerController.flowplayer.destroyControls();
            flowPlayerController.flowplayer.unload();
            flowPlayerController.flowplayer.close();

            //remove fullscreen black background
            $fullscreenBg = $j("#video_fullscreen_background").remove();
            $j('#mot-popup-container').css({ 'background': this.origPopupBgColor, 'background-color': this.origPopupBgColor });
            $j('.vjs-fullscreen-control', flowPlayerController.constrolsObj).unbind('click');
            $j('div.video-js-box').unbind('mouseenter');
            $j('div.video-js-box').unbind('mouseleave');
            flowPlayerController.isFullScreen = false;
            flowPlayerController.removeBackground();
            $j(window).unbind('resize', flowPlayerController.resizeFullscreenVideo);
        }
    },
    onEscapePress: function (e) {
        if (e.keyCode == 27) {
            if (flowPlayerController.isFullScreen)
                $j('.vjs-fullscreen-control', flowPlayerController.controlsObj).trigger('click');
            $j(document).motPopup('enableEscapeKey');
        }   // esc
    }
};
