﻿/*====================================================================================================
//////////////////////////////////////////////////////////////////////////////////////////////////////

 Author : http://www.yomotsu.net
 created: 2007/11/01
 update : 2007/12/22
 Licensed under the GNU Lesser General Public License
 JSを読み込むためのスクリプト

//////////////////////////////////////////////////////////////////////////////////////////////////////
====================================================================================================*/

var yomotsuLoader = {

	conf : {
		thisName : "import.js",
		loadJS   : ["default.js","jquery.js","iepngfix.js","smartRollover.js","jquery.page-scroller-306.js","CurrentOn.js","styleswitcher.js","googlemap.js","jpreLoad.js","jquery.flatheights.js"]
	},

	
	main : function(){
		var script = document.getElementsByTagName("script");
		for(i=0;i<script.length;i++){
			if(script[i].getAttribute("src").indexOf(yomotsuLoader.conf.thisName)!=0){
								
				locationStr = location+""
				var DirArray = new Array();
				N=0;
				while (true) { 
				 DirArray[N] = locationStr.slice(0,locationStr.indexOf("/"));
				 locationStr = locationStr.slice(locationStr.indexOf("/")+1,locationStr.length);
				 N++;
				 if (locationStr.indexOf("/")==-1) {
					break;
				 }
				}
				
				
				var scriptSrc = script[i].getAttribute("src");
				scriptSrc      = scriptSrc.replace(/\.\.\//g, "");
				var upperDirLength = script[i].getAttribute("src").match(/\.\.\//g) ? script[i].getAttribute("src").match(/\.\.\//g).length : 0 ;
				
				var thisDir = ""
				for(j=0;j<(DirArray.length - upperDirLength);j++){
					thisDir += DirArray[j]+'/'
				}
				thisDir = thisDir.slice(0, -1) + '/' + scriptSrc ;
				thisDir = thisDir.slice(0,-1 * yomotsuLoader.conf.thisName.length)
		

		
				for(j=0;j<yomotsuLoader.conf.loadJS.length;j++){
					
					if (!yomotsuLoader.conf.loadJS[j].match(/^\/|^http\:|^https\:|^\.\.\//)) {
						yomotsuLoader.writeJS(thisDir+yomotsuLoader.conf.loadJS[j])
					}
					else if (yomotsuLoader.conf.loadJS[j].match(/^\/|^http\:|^https\:/)) {
						yomotsuLoader.writeJS(yomotsuLoader.conf.loadJS[j])
					}
					else if (yomotsuLoader.conf.loadJS[j].match(/^\.\.\//)) {
						
						var writeDirArray = new Array();
						
						writeDir = thisDir;
						N=0;
						while (true) { 
							writeDirArray[N] = writeDir.slice(0,writeDir.indexOf("/"));
							writeDir = writeDir.slice(writeDir.indexOf("/")+1,writeDir.length);
							N++;
							if (writeDir.indexOf("/")==-1) {
								break;
							}
						}
						
						upperDirArray = yomotsuLoader.conf.loadJS[j].match(/\.\.\//g);
						var dir =""
						for(k=0;k<(writeDirArray.length - upperDirArray.length);k++){
							dir += writeDirArray[k]+'/'
						}

						// remove "../"
						yomotsuLoader.conf.loadJS[j] = dir + yomotsuLoader.conf.loadJS[j].replace(/\.\.\//g, "")
						yomotsuLoader.writeJS(yomotsuLoader.conf.loadJS[j])
						
					}
				}
				
			break;
			}
		}
	}, // END OF yomotsuLoader.main
		
	writeJS : function(filePath){
		script = document.createElement("script");
		script.setAttribute("src",filePath);
		script.setAttribute("type","text/javascript");
		document.getElementsByTagName("head")[0].appendChild(script);
	}
	
}

yomotsuLoader.main()
