/*
	RadioPlayer Class
	Coded by Moh for use by BobbaFM & HabboPFM only!
*/

var radioPlayerClass = Class.create({

	initialize: function () {	
		
		var so = new SWFObject('_files/player.swf', 'mpl', '1', '1', '9' );
		so.addParam( 'allowfullscreen', 'true' );
		so.addParam( 'allowscriptaccess', 'always' );
		so.addParam( 'wmode', 'opaque' );
		so.addVariable( 'duration', '9999' );
		so.addVariable( 'file', 'http://50.7.243.50:8169/;stream.nsv' );
		so.addVariable( 'provider', 'sound' );
		so.addVariable( 'volume', '50' );
		so.addVariable( 'autostart', 'true' );
		so.addVariable( 'playerready', 'radioPlayer.buildControls' );
		so.write( 'radioswf' );
			
	},
	
	buildControls: function( obj ) {
	
		radioPlayer.player = $( obj['id'] );
						
		radioPlayer.volume = new Control.Slider( $( 'volume' ), $( 'radio_player_volume' ), {
			sliderValue: 0.5,
			onSlide: function( value ) {
				value = value * 100;
				radioPlayer.player.sendEvent( 'volume', value );
			},
			onChange: function( value ) {
				value = value * 100;
				radioPlayer.player.sendEvent( 'volume', value );
			}
		});
		
		$( 'play' ).stopObserving( 'click' );
		$( 'stop' ).stopObserving( 'click' );
		$( 'refresh' ).stopObserving ('click' );
		
		$( 'play' ).observe( 'click', function() {
			radioPlayer.toggle(1);			
		} );
		
		$( 'stop' ).observe( 'click', function() {
			radioPlayer.toggle(2);			
		} );
		
		$( 'refresh' ).observe( 'click', function() {
			radioPlayer = new radioPlayerClass();
			radioPlayer.muted = false;
		} );	
		
	},
	
	toggle: function( act ) {
		
		if( act == 1 ) {
			radioPlayer.muted = false;
			radioPlayer.volume.setValue( 0.5 );
		}
		else if( act == 2 ) {
			radioPlayer.muted = true;
			radioPlayer.volume.setValue( 0 );
		}
		
	},

});

/*
	habboPFM Class
	Coded by Moh for use by BobbaFM & HabboPFM only!
*/

var habboPFMClass = Class.create({

	initialize: function () {	
		
		this.createLinks();
			
	},
	
	createLinks: function( container ) {
	
		container = container ? container + ' ' : '';

		$$( container + 'a[href!=#]' ).each( function( element ) {
						
			if( !element.target && !element.onclick ) {
							
				Event.observe( element, 'click', function( event ) {
					
					event.stop();
										
					href = $( element ).readAttribute( 'href' );
										
					habboPFM.loadPage( href );
					
					
				} );
			
			}
			
		} );
		
	},
	
	loadPage: function( url, container ) {
		
		container = container ? container : 'middle_content';
		
		$( container ).innerHTML = '<br /><div align="center"><img src="_images/_layout/loader.gif" alt="Loading" /></div>';
		
		hideQtips();
		
		if( url.match("content/values") ) {
			$('rare_categories').show();
		} else {
			$('rare_categories').hide();
		}
		
		new Ajax.Updater( container, url, {
			
			method: 'get',
			evalScripts: true,
			
			onComplete: function() {
	
				habboPFM.thisPage = url;
				
				habboPFM.createLinks( '#' + container );
				
				jQuery( '#' + container + ' .tooltip[title]').qtip({ position:{ at: 'top center', my: 'bottom center' }, style: { classes: 'ui-tooltip-light ui-tooltip-rounded' } });
				jQuery.address.value(url);
				
			}
			
		});
		
	},

});

function hideQtips() {
	//jQuery'.tooltip[title]').qtip("destroy");

	jQuery('.ui-tooltip').qtip('hide');

}

document.observe( 'dom:loaded', function() {
	jQuery( '.tooltip[title]').qtip({ position:{ at: 'top center', my: 'bottom center' }, style: { classes: 'ui-tooltip-light ui-tooltip-rounded' } });
	radioPlayer = new radioPlayerClass();
	habboPFM = new habboPFMClass();
	
	hash = document.location.hash.replace( '#', '' );
	url = hash ? hash : 'content/home.php';
	
	habboPFM.thisPage = url;
	
	habboPFM.loadPage( habboPFM.thisPage );

	jQuery.address.externalChange(function(event) {
		if( event.value != "/" ) {
			habboPFM.loadPage( "/v2" + event.value  );
		}
	});	
});
