//-----------------------------------------------------
//  setting
//-----------------------------------------------------
var yomotsuBoxWidth = 704;


//-----------------------------------------------------
//  HTTP Request
//-----------------------------------------------------

var getData = function(URI,targetID){

	var req = window.XMLHttpRequest ? new XMLHttpRequest() : (function() {
			try      { return new ActiveXObject("Msxml2.XMLHTTP");    }
			catch(e) { return new ActiveXObject("Microsoft.XMLHTTP"); }
	})();

	req.onreadystatechange = function(){ 
		if (req.readyState != 4 ) return ;
		if (req.status == 200 || req.status==0) { 
			
			var resText = req.responseText;
			if ( navigator.appVersion.indexOf( "KHTML" ) > -1 ) {
				var esc = escape( resText );
				if ( esc.indexOf("%u") < 0 && esc.indexOf("%") > -1 ) {
					resText = decodeURIComponent( esc );
				}
			}
			
			document.getElementById(targetID).innerHTML = resText;
			
		}
	}
	
	req.open('GET', URI, true); 
	req.send(null);
}

//-----------------------------------------------------
//  Page coordinates
//-----------------------------------------------------

var getPageSize = function(){
	var w1=w2=h1=h2=0, width, height;
			
	if (document.documentElement) {
		w1 = document.documentElement.scrollWidth;
		h1 = document.documentElement.scrollHeight;
	}
	
	if (document.body) {
		w2 = document.body.scrollWidth;
		h2 = document.body.scrollHeight;
	}
	
	var width  = Math.max(w1, w2);
	var height = Math.max(h1, h2);
		
	return {width: width, height: height};
}

//---------------------------

var getPageOffset = function(){
	var xOffset  = document.body.scrollLeft || document.documentElement.scrollLeft;
	var yOffset  = document.body.scrollTop  || document.documentElement.scrollTop;
	return {xOffset: xOffset, yOffset: yOffset};
}

//-----------------------------------------------------
//  content area
//-----------------------------------------------------

var yomotsuBox = {
	
	start : function(){
		try {
			window.addEventListener('load', yomotsuBox.trigger, false);
		} catch (e) {
			window.attachEvent('onload', yomotsuBox.trigger);
		}
	},
	
	trigger : function(){
	 var a = document.getElementsByTagName("a");
	 for(var i=0; i<a.length; i++){
		if(a[i].className.match(/\bshow-details\b/)){
			a[i].onclick = function(){
				yomotsuBox.set(this.href);
				return false;
			}
		}
	 }
	},

	set : function(URI){
	
		if(document.getElementById("show-details")) return;
		
		var yomotsuBox = document.createElement("div");
		yomotsuBox.id = "show-details";
		yomotsuBox.style.width    = yomotsuBoxWidth + "px";
		yomotsuBox.style.position = "absolute";
		yomotsuBox.style.zIndex   = "100";
		yomotsuBox.style.top  = getPageOffset().yOffset + 100 + "px";
		yomotsuBox.style.left = getPageSize().width / 2 - (yomotsuBox.style.width.slice(0,-2) / 2) + "px";
		
		document.body.appendChild(yomotsuBox);
		backScreen.set();
		
		getData(URI,yomotsuBox.id); // show-details innerHTML
		
	},
	
	remove : function(){
		var yomotsuBox = document.getElementById("show-details");
		if(yomotsuBox)
		document.body.removeChild(yomotsuBox);
		backScreen.remove();
	}
	
}

yomotsuBox.start()


//-----------------------------------------------------
//  backScreen
//-----------------------------------------------------


var backScreen = {

	alpha : 0,
	
	set : function(){
		this.hideSelectElements(); // for IE 6 select-zIndex BUG	
		var backScreen = document.createElement("div");
	
		backScreen.id = "back-screen";
		backScreen.style.position = "absolute";
		backScreen.style.left     = 0;
		backScreen.style.top      = 0;
		backScreen.style.zIndex   = 99;
		backScreen.style.width    = getPageSize().width  +"px";
		backScreen.style.height   = getPageSize().height +"px";
		backScreen.style.backgroundColor = "#000";
		backScreen.style.filter     ="alpha(opacity="+this.alpha*100+")";
		backScreen.style.MozOpacity =this.alpha;
		backScreen.style.opacity    =this.alpha;
		
		document.body.appendChild(backScreen);
		
		this.alpha = 0;
		this.fadeIn();
	},
	
	fadeIn : function(){
		var backScreen = document.getElementById("back-screen");
		this.alpha += 0.07;
		if(backScreen.style.opacity)        	backScreen.style.opacity    = this.alpha;
		else if(backScreen.style.MozOpacity)	backScreen.style.MozOpacity = this.alpha;
		else if(backScreen.style.filter)	    backScreen.style.filter     = "alpha(opacity="+this.alpha*100+")";
		if (this.alpha < 0.7) {
			backScreen.onclick = function(){return};
			window.setTimeout("backScreen.fadeIn()", 25);
		}
		else {
			backScreen.onclick = yomotsuBox.remove;
		}
	},
	
	fadeOut : function(){
		var backScreen = document.getElementById("back-screen");
		backScreen.onclick = function(){return};
		this.alpha -= 0.07;
		if(backScreen.style.opacity)        	backScreen.style.opacity    = this.alpha;
		else if(backScreen.style.MozOpacity)	backScreen.style.MozOpacity = this.alpha;
		else if(backScreen.style.filter)	    backScreen.style.filter     = "alpha(opacity="+this.alpha*100+")";
		if (this.alpha > 0.07) {
			window.setTimeout("backScreen.fadeOut()", 25);
		}
		else{
			document.body.removeChild(backScreen);
			this.alpha = 0;
		}
	},
	
	remove : function(){
		var backScreen = document.getElementById("back-screen");
		if(backScreen)
			this.fadeOut();
		this.showSelectElements(); // for IE 6 select-zIndex BUG	
	},
	
	fix : function(){
		var backScreen = document.getElementById("back-screen");
		if(backScreen){
			backScreen.style.width  = getPageSize().width  +"px";
			backScreen.style.height = getPageSize().height +"px";
		}
	},
	
	//-----------------------------------------------------
	//  select elements z-index BUG ( IE 6 )
	//-----------------------------------------------------
	
	hideSelectElements : function(){
		if ((typeof document.documentElement.style.zoom != "undefined")&&(typeof document.documentElement.style.msInterpolationMode == "undefined")){
			var selectEle = document.getElementsByTagName("select");
			for(i=0;i<selectEle.length;i++){
				selectEle[i].style.visibility = "hidden";
			}
			
			var selectEle2 = document.getElementById("show-details").getElementsByTagName("select")
			for(i=0;i<selectEle2.length;i++){
				selectEle[i].selectEle2.visibility = "visible";
			}
		}
	},
	
	showSelectElements : function (){
		if ((typeof document.documentElement.style.zoom != "undefined")&&(typeof document.documentElement.style.msInterpolationMode == "undefined")){
			var selectEle = document.getElementsByTagName("select");
			for(i=0;i<selectEle.length;i++){
				selectEle[i].style.visibility = "visible";
			}
		}
	}
	
}

try {
	window.addEventListener('resize', backScreen.fix, false);
} catch (e) {
	window.attachEvent('onresize', backScreen.fix);
}


