/* $Id: player.js, v0.1 - 26/08/08 21:06:01, http://neverbesilent.org, http://remidian.com Exp $ */
/** http://www.daniel-skinner.co.uk/chaining-with-mootools-12-tutorial/31/01/2008 */
/** http://www.mootorial.com/wiki/mootorial/09-howtowriteamootoolsclass */



var rmi_ajx_player = new Class({

	Implements: [ Options, Chain],

	options: {
		s_url: '',
		s_html_init: _SAJXINIT,
		n_top: 200,
		n_left: 200,
		n_width: 500,
		n_height: 300
	},


	initialize: function( options) {
		this.setOptions(options);
		
		if ( $('ajx-player-canvas'))
			$('ajx-player-canvas').dispose();
	},


	start: function() {
		el_playr = new Element('div', {
			'id': 'ajx-player-canvas',
			'class': 'ajx-player-canvas-loading'
		});
		el_playr.injectInside ( $('wrapper-columns'));

		this.el_playr = el_playr;
		this.el_morph = new Fx.Morph( this.el_playr, {'duration': 500, 'wait': false});

		this.chain(
            function() { this.el_open (); },
            function() { this.el_request (); }
    );

		this.el_open ();
	},


	el_open: function () {
		this.el_playr.setStyles({ 'display': 'block', 'cursor': 'move'});
		this.el_playr.set( 'html', '<div id="ajx-player-canvas-menu"><div id="ajx-player-canvas-menu-text">' + this.options.s_html_init + '</div><a href="javascript://" id="ajx-player-canvas-menu-close">x</a></div>');
		$('ajx-player-canvas-menu-close').addEvent('click', this.el_close.bind(this));
		this.el_morph.start({
				'top': [ 0, this.options.n_top],
				'width': [ this.options.n_width],
				'height': [ this.options.n_height]
		});
		this.el_playr.makeDraggable();
		this.callChain();
	},
	
	
	el_close: function () {
		$('ajx-player-canvas').set( 'text', '');
			$('ajx-player-canvas').set( 'html', '');
			this.el_morph.start({
				'opacity': 0
			}).chain( function() {
				$('ajx-player-canvas').dispose();
			});
			return false;
	},
	

	el_request: function () {
		var req = new Request.HTML({
			url :  this.options.s_url,
			onFailure	: function () {
					$( 'ajx-player-canvas').set( 'html', 'error occured');
			},
					/** onSuccess	: function(html) {*/
			onComplete: function ( responseTree, responseElements, responseHTML, responseJavaScript) {
				$( 'ajx-player-canvas').set( 'html', responseHTML);
				$( 'ajx-player-canvas').removeClass( 'ajx-player-canvas-loading');
				$('ajx-player-canvas-menu-close').addEvent('click', function() {
					$('ajx-player-canvas').set( 'text', '');
					_morph = new Fx.Morph( $('ajx-player-canvas'), {'duration': 500, 'wait': false});
					_morph.start({
						'opacity': 0
					}).chain( function() {
						$('ajx-player-canvas').dispose();
					});
					return false;

				});
			}
		}).send();
		this.callChain();
	}
	
	
})





window.addEvent( 'domready', function() {

	$('trigger-player-infolive').addEvent( 'click', function(el) {
		var pos = this.getPosition() ;
		i_player = new rmi_ajx_player({
			's_url': _URL_TEMPLATE_JS + '/include/_html/_infolive.ajx.php?l=' + _CUR_LANG,
			'n_top': pos['y'] - 100,
			'n_height': 300,
			'n_width': 500			
		});
		i_player.start();
			/** return false prevents freeze of player */
						return false;
	})
	$('trigger-player-jlemonline').addEvent( 'click', function(el) {
		var pos = this.getPosition() ;
		i_player = new rmi_ajx_player({
			's_url': _URL_TEMPLATE_JS + '/include/_html/_jlemonline.ajx.php?l=' + _CUR_LANG + '&t=' + _TEMPLATE,
			'n_top': pos['y'] - 100,
			'n_height': 394,
			'n_width': 500			
		});
		i_player.start();
			/** return false prevents freeze of player */
						return false;
	})
	
	
	/*
	$('kotelcam-stream-1').addEvent( 'click', function(el) {
		var pos = this.getPosition() ;
		i_player = new rmi_ajx_player({
			's_url': SURLTMPL + '/include/_html/_wallcam.ajx.php?s=0',
			'n_top': pos['y'] - 400,
			'n_height': 300,
			'n_width': 500
		});
		i_player.start();
	})
	*/
	
/*
stable
	$$('.kotelcam-stream').each( function( el, i) {
		el.addEvent( 'click', function(el) {
			
			//alert(Browser.Engine.trident); 
			if (Browser.Engine.trident) {
			
			}	
			
			var pos = this.getPosition() ;
			i_player = new rmi_ajx_player({
				's_url': SURLTMPL + '/include/_html/_wallcam.ajx.php?s=' + i + '&w=500&h=300&t=' + STEMPLAT + '&b=' + Browser.Engine.trident,
				'n_top': pos['y'] - 30,
				'n_height': 300,
				'n_width': 500
			});
			i_player.start();
		})	
	})
*/


})
