/*
**	JW Player Javascript Interface
**
**	(c) 2010 Mikoon Webservices
*/

var JWPlayer = new Class({
	
	Implements: Options,
	
	options: {
		id: 'mediaplayer',
		debug:false		
    },
	
	initialize: function(options){
		
		//	setup options
		this.setOptions(options);
		
		// get base elements
		this.player = this.get_flash_object(this.options.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");
	},

	next: function(){
		this.player.sendEvent("NEXT", "true");	
	},
	
	prev: function(){
		this.player.sendEvent("PREV", "true");	
	},

	queue: function(item_nr){
		this.player.sendEvent("ITEM", item_nr);
		this.pause();
		this.stop();
	},

	get_playlist: function(){
		return this.player.getPlaylist();
	},

	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);
		  	}
		}
	}

});
