Suppose I create an object such as YouTube's video player (but not the same, this is just for an example). I want to fire events when the player ends, and when it starts playing, etc.
So in any code by any customer that uses my object, I want him to be able to do something like:
 player.addEventListener("onWeirdPlayerEnded", "somefunction");
I do know that there is such a thing as a javaScript "createEvent" feature such as:
var ppEvent = document.createEvent('CustomEvent');
However, I have some questions about it.

Lets say in my player code, I have function that does something like this:
function reachedEnd() {
// do something
It seems to be that I should fire the event "onWeirdPlayerEnded" at this point (within the function). But I don't think I should create it with "createEvent" at the same time that I fire it. I should just fire it. Creation should have happened earlier.

So what I need to know is:
1. Where and how do I create the event and give a name such as "onWeirdPlayerEnded"
2. How do I fire the event (in the do something... area)
3. Can the customer's use it in his webpage with his "addEventListener".