﻿/*var Beolit = {
    init: function(id, imgOn, imgOff) {
        var imageOn = new Image();
            imageOn.onload = function() {

        };
        imageOn.src = imgOn;
        $('#img' + id).mouseover(function() {
            $(this).css('background-image', 'url(' + imgOn + ')');
            document.getElementById('player' + id).sendEvent('PLAY', 'true');
        });
        $('#img' + id).mouseout(function() {
            $(this).css('background-image', 'url(' + imgOff + ')');
            document.getElementById('player' + id).sendEvent('PLAY', 'false');
        });
    }
}*/

function playerReady(player) {
	var beolitId =player.id.replace(/player/, 'beolit');
    setTimeout(function () {
        if (window[beolitId]) {
            window[beolitId].playerReady =true;
            window[beolitId].checkDisplay();
        }
    }, 10);
    
}


var Beolit = function (id, imgOnSrc, imgOffSrc) {
    this.image = $('#img' + id);
    this.imageOnReady =false;
    this.imageOffReady =false;
    this.imgOnSrc =imgOnSrc;    
    this.imgOffSrc =imgOffSrc;
    this.playerReady =false;        

    var _this =this;
    var imageOn =new Image();
    imageOn.onload =function () {
        _this.imageOnReady =true;
        _this.checkDisplay();
    };
    imageOn.src =imgOnSrc;

    var imageOff =new Image();
    imageOff.onload =function () {
        _this.image.attr('src', _this.imgOffSrc);
        _this.imageOffReady =true;
        _this.checkDisplay();
    };
    imageOff.src =imgOffSrc;

    $('#img' + id).mouseover(function() {
        $(this).attr('src', _this.imgOnSrc);
        document.getElementById('player' + id).sendEvent('PLAY', 'true');
    });
    $('#img' + id).mouseout(function() {
        $(this).attr('src', _this.imgOffSrc);
        document.getElementById('player' + id).sendEvent('PLAY', 'false');
    });
    window['beolit' + id] =this;
}
Beolit.prototype.checkDisplay = function() {
    this.image.css('display', this.imageOffReady && this.imageOnReady && this.playerReady ? '' : 'none');
}