/**
 * @copyright TryHabbo 2011 - 2012
 * @project TryHabbo Website
 * @revision 1.4.1
 */

jQuery.noConflict();

var TryHabbo = {};
    
    TryHabbo.Global = 
    {
        
        hash: '',
        
        __construct: function()
        {
            
            this.hash = document.location.hash.replace( '#!', '' );
            
            this.detechHash();
                                    
        },
        
        detechHash: function()
        {
            
            if( this.hash.length > 0 )
            {
                
                this.LoadPage( this.hash );

            }
            else
            {
                
                this.LoadPage( '/home' );
                document.location = "#!/home";

            }
            
        },
        
        LoadPage: function( pageName, Cont )
        {
            
            if( !Cont )
            {
            	
            	Cont = 'loadContent';
                jQuery('#' + Cont).html( "<div class='content_top'></div><div class='content_middle'><div class='large_red'><img src='/scripts/genVolter?a=LOADING...&b=red' /></div><div align='center' style='padding:10px'><img src='//th-static.cdn.tryhabbo.net/web/j13hJ/assets/images/loading.gif' /></div></div><div class='content_bottom'></div>" );
                
                jQuery.get(
            
                    "load/" + pageName, 
                    function( data )
                    {  
                    
                        jQuery( '#' + Cont ).html( data );
                        document.location = "#!" + pageName;
                    
                    }
            
                )
            	
            }
            else
            {
                
                jQuery.get(
            
                    "load/" + pageName, 
                    function( data )
                    {  
                    
                        jQuery( '#' + Cont ).html( data );
                    
                    }
            
                )
                
            }
                
        },

    };
		
jQuery( 'form' ).live( 'submit', function( event )
{
  	
  	var divName = jQuery( this ).attr( 'name' );

  	jQuery.post( jQuery( this ).attr( 'action' ), jQuery( this ).serialize(), function( loadForm )
  	{
  		
  		jQuery( divName ).html( loadForm );
  		
  	});
  	
  	return false;
  	
} );

jQuery( function()
{

	jQuery.stylesheetInit();

	jQuery( '#toggler' ).bind(

			'click',
			function( e )
			{

				jQuery.stylesheetToggle();
				return false;

			}

	);

	jQuery( '.styleswitch' ).bind(

			'click',
			function( e )
			{

				jQuery.stylesheetSwitch(this.getAttribute('rel'));
				return false;

			}

	);

});

jQuery( function()
{

	jQuery( '#heart' ).thTooltips( { fade: true } );

} );

jQuery( document ).ready( function()
{

    TryHabbo.Global.__construct();

});
