/*
**	JW/Longtail Player Javascript class
**
**	(c) 2010 Mikoon Webservices
*/

/*
**	Usage:
**
**	myplayer = new JWPlayer('element-id', {options});
*/

var JWPlayer = new Class({
	
	Implements: Options,
	
	options: {
		debug:false		
    },
	
	initialize: function(id, options){
		//	setup options
		this.setOptions(options);
		// get base elements
		this.player = this.get_flash_object(id);
	},

	play: function(){
		this.player.sendEvent("PLAY","true");
	},
	
	load: function(in_url){
		this.player.sendEvent("LOAD", in_url);
	},
	
	pause: function(){
		this.player.sendEvent("PLAY", false);
	},
	
	stop: function(){
		this.player.sendEvent("STOP","true");
	},
	
	seek: function(in_seconds){
		this.pause();
		this.player.sendEvent("SEEK", in_seconds);
		this.play();
	},

	queue: function(item_nr){
		this.player.sendEvent("ITEM", item_nr);
		this.pause();
		this.stop();
	},

	ondone: function(in_function){
		this.player.addModelListener("STATE", in_function);
	},
	
	removelistener: function(in_event, in_function){
		this.player.removeModelListener(in_event, in_function);
	},

	get_flash_object: function(in_id){
		if (window.document[in_id]){
			return window.document[in_id];
		}
		if (navigator.appName.indexOf("Microsoft Internet")==-1){
		    if (document.embeds && document.embeds[in_id]){
      			return document.embeds[in_id]; 
		  	} else {
		    	return document.getElementById(in_id);
		  	}
		}
	}

});
