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

 Author : http://www.yomotsu.net
 created: 2007/11/01
 update : 2008/07/16

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

// Apple detection object
var Apple = {};
Apple.UA = navigator.userAgent;
Apple.Device = false;
Apple.Types = ["iPhone", "iPod", "iPad"];
for (var d = 0; d < Apple.Types.length; d++) {
	var t = Apple.Types[d];
	Apple[t] = !!Apple.UA.match(new RegExp(t, "i"));
	Apple.Device = Apple.Device || Apple[t];
}
// for DEBUG
//Apple.iPad = true;
// is this an Apple device?
//alert(
//	"Apple device? " + Apple.Device +
//	"\niPhone? " + Apple.iPhone +
//	"\niPod? " + Apple.iPod +
//	"\niPad? " + Apple.iPad
//);

/* console.log kill */

if (! ("console" in window) ) {
	var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
	window.console = {};
	for (var i = 0; i <names.length; ++i) window.console[names[i]] = function() {};
}

var yomotsuLoader = {

	conf : {
		loader : 'jsloader.js',
		loadJS : [
			'modernizr-1.7.min.js',
			'jquery.LangSelector.js',
			'jquery.createVideo.js',

			// swipe begen-			
			'jquery.easing.js',
			'jquery-ui-1.8.9.custom.min.js',
			'jquery.ui.swipable.js',
			'jquery.ui.fakepageslide.js',
			'main.js',
			// swipe end--
			
			//'/asset/jme/mm.embed.js',
			'jquery.cookie.js',
			'jquery.ui.transitionChainable.js',
			'jquery.ui.slideGallery.js',
			'jquery.ui.fluidBlocks.js'
			//'misc.js'
		]
	},
	
	main : function(){
		var script = document.getElementsByTagName("script");
		for(var i=0;i<script.length;i++){
			if(script[i].getAttribute("src") && script[i].getAttribute("src").match(yomotsuLoader.conf.loader)){
				
				locationStr = location+""
				var DirArray = new Array();
				var 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 loaderDir = "";
				if(scriptSrc.match(/^http\:|^https\:|^file\:|^\//)){
					loaderDir = scriptSrc.replace(yomotsuLoader.conf.loader,"");
				}
				else {
					var upperDirLength = script[i].getAttribute("src").match(/\.\.\//g) ? script[i].getAttribute("src").match(/\.\.\//g).length : 0 ;
					
					for(j=0;j<(DirArray.length - upperDirLength);j++){
						loaderDir += DirArray[j]+'/'
					}
					loaderDir = loaderDir.slice(0, -1) + '/' + scriptSrc ;
					loaderDir = loaderDir.slice(0,-1 * yomotsuLoader.conf.loader.length);
				}				
		
				for(j=0;j<yomotsuLoader.conf.loadJS.length;j++){
					
					if (!yomotsuLoader.conf.loadJS[j].match(/^\/|^http\:|^https\:|^\.\.\//)) {
						yomotsuLoader.setJS(loaderDir+yomotsuLoader.conf.loadJS[j])
					}
					else if (yomotsuLoader.conf.loadJS[j].match(/^\/|^http\:|^https\:/)) {
						yomotsuLoader.setJS(yomotsuLoader.conf.loadJS[j])
					}
					else if (yomotsuLoader.conf.loadJS[j].match(/^\.\.\//)) {
						
						var setDirArray = new Array();
						
						setDir = loaderDir;
						N=0;
						while (true) {
							setDirArray[N] = setDir.slice(0,setDir.indexOf("/"));
							setDir = setDir.slice(setDir.indexOf("/")+1,setDir.length);
							N++;
							if (setDir.indexOf("/")==-1) {
								break;
							}
						}
						
						upperDirArray = yomotsuLoader.conf.loadJS[j].match(/\.\.\//g);
						var dir =""
						for(k=0;k<(setDirArray.length - upperDirArray.length);k++){
							dir += setDirArray[k]+'/'
						}

						// remove "../"
						yomotsuLoader.conf.loadJS[j] = dir + yomotsuLoader.conf.loadJS[j].replace(/\.\.\//g, "")
						yomotsuLoader.setJS(yomotsuLoader.conf.loadJS[j])
						
					}
				}
				
			break;
			}
		}
	}, // END OF yomotsuLoader.main
		
	setJS : function(filePath){
		document.write('<script type="text/javascript" src="' + filePath + '"></script>');
	}
	
}

yomotsuLoader.main()


