var issuuAuthorMode=false;
var FloatLayers       = new Array();
   var FloatLayersByName = new Array();
 
   function FloatLayer(name, offX, offY, speed) {
 	this.index = FloatLayers.length;
 
 	FloatLayers.push(this);
 	FloatLayersByName[name] = this;

	this.name    = name;
	this.floatX  = 0;
	this.floatY  = 0;
	this.tm      = null;
	this.steps   = speed;
	this.alignHorizontal = (offX >= 0) ? leftFloater : rightFloater;
	this.alignVertical   = (offY >= 0) ? topFloater : bottomFloater;
	this.ifloatX = Math.abs(offX);
	this.ifloatY = Math.abs(offY);
  }
new FloatLayer('pdf_par_div',0,0,5);

function detach(){
lay  = document.getElementById('floatlayer');
left = getXCoord(lay);
top  = getYCoord(lay);
lay.style.position = 'absolute';
lay.style.top      = top;
lay.style.left     = left;
getFloatLayer('floatlayer').initialize();
alignFloatLayers();
}

function getXCoord(el) {
	x = 0;
	while(el){
		x += el.offsetLeft;
		el = el.offsetParent;
	}
	return x;
}
function getYCoord(el) {
	y = 0;
	while(el){
		y += el.offsetTop;
		el = el.offsetParent;
	}
	return y;
}

function getFloatLayer(name){
	return FloatLayersByName[name];
}

FloatLayer.prototype.initialize=defineFloater;

function defineFloater(){
this.layer  = document.getElementById(this.name);
this.width  = this.layer.offsetWidth;
this.height = this.layer.offsetHeight;
this.prevX  = this.layer.offsetLeft;
this.prevY  = this.layer.offsetTop;
}

FloatLayer.prototype.align=alignFloater;

function alignFloatLayers() {
for( var i=0; i<FloatLayers.length; i++)
	FloatLayers[i].align();
}

function alignFloater(){
if(this.layer == null) this.initialize();
this.alignHorizontal();
this.alignVertical();
if( this.prevX != this.floatX || this.prevY != this.floatY ){
	if(this.tm == null)
			this.tm=setTimeout('FloatLayers['+this.index+'].adjust()',50);
	}
}

function leftFloater() {
this.floatX = document.body.scrollLeft + this.ifloatX;
 }
  function topFloater() {
	this.floatY = document.body.scrollTop + this.ifloatY;
  }
function rightFloater() {
this.floatX = document.body.scrollLeft +
			document.body.clientWidth - this.ifloatX - this.width;
}
function bottomFloater() {
this.floatY = document.body.scrollTop +
			document.body.clientHeight - this.ifloatY - this.height;
}

FloatLayer.prototype.adjust=adjustFloater;

  function adjustFloater() {
	this.tm=null;
	if(this.layer.style.position!='absolute')return;

	var dx = Math.abs(this.floatX-this.prevX);
	var dy = Math.abs(this.floatY-this.prevY);

	if (dx < this.steps / 2)
		cx = (dx >= 1) ? 1 : 0;
	else
		cx = Math.round(dx/this.steps);

	if (dy < this.steps/2)
		cy = (dy >= 1) ? 1 : 0;
	else
		cy = Math.round(dy/this.steps);

	if (this.floatX > this.prevX)
		this.prevX += cx;
	else if (this.floatX < this.prevX)
		this.prevX -= cx;

	if (this.floatY > this.prevY)
		this.prevY += cy;
	else if (this.floatY < this.prevY)
		this.prevY -= cy;

	this.layer.style.left = this.prevX;
	this.layer.style.top  = this.prevY;

	if (cx != 0 || cy != 0){
		if(this.tm == null)
			this.tm=setTimeout('FloatLayers['+this.index+'].adjust()',50);
	}else
		alignFloatLayers();
 }

function appendPDFLayer(pdfLayer){
var pdfFrame = "issuu_pdf_frame";
var pdfCell = pdfLayer;
pdfCell=pdfCell.replace("_div","_cell");
var pdfPal = pdfLayer;
pdfPal=pdfPal.replace("_div","_pal");
var pdfHal = pdfLayer;
pdfHal=pdfHal.replace("_div","_hal");
try{
var frameWidthDec = 176;
if(navigator.appName.indexOf("Microsoft")<0 && issuuAuthorMode==true){
frameWidthDec = 193;
}
document.getElementById(pdfFrame).width=document.body.clientWidth-frameWidthDec;
document.getElementById(pdfFrame).height=document.body.clientHeight-101;
document.getElementById(pdfCell).width=document.body.clientWidth-frameWidthDec;
document.getElementById(pdfCell).height=document.body.clientHeight-101;
document.getElementById(pdfPal).width=document.body.clientWidth-frameWidthDec;
document.getElementById(pdfHal).width=document.body.clientWidth-107;
document.getElementById(pdfLayer).style.tableLayout="fixed";
}catch(e){}
try{
document.getElementById("pdf_child_div").appendChild(document.getElementById(pdfLayer));
}
catch(e){}
}

function findPosX(obj) 
{ 
	var curleft = 0; 
	if(obj.offsetParent) 
		while(1) 
		{ 
			curleft += obj.offsetLeft; 
			if(!obj.offsetParent) 
				break; 
			obj = obj.offsetParent; 
		} 
		else if(obj.x) 
			curleft += obj.x; 
	return curleft; 
}


function toggleexternalpdf(id,frameid){

if(document.getElementById("pdf_par_div").style.visibility==''){
document.getElementById("pdf_par_div").style.visibility='hidden';
try{document.getElementById(id).style.display='none';}catch(e){}
document.getElementById("pdf_par_div").style.zIndex=2;


}else{
document.getElementById("pdf_par_div").style.visibility='';
try{document.getElementById(id).style.display='';}catch(e){}
document.getElementById("pdf_par_div").style.zIndex=4;

}

}


function pagepdf(url,pdflayer){

 document.getElementById(pdflayer).src = url;

}


