﻿/// <reference path="../../jquery/jquery-1.5.js" />
lightplayer.MediaPlayer = function (options) {
    this.options = options;
    this.tracks = options.tracks;
    this.captions = [];
    this.chapters = [];
    this.element = options.element;
    this.$element = $(this.element);
    this.$element.find("*").remove();
    this.media = lightplayer.MediaElement.create(options);
    $(this.media.element).appendTo(this.$element);

    this.setSources = function (srcs) {
        this.sources = srcs;
        this.media.setSources(srcs);
    };

    this.setSources(options.sources);

    this.isFullScreen = function () {
        return this.media.isFullScreen;
    };
    onFullScreenEscKeyDown = function (e) {
        if (e.keyCode == 27) {
            self.fullScreen(false);
        }
    };
    this.fullScreen = function (f) {
        this.media.fullScreen(f);
        this.surface.adjust();
    };

    this.width = options.width;
    this.height = options.height;
    this.$element.css('width', this.width + 'px');
    this.$element.css('height', this.height + 'px');
    //this.$element.addClass('lightplayer-id-', this.height + 'px');

    if (lightplayer.html.surfaces[options.surface]) {
        this.surface = new lightplayer.html.surfaces[options.surface](this, options);
        this.surface.build();
    }
};
lightplayer.MediaPlayer.prototype = {
    ready: function () {
        if (typeof this.surface.ready == 'function') {
            this.surface.ready();
        }
    },
    isMuted: function () {
        return this.media.isMuted();
    },
    load: function () {
        this.media.load();
    },
    play: function () {
        this.media.play();
    },
    stop: function () {
        this.media.stop();
    },
    pause: function () {
        this.media.pause();
    },
    seek: function (time) {
        this.media.seek(time);
    },
    buffered: function () {
        return this.media.buffered();
    },
    duration: function () {
        return this.media.duration;
    },
    volume: function (vol) {
        return this.meida.volume(vol);
    },
    mute: function (m) {
        this.meida.mute(m);
    }
};
