/* -------------------------------------------------------------------------- */
/** 
 *    @fileoverview
 *       external js/css files loader.
 *
 *    @version 1.0.20101206
 */
/* -------------------------------------------------------------------------- */

if(typeof CWJL=="undefined"){
	CWJL={}
}

CWJL.ImportJS=function(B){
	if(!B||typeof B!="string"){
		throw new TypeError("CWJL.ImportJS: first argument must be a file name or file path or full URL.")
	}else{
		var D=arguments.callee;
		var A=(B.match("/"))?"":D.dir;
		var C=A+B;
		if(!D.isImported(C)){
			if(D.isCapableOfDOM()){
				(D.getHeadElement().appendChild(document.createElement("script"))).src=C
			}else{
				document.write('<script type="text/javascript" src="'+C+'"><\/script>')
			}
			D.imported.push(C)
		}
	}
};

CWJL.ImportJS.dir="./";
CWJL.ImportJS.imported=[];
CWJL.ImportJS.isImported=function(C){
	if(!C||typeof C!="string"){
		throw new TypeError("CWJL.ImportJS.isImported: first argument must be a file name or file path or full URL.")
	}else{
		for(var A=0,B=false;(A<this.imported.length&&!B);A++){
			B=(this.imported[A]==C)
		}return B}
};

CWJL.ImportJS.isCapableOfDOM=function(){
	return false
};

CWJL.ImportJS.getHeadElement=function(){
	var A=arguments.callee;
	return A._cache_||(A._cache_=document.getElementsByTagName("head")[0])
};

CWJL.ImportJS.from=function(D){
	if(!D||typeof D!="string"){
		throw new TypeError("CWJL.ImportJS.from: first argument must be a directory path or a file name.")
	}else{
		if(D.match("/")){
			if(D.substr(D.length-1)!="/"){
				throw new TypeError("CWJL.ImportJS.from: first argument must end with '/' in the case of specifying directory path.")
			}else{
				this.dir=D
			}
		}else{
			var B=this.getHeadElement().getElementsByTagName("script");
			for(var C=0,E=B.length;C<E;C++){
				var A=B[C].src.split("/");
				if(A.pop()==D){
					this.dir=A.join("/")+"/";
					break
				}
			}
		}
	}return this.dir
};

CWJL.ImportCSS=function(D,C){
	if(!D||typeof D!="string"){
		throw new TypeError('CWJL.ImportCSS: argument "path" must be a file name or file path or full URL.')
	}else{
		if(C&&typeof C!="string"){
			throw new TypeError('CWJL.ImportCSS: argument "media" must be a string.')
		}else{
			var F=arguments.callee;
			var A=(D.match("/"))?"":F.dir;
			var E=A+D;
			if(!F.isImported(E)){
				if(F.isCapableOfDOM()){
					var B=document.createElement("link");
					B.rel="stylesheet";
					B.type="text/css";
					B.href=E;
					B.media=C||"all";
					F.getHeadElement().appendChild(B)
				}else{
					document.write('<link rel="stylesheet" type="text/css" href="'+E+'" media="'+(C||"all")+'" />')
				}
				F.imported.push(E)
			}return B
		}
	}
};

CWJL.ImportCSS.dir="./";
CWJL.ImportCSS.imported=[];
CWJL.ImportCSS.isImported=CWJL.ImportJS.isImported;
CWJL.ImportCSS.isCapableOfDOM=CWJL.ImportJS.isCapableOfDOM;
CWJL.ImportCSS.getHeadElement=CWJL.ImportJS.getHeadElement;
CWJL.ImportCSS.from=function(A){
	if(!A||typeof A!="string"){
		throw new TypeError("CWJL.ImportCSS.from: first argument must be a directory path or a file name.")
	}else{
		if(A.match("/")){
			if(A.substr(A.length-1)!="/"){
				throw new Error("CWJL.ImportCSS.from: first argument must end with '/' in the case of specifying directory path.")
			}else{
				this.dir=A
			}
		}else{
			throw new Error("CWJL.ImportCSS.from: first argument must end with '/' in the case of specifying directory path.")
		}
	}return this.dir
};


/* --------------- import external scripts --------------- */

CWJL.ImportJS.from('http://www.cwj.jp/common/js/');   // URL/path to js-directory, or filename of this file.

CWJL.ImportJS('jquery.js');
CWJL.ImportJS('jquery.easing.js');
CWJL.ImportJS('jquery.validate.js');
CWJL.ImportJS('jquery.mousewheel.js');
CWJL.ImportJS('jquery.cookie.js');
CWJL.ImportJS('jquery.json.js');

CWJL.ImportJS('cwj.js');
CWJL.ImportJS('cwj.rollover.js')
CWJL.ImportJS('cwj.scroller.js');
CWJL.ImportJS('cwj.fontSizeObserver.js');
CWJL.ImportJS('cwj.flatHeights.js');
//CWJL.ImportJS('cwj.tabView.js');
CWJL.ImportJS('cwj.setting.js');
CWJL.ImportJS('cwj.address.js');
