/*!
 * Copyright 2010, Root-Sea
 */

////// 矩形を作る //////
function makeRectangle(id, x, y, w, h, color, alpha, pos) {
	
	//divを作る
	var ds = document.createElement('div');
	ds.setAttribute('id', id);
	if (pos != undefined) {
		ds.style.position = pos;
	}
	ds.style.left = x + 'px';
	ds.style.top = y + 'px';
	ds.style.width = w + 'px';
	ds.style.height= h + 'px';
	
	//ブラウザごとの処理の場合分け
	var userAgent = window.navigator.userAgent.toLowerCase();
	if (userAgent.indexOf("msie") > -1) {
		ds.style.display = 'none';
		ds.style.backgroundColor = color;
		if (alpha < 100) ds.style.filter='alpha(opacity=' + alpha + ')';
	} else {
		ds.style.backgroundColor = color;
		if (alpha < 100) ds.style.opacity = alpha / 100;
	}
	
	if (userAgent.indexOf("msie") > -1) {
		ds.style.display = '';
	}
	
	return ds;
}



////// 動的スクリプトローディング //////
var aJS = new Array();

//読み込んだJSファイルの数
var cntJS = 0;

//読み込むべきJavaScriptファイル名を追加する
function addJSFile(file) {
	aJS.push(file);
}

//JSファイルを動的に読み込む
function JavaScriptLoader(src, callback){
	
	var sc = document.createElement('script');
	sc.type = 'text/javascript';
	if (window.ActiveXObject) {
		sc.onreadystatechange = function(){
			if (sc.readyState == 'complete') callback();
			if (sc.readyState == 'loaded') callback();
		};
	} else {
		sc.onload = function(){
			callback();
		};
	}
	sc.src = src;
	document.body.appendChild(sc);
}

//JSファイルを順番に読み込む
function nextLoad() {
	cntJS++;
	
	if (cntJS < aJS.length) {
		JavaScriptLoader(aJS[cntJS], nextLoad);
	}
}

//JSファイルが全部読み込まれたかどうか、チェックする
function isLoaded() {
	return (cntJS == aJS.length && cntJS > 0);
}
