
var ifrm;
var numFrame = 1;
var currentFrame="tehframe";

function adjustIFrameSize(iframeWindow) {

	if(iframeWindow.document){
		if (iframeWindow.document.height) {
			var iframeElement = document.getElementById(currentFrame);
			//alert(iframeElement);


			//alert(iframeWindow.document);
			//alert(iframeWindow.document.childNodes[1]);
			//alert();
			var body = iframeWindow.document.childNodes[1].getElementsByTagName("body")[0];
			
			for(var i=0; i<body.childNodes.length ; i++){
				if(body.childNodes[i].id != "delform" && body.childNodes[i].nodeName != "#text"){
					//alert("hiding " + iframeWindow.document.childNodes[1].childNodes[2].childNodes[i].nodeName);
					body.childNodes[i].style.display = 'none';
				}else{
					//alert(iframeWindow.document.childNodes[1].childNodes[2].childNodes[i].nodeName);
					if(body.childNodes[i].id == "delform"){
					body.style.padding = "0px";
					
					//alert(iframeWindow.document.childNodes[1].childNodes[2].childNodes[i].childNodes.length);
					for(var j=0; j<body.childNodes[i].childNodes.length ; j++){
						//alert(iframeWindow.document.childNodes[1].childNodes[2].childNodes[i].childNodes[j].nodeName);
						if(  body.childNodes[i].childNodes[j].nodeName   == "TABLE")
							body.childNodes[i].childNodes[j].style.display = 'none';
					}
					}
					
				}
			}
			//iframeElement.style.height = iframeWindow.document.height + 'px';
			//iframeWindow.document.width =  window.innerWidth + 'px';
			//iframeElement.style.width = window.innerWidth + 'px'; // iframeWindow.document.width + 'px';
			return iframeWindow.document.height;
		}
	}else{
		return -1;
	}
}

var fheight=0;
var pos=0;
var timer=0;
var firstT = true;
 
function resizeE(){
		
		
	try{
		document.getElementById('displayDiv').removeChild(document.getElementById('loadingSpinner'));
		}catch(err){}
}

function resizeMore(){

	fheight = adjustIFrameSize(document.getElementById(currentFrame).contentWindow);

	if(fheight ==-1){
		document.getElementById('displayDiv').removeChild(ifrm);
		alert("Sorry Firefox Only");
		resizeE();
	}
	else{
		

		document.getElementById(currentFrame).style.height = fheight + 'px'; 
		try{
		document.getElementById('displayDiv').removeChild(document.getElementById('loadingSpinner'));
		}catch(err){}
		currentFrame+=1;
		

	}	
	

	
}


function test(){
alert("testing");
alert( this.id);
alert( parent.document.getElementById('displayDiv').childNodes.length);
alert( parent.name);
}

var folder;
var newURL;

function loadMore() {


		

	
	var imgF = document.createElement("div");
	imgF.id = "loadingSpinner";
	imgF.innerHTML = '<img src="http://nekomimichan.org/css/spinner.gif" />';
	imgF.style.textAlign = "center";
	document.getElementById('displayDiv').appendChild(imgF);
	timer = setTimeout('resizeE()',10000);
	
	//document.getElementById('displayDiv').innerHTML = '<img src="spinner.gif" alt="loading"/>' 
	ifrm = document.createElement("iframe");
	ifrm.id = currentFrame;
	
	if(firstT){
		newURL = window.location.protocol + "//" + window.location.host ;
		
		var loc = window.location.pathname;
		//alert(loc);
		folder = loc.substr(0,loc.lastIndexOf("/") +1 );
		var indexOfFile = loc.lastIndexOf("/") + 1;
		
		var fileName = loc.substr(indexOfFile);
		fileName = fileName.substr(0,fileName.lastIndexOf("."));
		//alert(fileName);
		var numbern =  parseInt(fileName);
		//alert(numbern);
		
		if( isNaN(numbern) ){
			numFrame = 1;
		}
		else
			numFrame = numbern+1;
		firstT = false;
		//alert(numFrame);
	}
	
	ifrm.src = newURL + folder + numFrame++ + ".html";
//	alert(ifrm.src);
	//ifrm.src = "http://nekomimichan.org/n/1.html";
	ifrm.style.width = "100%";
	ifrm.style.height = "0px";
	ifrm.style.border = "0px";
	ifrm.style.padding = "0px";
	ifrm.scrolling="no";
	
	ifrm.onload = resizeMore;
	document.getElementById('displayDiv').appendChild(ifrm);
	
	
	//resizeMore();
}

