var calunits      = "px";
var BGbouncelimit = 32; // must be divisible by 8
var ie = document.all;

function BGinitbox(x, y){
  //BGscroll_top       = top.window.pageYOffset;
  BGscroll_top = (ie) ? truebody().scrollTop : window.pageYOffset;

  BGstyle            = top.document.getElementById("bg_div").style;
  BGstyle.left       = x+calunits;   
  BGstyle.top        = (parseInt(BGscroll_top) + parseInt(y))+calunits;

  BGstyle.visibility = "visible";
  
  BGdropstart        = setInterval("BGdropin(x, y)", 50);
}

function BGdropin(x, y){
  BGscroll_top = (ie) ? truebody().scrollTop : window.pageYOffset;

  if ( parseInt(BGstyle.top) < parseInt(BGscroll_top) + parseInt(y) ) {
		BGstyle.top = parseInt(BGstyle.top) + 30 + calunits;
	} else {
		clearInterval(BGdropstart);
		BGbouncestart = setInterval("BGbouncein()", 30);
	}
  BGbouncelimit = 32;
}

function BGbouncein(){
	BGstyle.top = parseInt(BGstyle.top) - BGbouncelimit + calunits;
	if ( BGbouncelimit < 0 ){
		BGbouncelimit += 8;
	}
	BGbouncelimit = BGbouncelimit * (-1);
	if (BGbouncelimit == 0){
		clearInterval(BGbouncestart)
	}
}

function BGdismissbox(){
	if (top.window.BGbouncestart) {
		clearInterval(BGbouncestart);
	}
  //BGstyle.display="none";
/*
  var d = document.getElementById("bg_div");
  var p      = selectedDiv.parentNode;
  p.removeChild(selectedDiv);
*/
  top.document.getElementById("bg_div").innerHTML = '';

  BGstyle.visibility="hidden";

  //return false;
}



function truebody(){
	return (top.document.compatMode && top.document.compatMode!="BackCompat") ? top.document.documentElement : top.document.body;
}


/* Creates a new custom window dynamically */
function BGdivwindow(url, size, pos){	

  size_arr = size.split('x');
  w = size_arr[0];
  h = size_arr[1];
  w = 500;
  h = 300;

  if (pos != 'center'){
    pos_arr = pos.split('x');
    x = pos_arr[0];
    y = pos_arr[1];  
  } else {
    x = (top.window.screen.width - w)/2;
    y = (top.window.screen.height - h)/2;
  }
  
  divElement = top.document.getElementById('bg_div');

  // bring in front
  bringFront = new Number (divElement.style.zIndex);
  if ( Number.bringFront != NaN ){
    bringFront += 100000;
  } else {
    bringFront = 100001;
  }
  divElement.style.zIndex = bringFront; 

  divElement.innerHTML = '<div class="overflow_div" id="BGoverflow"></div>';

  divcontent  = '<div style="width:'+w+'px;">';
  divcontent += '<div style="float: left; color:#005BB7; font-weight: bold; font-size:15px;">Bible Passage</div>';
  divcontent += '<div style="float: right"><a onClick="BGdismissbox(); return false;" href="void(0)">Close</a></div>';
  divcontent += '<iframe id="BGdropinframe" src="" frameBorder="0" width="1" height="1" style="padding-top: 10px;font-size:14px;"></iframe>';
  divcontent += '</div>';

  top.document.getElementById('BGoverflow').innerHTML = divcontent;

  iFrameElement        = top.document.getElementById('BGdropinframe');
  iFrameElement.src    = url;
  iFrameElement.height = h;
  iFrameElement.width  = w;


  divElement.style.visibility = 'visible';
  divElement.style.display = '';

  BGinitbox(x, y);

  return false;

}
