/********************************************************

	最終配置ロジック

*******************************************************/

/********************************************************
 2重押し防止対策
*******************************************************/
var loadWindow = function(invocation) {
	aroundOnclick(document);
	return invocation.proceed();
}

function aroundOnclick( item ) {
	if( item == null ) { return; }

	if( item.onclick != null || item.href != null
		|| ( item.type != null && ( item.type == "submit" || item.type == "image" ) ) ) {
		Object.Aspect.around( item, "onclick", checkBusy );
		return;
	}

	if( item.childNodes == null ) {
		return;
	}

	var length = item.childNodes.length;
	for( var i = 0; i < length; i++ ) {
		aroundOnclick( item.childNodes[i] );
	}

	return;
}

var checkBusy = function( invocation ) {
	if( isLoading() ) {
		return false;
	}
	return invocation.proceed();
}

Object.Aspect = {
	_around : function( target, methodName, aspect ) {
		var method = target[methodName];
		target[methodName] = function() {
			var invocation = {
				"target" : this,
				"method" : method,
				"methodName" : methodName,
				"arguments" : arguments,
				"proceed" : function() {
					if( !method ) {
						return true;
					}
					return method.apply( target, this.arguments );
				}
			};
			return aspect.apply( null, [invocation] );
		};
	},

	around : function( target, methodNames, aspect ) {
		this._around( target, methodNames, aspect );
	}
}

Object.Aspect.around( window, "onload", loadWindow );


