var myBook,p1,p2;
var pageBorderColor="#000000",pageBorderStyle="solid",pageBorderWidth="1";
var isMoving=false;

var ID,numPixels=20;
var pWidth=300;
var pHeight=361;
var pSpeed=30;
var counter=1;
var pBorders;
var pages=new Array;
function ini(){
pBorders=parseInt(pageBorderWidth)*2;
	if(myBook=document.getElementById("bookflip")){
		myBook.style.width=(pWidth*2)+(pBorders*2)+'px';
		myBook.style.height=pHeight+pBorders+'px';
		myBook.style.position="relative";
		myBook.style.zIndex="0";
		myBook.style.overflow="hidden";
		
		
		for(i=4;i>=0;i--){
			var myDiv = document.createElement('div'); 

			myDiv.style.position="absolute";
			myDiv.style.left=pWidth+'px';
			myDiv.style.top="0px";
			myDiv.style.width=pWidth+"px";
			myDiv.style.height=pHeight+"px";			
			myDiv.style.margin="0px";			
			myDiv.style.overflow="hidden";
			myDiv.style.backgroundColor="#ffffff";
			
			myDiv.style.border=pageBorderWidth + "px " + pageBorderStyle + " " + pageBorderColor;

			myDiv.setAttribute("id","p"+i);			
			myBook.appendChild(myDiv);
			
			ajaxFunction("p" + i,pages[i]);

		}	
			p1=document.getElementById("p1");
			p2=document.getElementById("p2");
	}
}

function clipmeR(){
		if(isMoving){return;};
		isMoving=true;

		p2.style.zIndex=2;
		p1.style.zIndex=1;
		
	if(counter>0){
		p1=document.getElementById("p1");
		p2=document.getElementById("p2");
		counter=0;
	}else{
		p1=document.getElementById("p3");
		p2=document.getElementById("p4");
		counter=1;
	}
	p2.style.zIndex=4;
	p1.style.zIndex=3;

	p1.style.left="0px";
	goleft(-pWidth,pWidth);	
	
	
}

function goleft(currLeft,currWidth){
	if(currLeft >=(pWidth-(numPixels))){
		window.clearTimeout(ID);
		p2.style.left=pWidth+"px";

		p1.style.clip="rect(0px,"+pWidth+pBorders+"px,"+pHeight+pBorders+"px,"+0+"px)";//rect(top,right,bottom,left)
		p2.style.clip="rect(0px,"+pWidth+pBorders+"px,"+pHeight+pBorders+"px,"+0+"px)";//rect(top,right,bottom,left)

		isMoving=false;

		return;
	}
	currLeft=currLeft+(numPixels*2);//2 * width reveal
	currWidth = currWidth-numPixels;
	hideWidth=pWidth-currWidth;
	p1.style.clip="rect(0px,"+hideWidth+"px,"+pHeight+pBorders+"px,"+0+"px)";//rect(top,right,bottom,left) //low to high
	
	p2.style.clip="rect(0px,"+pWidth+pBorders+"px,"+pHeight+pBorders+"px,"+currWidth+"px)";//rect(top,right,bottom,left)	
	p2.style.left=currLeft+'px';
//alert(p1.style.width);

	ID = window.setTimeout('goleft('+currLeft+','+currWidth+')',pSpeed);
	
}








function clipmeL(){
	if(isMoving){return;};
	isMoving=true;
	p1.style.zIndex=2;
	p2.style.zIndex=1;
	if(counter>0){
		p1=document.getElementById("p1");
		p2=document.getElementById("p2");
		counter=0;
	}else{
		p1=document.getElementById("p3");
		p2=document.getElementById("p4");
		counter=1;
	}



	p1.style.zIndex=5;
	p2.style.zIndex=4;

	goright(pWidth*2,0);
}

function goright(currLeft,currWidth){
	if(currLeft <= numPixels*2){
		window.clearTimeout(ID);
//alert("");
		p1.style.clip="rect(0px,"+pWidth+pBorders+"px,"+pHeight+pBorders+"px,"+0+"px)";//rect(top,right,bottom,left)
		p1.style.left=0+'px';

	//p1.style.width=pWidth+'px';
//alert("");
		
//alert("");
		
		p2.style.left=pWidth+'px';

		p2.style.clip="rect(0px,"+pWidth+pBorders+"px,"+pHeight+pBorders+"px,"+0+"px)";//rect(top,right,bottom,left)
		isMoving=false;

		return;
	}


	currLeft=currLeft-(numPixels*2);//2 * width reveal
	currWidth=currWidth+numPixels;
	hideWidth = currLeft-pWidth;
	
	p1.style.clip="rect(0px,"+currWidth+"px,"+pHeight+pBorders+"px,"+0+"px)";//rect(top,right,bottom,left) clip 
	p1.style.left=currLeft+'px';

	
	
	p2.style.clip="rect(0px,"+pWidth+pBorders+"px,"+pHeight+pBorders+"px,"+hideWidth+"px)";//rect(top,right,bottom,left)
	

//alert("");
	
	ID = window.setTimeout('goright('+currLeft+','+currWidth+')',pSpeed);
	
}



//ajax->
function ajaxFunction(page,myurl){
	var xmlHttp;
	try{// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e){// Internet Explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
		
			document.getElementById(page).innerHTML=xmlHttp.responseText;
			//document.getElementById("p2").innerHTML=xmlHttp.responseText;
			//alert(	xmlHttp.responseText);
//temp=xmlHttp.responseText;
	//return xmlHttp.responseText;

		}
    }
	xmlHttp.open("GET",myurl,true);
	xmlHttp.send(null);

}