﻿var player = null;
var pathtmp = null;
//kliknieta mp3
var objplay = null;

function playerReady(thePlayer) {
    player = document.getElementById('playerbg');
    addListeners();
}

function addListeners() {
    if (player) {
        player.addModelListener("STATE", "stateListener");
    } else {
        setTimeout("addListeners()", 1);
    }
}

function play(obj,path) {
    jQuery(".listen a img").attr("src", "/jedynka/_img/listen.gif");
    objplay = jQuery(obj);
	//play
	if (tmp==false){
	player.sendEvent('LOAD', path);
    objplay.find("img").attr("src", "/jedynka/_img/stop.gif");
	}
	else
	{
		player.sendEvent('STOP');
        objplay.find("img").attr("src", "/jedynka/_img/listen.gif");
        tmp = false;
	}
    
}

function stateListener(obj) {
    //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
    currentState = obj.newstate;
    previousState = obj.oldstate;

    if ((currentState == "COMPLETED") && (previousState == "PLAYING")) {
        objplay.find("span").text("");
        objplay.find("img").attr("src", "/jedynka/_img/listen.gif");
        tmp = false;
    }
    if (currentState == "PLAYING") {
        objplay.find("span").text("");
        tmp = true;
    }
    if (currentState == "BUFFERING") {
        objplay.find("span").text("");
    }
}