$( function() {

	$( 'div#loading' ).remove();

   $( 'body' ).noisy( { opacity: 0.05 } );
   $( 'div#content_tabs' ).tabs( { fx: { height: 'toggle', duration: 'slow' } } );
   $( 'div#resources_tabs' ).tabs( { fx: { height: 'toggle', duration: 'slow' } } );
   $( 'div#usables_tabs' ).tabs( { fx: { height: 'toggle', duration: 'slow' } } );

   $( 'div#navigation a' ).click( function() {

	$( 'div#navigation a' ).removeAttr( 'id' );
	$( this ).attr( 'id', 'selected' );

   } );

   $( window ).scroll( function() {

	if( $( window ).scrollTop() > 400 ) {

	   $( '.scrollTop' ).fadeIn();

	} else {

	   $( '.scrollTop' ).fadeOut( 'slow' );

	}

   } );

   $( 'div#usables form' ).live( 'submit', function() {

	var error;
	var thehead = $( this ).parent().attr( 'id' );
	var thevalue = $( this ).serialize();
	var theresult = $( 'div#' + thehead + '_result' );

	$( theresult ).css( 'display', 'none' );

	$( 'input:text, select', this ).each( function() {

	   if( $( this ).val() == '' ) {

		error = 'yes';
		$( this ).focus();

	   }

	} );

	if( error != 'yes' ) {

	   var constructUrl = 'http://habboemotion.com/usables/' + thehead + '/?' + thevalue;
	   var constructBbcode = '[url="http://habboemotion.com"][img]' + constructUrl + '[/img][/url]';
	   var constructHtml = '<a href="http://habboemotion.com" target="_blank"><img src="' + constructUrl + '" alt="" /></a>';

	   $( theresult ).css( 'display', 'inline' );

	   $( 'img#preview', theresult ).attr( 'src', constructUrl );
	   $( 'input#direct', theresult ).val( constructUrl );
	   $( 'input#html', theresult ).val( constructHtml );
	   $( 'input#bbcode', theresult ).val( constructBbcode );

	}

	return false;

   } );

} );

var _gaq = _gaq || [];
_gaq.push( [ '_setAccount', 'UA-6939691-1' ] );
_gaq.push( [ '_trackPageview' ] );

( function() {

    var ga = document.createElement( 'script' );
    ga.type = 'text/javascript';
    ga.async = true;
    ga.src = ( 'https:' == document.location.protocol ? 'https://ssl' : 'http://www' ) + '.google-analytics.com/ga.js';

    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore( ga, s );

} )();
