/**
 *  This file is part of Noticias MVS.
 *
 *  Noticias MVS is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Noticias MVS is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Noticias MVS.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package public
 * @subpackage js
 * @author Óscar Palacios <oscarpalacious@gmail.com>
 * @author Ignacio Castañeda <ictsac@gmail.com>
 * @copyright Copyright (c) 2010, Óscar Palacios, Ignacio Castañeda
 * @license http://www.gnu.org/licenses/gpl.html GNU Public License
 *
 * Basado en el código de niftyplayer:
 * http://www.varal.org/niftyplayer/
 * Éste a su vez tiene licencia MIT:
 * http://www.opensource.org/licenses/mit-license.php
 */


/*
 * "Cargador" del objeto.
 */
var FlashHelper = {
	movieIsLoaded : function(theMovie) {
		if(typeof(theMovie) != 'undefined') return theMovie.PercentLoaded() == 100;
		else return
		false;
	},

	getMovie : function(movieName) {
		if(navigator.appName.indexOf('Microsoft') !=-1) return window[movieName];
		else return document[movieName];
	}
};


/*
 *  Controles básicos del player.
 */
var playerObject = {

	player : function() {
		this.obj = FlashHelper.getMovie('playerNoticiasv2');
		//if(!FlashHelper.movieIsLoaded(this.obj)) return;

		this.play = function() {
			this.obj.TCallLabel('/','play');
		};
		this.stop = function() {
			this.obj.TCallLabel('/','stop');
		};
		this.pause = function() {
			this.obj.TCallLabel('/','pause');
		};
		this.playToggle = function() {
			this.obj.TCallLabel('/','playToggle');
		};
		this.reset = function() {
			this.obj.TCallLabel('/','reset');
		};
		this.load = function(url) {
			this.obj.SetVariable('currentSong', url);
			this.obj.TCallLabel('/','load');
		};
		this.loadAndPlay = function(url) {
			this.load(url);
			this.play();
		};
		this.getState = function() {
			var ps = this.obj.GetVariable('playingState');
			var ls = this.obj.GetVariable('loadingState');
			if(ps == 'playing')
				if (ls == 'loaded') return ps;
				else return ls;
			if(ps == 'stopped')
				if(ls == 'empty') return ls;
				if(ls == 'error') return ls;
				else return ps;
			return ps;
		};
		this.getPlayingState = function() {
			return this.obj.GetVariable('playingState');
		};
		this.getLoadingState = function() {
			return this.obj.GetVariable('loadingState');
		};
		this.registerEvent = function(eventName, action) {
			this.obj.SetVariable(eventName, action);
		};
		return this;
	}
};
