$(function(){
	var params = new Object();
	var search = window.location.search;
	if( search ) {
		search = search.substring( 1 );
		var pairs = search.split( '&' );
		for( var i = 0; i < pairs.length; i++ ) {
			if( pairs[ i ] ) {
				var pair = pairs[ i ].split( '=' );
				params[ pair[ 0 ] ] = pair[ 1 ];
			}
		}
	}

	$( 'body' ).append( '<div id="content-disabled" style="display: none;">&nbsp;</div>' );
	$( 'body' ).append( $( '.trading-table' ) );
	$( '#content-disabled' ).click(
		function() {
			hideAllTables();
			disableContent( false );
		}
	);

	$( window ).resize(
		function() {
			setBlockSize();
		}
	);

	function hideAll() {
		$( '.c-shadow' ).hide();
		$( '.bill-block' ).addClass( 'off' );
	}
	
	function hideAllTables() {
		$( '.trading-table' ).hide();
		$( '.clone' ).addClass('hidden');
		$( '.main' ).height( 'auto' );
	}
	
	function setBlockSize() {
		var block = $( '#content-disabled' );
		if( block.is( ':hidden' ) ) return false;
		block.css({
			'width': $( document ).width() + 'px',
			'height': $( document ).height() + 'px'
		});
	}
	
	function disableContent( flag ) {
		var block = $( '#content-disabled' );
		if( flag ) {
			block.show();
			setBlockSize();
		} else {
			block.hide();
		}
	}

	$( '.bill-block' ).each(
		function() {
			var _self = $( this );
			var id = _self.attr( 'id' );
			_self.find( '.o-but a' ).click(
				function( ev ) {
					ev = ev || window.event;
					ev.preventDefault ? ev.preventDefault() : ev.returnValue = false;
					hideAll();
					_self.removeClass( 'off' );
					if( id ) {
						$( '#info-' + id ).show();
						$( '#bill' ).addClass( 'line' );
						//var gwoTracker=_gat._getTracker( "UA-9818349-1" );
						//gwoTracker._trackPageview( "/2488757588/goal" );
					}
				}
			);

			_self.find( '.b-but a' ).not( '#mt5' ).click(
				function( ev ) {
					ev = ev || window.event;
					ev.preventDefault ? ev.preventDefault() : ev.returnValue = false;

					if( id ) {
						var table = $( '#table-' + id );
						table.show();
						if( $( '.main' ).height() < table.height() + 50 ) {
							$( '.main' ).height( table.height() + 50 );
						}
						disableContent( true );
					}
				}
			);

		}
	)

	$( '.trading-table' ).each(
		function() {
			var _self = $( this );
			_self.find( '.p-close span' ).click(
				function() {
					hideAllTables();
					disableContent( false );
				}
			);
		}
	);

	$( ".level-two div" ).click(function() {
		clickId = $(this).attr("id");
		$("div.sub-grad-min").hide();
		$("div." + clickId).show();
	});

	$("div.sub-grad-min p.p-close").click(function() {
		$(this).parent().parent().hide();
	});

	if( params[ 'type' ] ) {
		$( '#' + params[ 'type' ] + ' .o-orange a' ).click();
	}
	
	document.onready = function() {
		if( params[ 'trade_type' ] ) {
			$( '#' + params[ 'trade_type' ] + ' .b-but a' ).click();
		}
	};

	PageStatus.ActionData.AddAction( 'btn', function( id ) {
	    $(  '#' + id + ' .o-but a' ).click() 
    });
})





