/*Create an event class called 'myEvent'.
* We pass a callback function that will alert the value stored
* in the 'data' properties of the event object thrown.
* Arguments are :
* @name:string required  
* @data:object 
* @callback:function(ev:EventClass that is thrown)
*/					
var myEvent = new OPS.Factory.Event('myEvent','',function(ev){
		alert('This is the callback of the Event Class myEvent' + '\n' + 
			   'And this is the value from the source input :' + ev.getData());
	}
);

/*The event must be registered in the OPS Events manager engine.
* This will possibly change in next release where creating an event
* will also register it automatically.
*/
OPS.Events.addEvent(myEvent);

/*This is a simple listener that simply read the value that the event carry
* and write it on the document.Any listeners receive the event thrown as argument.
*/
var myFunction = function(ev){
	document.getElementById('target').innerHTML = ev.getData();
} 

/*Now I can subscribe myFunction to listen for myEvent
* Note that the function will be called when an Event with the same 'Name' properties
* of the registered event is thrown. An interface check that the event thrown has the required
* methods. ( setter/getter for properties name,data,callback)
*/
OPS.Events.subscribe( myFunction , myEvent );

/* Event can now be dispatched. We can dispatched the already craeted myEvent class 
* or create a new class with the same name.
* In this case we add to the event 'data' properties the value of an html element
*/
$(document).ready(function(){
	$('.dispatch').click(function(){
		myEvent.setData(document.getElementById('source').value);
		OPS.Events.dispatchEvent(myEvent);
	});
});	
