// Global killswitch
if (Drupal.jsEnabled) {
  $(document).ready(bibleAutoAttach);
}

function bibleAutoAttach() {
  var span = document.createElement('span');
  span.id = "SNData";
  span.style.width=300;
  span.style.height=200;
  span.style.top=0;
  span.style.left=0;
  span.style.color='#000000';
  span.style.background='silver';
  span.style.position="absolute";
  span.style.visibility="hidden";
  span.style.zIndex="999";
  span.style.textAlign = "left";
  span.innerHTML = "";
  document.body.appendChild(span);
  $("span.biblesn a")
    .mouseover(function(E) {
      var dat = ($(this).attr("href")).split('/');
      var SN = dat[dat.length-1];
      if (this.SN==SN) return;
      this.SN = SN;

      var baseurl = window.location.href.substr(0, window.location.href.lastIndexOf('bible'));
      var sndspan = document.getElementById('SNData');
      span.style.visibility = "visible";
      sndspan.innerHTML = "Wait...";
      sndspan.style.left = E.pageX;
      sndspan.style.top = E.pageY;
      $.ajax({
        type: "GET",
        url: baseurl+"/bible/snajax/"+SN,
        success: function (data) {
          // Parse back result
          if (data=='""') { sndspan.innerHTML = 'No Data of ['+SN+']'; return; }
          data = data.substring(1, data.length-2);
          lines = data.split('|');
          sndspan.innerHTML = '';
          for (i=0; i<lines.length; i++)
          sndspan.innerHTML += lines[i]+"<br/>";
        },
        error: function (xmlhttp) {
          alert('An HTTP error '+ xmlhttp.status +' occured.\n');
        }
      });
      return false;
    })
    .mouseout(function() {
      var sndspan = document.getElementById('SNData');
      span.style.visibility="hidden";
      this.SN = "";
    });  
}

function goDIV(divID) { 
	if (document.getElementById) { // DOM3 = IE5, NS6 
		if(document.getElementById(divID).style.visibility == 'visible'){
			document.getElementById(divID).style.visibility = 'hidden';
			document.getElementById(divID).style.display = 'none';
		}
		else {
			document.getElementById(divID).style.visibility = 'visible';
			document.getElementById(divID).style.display = 'block';
		}
	} 
} 

function increaseFont() {
  p = document.getElementById("bible");
  if(p.style.fontSize) {
	 var s = parseInt(p.style.fontSize.replace("%",""));
  } else {
	 var s = 100;
  }
	 s += 10;
  p.style.fontSize = s+"%"
}

function decreaseFont() {
  p = document.getElementById("bible");
  if(p.style.fontSize) {
	 var s = parseInt(p.style.fontSize.replace("%",""));
  } else {
	 var s = 100;
  }
	 s -= 10;
  p.style.fontSize = s+"%"
}

function setCrossRef(verse, element) {
	verseInput = document.getElementById("vInput");
	verseInput.value = verse;
	document.getElementById("toolsVerse").style.visibility = 'visible';
    document.getElementById("xrInput").value = '';
	document.getElementById("xrInput").focus();
	$(element).click(function(e) { alert(e.pageX); });
	$("#xrInput").autocomplete("/bible/refajax", {lineSeparator:'|', maxItemsToShow:10, cellSeparator:';'});
}

//
//$(document).ready(function(){
//
//$(".verse").click(function () {
//  $(this).hide("slide", { direction: "down" }, 1000);
//});
//
//});
//
