/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  based on alttxt v1.2 by Brian Gosselin of scriptasylum.com, featured on http://www.dynamicdrive.com

var center=false;     // CENTERS THE BOX UNER THE MOUSE, OTHERWISE DISPLAYS BOX TO THE RIGHT OF THE MOUSE

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


var IE5 = (document.getElementById && document.all)? true : false;
var NS6 = (document.getElementById && navigator.appName.indexOf("Netscape")>=0 )? true: false;
var W3C = (document.getElementById)? true : false;
var w_y, w_x, navtxt, thanksPopUp, infoPopUp, boxwidth;
var arrowPopUp;
var ishover=false;
var isloaded=false;
var ieop=0;
var op_id=0;
var op_id_smiley = 0;
var op_id_info = 0;
var bLocked = false;
var bUseIFrame = true;
var yside, xside;
var fHide;

if ( !(document.all && document.getElementById && !window.opera && navigator.userAgent.toLowerCase().indexOf("mac") == -1) )
{
	bUseIFrame = false;
}
else
{
	bUseIFrame = false;
	if (parseFloat(navigator.appVersion.split("MSIE")[1]) < 7)
	{
		bUseIFrame = true;
	}
}

function getwindowdims(){
	w_y=(NS6||window.opera)? window.innerHeight : (IE5)? document.body.clientHeight : 0;
	w_x=(NS6||window.opera)? window.innerWidth : (IE5)? document.body.clientWidth : 0;
}

function getboxwidth(){
	if(IE5)boxwidth=(navtxt.style.pixelWidth)? navtxt.style.pixelWidth : navtxt.offsetWidth;
	if(NS6)boxwidth=(navtxt.style.width)? parseInt(navtxt.style.width) : parseInt(navtxt.offsetWidth);
}

function movenavtxt(x,y,arrowPlacement,arrowSide){
	navtxt.style.left = x + 'px';
	navtxt.style.top = (y - 10) + 'px';
	arrowPopUp.style.left = (arrowSide == 1) ? (x+4) + 'px' : (x+boxwidth+3) + 'px';
	arrowPopUp.style.top = (arrowPlacement - 10) + 'px';
	if (bUseIFrame)
	{
		fHide.style.top = (y + 4) + 'px';
		fHide.style.left = (x + 23) + 'px';
	}
}

//**** END UTILITY FUNCTIONS ****//

function writePopUp(BookId, styleId) {
	if (isloaded)
	{
		if(BookId!=0){
			clearTimeout(op_id);
			ishover=true; 
			if (styleId == 7) {
				op_id=setTimeout('writeSmiley(\'' + BookId + '\',\'' + styleId + '\');', 1000);			
			}
			else if (styleId == 8) {
				op_id=setTimeout('writeInfoPopUp(\'' + BookId + '\',\'' + styleId + '\');', 1000);	
			}
			else {
				op_id=setTimeout('writePopUp2(\'' + BookId + '\',\'' + styleId + '\');', 1000);
			}
		}
		else{
			if (bUseIFrame)
			{
				fHide.style.visibility = "hidden";
			}
			navtxt.style.visibility="hidden";
			arrowPopUp.style.visibility="hidden";
	  		if(IE5)  {
				navtxt.style.filter="alpha(opacity=0)";
				arrowPopUp.style.filter="alpha(opacity=0)";
			}
			else {
				navtxt.style.MozOpacity=0;		
				arrowPopUp.style.MozOpacity=0;	
			}
			document.getElementById("midPopUp").innerHTML = '&nbsp;';	
			ishover=false;
			bLocked = false;
			clearTimeout(op_id);
		}
	}
}

function writePopUp2(BookId, styleId) {
	var boxheight, yoff, y, getpagescrolly;
//	navtxt.style.visibility = "hidden";
	ishover=true;
	bLocked = true;
	text = '<table border=0 cellpadding=0 cellspacing=0 width=376><tr>';
	
// Cover image		
	if (styleId == 1 || styleId == 2) {
		var strImg = document.getElementById('BookImage' + BookId).value;
		text += '<td valign="top" width="60"><div style="margin: 0px 0px 0px 28px;"><img src=' + strImg + ' width=60 /></div></td><td><img src=""/images/dot.gif"" width=8 height=1></td><td valign="top">';
	}
	else {
		text += '<td valign="top"><img src=""/images/dot.gif"" width=32 height=1></td><td valign="top">';
	}
	
// author/Title			
	var strTitle = document.getElementById('BookTitle' + BookId).value;
	var strAuthor = document.getElementById('BookAuthor' + BookId).value;
	text += '<table border=0 cellpadding=0 cellspacing=0>' +
		'<tr><td><span class="columnSort2">' + strTitle + '</span></td></tr><tr><td><img src=""/images/dot.gif"" width=1 height=1></td></tr>' +
		'<tr><td><span class="subtext2">' + strAuthor + '</span></td></tr><tr><td><img src=""/images/dot.gif"" width=1 height=8></td></tr>';
	
// price 			
	switch (styleId) {
	  case 1 :	
	  case '1':
	  case 3 :
	  case '3':
	  case 4 :
	  case '4':
	  case 5 : 
	  case '5':
		var RetailPrice = document.getElementById('RetailPrice' + BookId).value;
		if (RetailPrice == '0.00')
		{
			text += '<tr><td><span class="subtext2">WOWIO Price: Free</span></td></tr>';
		}
		else
		{
			text += '<tr><td><span class="subtext2">List Price: <del>$' + RetailPrice + '</del><img src=""/images/dot.gif"" width=16 height=1>WOWIO Price: Free</span></td></tr>';
		}
		text += '<tr><td><img src=""/images/dot.gif"" width=1 height=8></td></tr>';
	}
			
// Book of the month Blurb
	if (styleId == 4) {
		text += '<tr><td><span class="subtext2">Try WOWIO by downloading the Book of the Month for free, with no registration required. Click now to download the book!</span></td></tr>';
		text += '<tr><td><img src=""/images/dot.gif"" width=1 height=6></td></tr>';			
	}	

// description
	if (styleId != 5) {
		var strDesc = document.getElementById('BookText' + BookId).value;
		text += '<tr><td><span class="subtext2">' + strDesc + '</span></td></tr><tr><td><img src=""/images/dot.gif"" width=1 height=6></td></tr>';	
	}		
	text += '</table></td><td><img src=""/images/dot.gif"" width=12 height=1></td></tr></table>';	
	document.getElementById("midPopUp").innerHTML = text;
	
	if (IE5) {
		boxheight = parseInt(navtxt.offsetHeight);
		getpagescrolly = ietruebody().scrollTop;
	}
	else {
		boxheight = navtxt.offsetHeight;
		getpagescrolly = window.pageYOffset;
	}

	if ((w_y / my) > 2)
	{
		yoff = -20;
		yside = 1;
	}
	else
	{
		yoff = 40 - boxheight;
		yside = 2;
	}
	
	if (BrowserDetect.browser == 'Safari' && BrowserDetect.version < 500) {
		y = my + yoff;		
	}
	else {
		y = my + yoff + getpagescrolly;	
	}
	navtxt.style.top = (y - 10) + 'px';
	
	navtxt.style.visibility="visible";
	arrowPopUp.style.visibility="visible";
  	if(IE5)  {
		navtxt.style.filter="alpha(opacity=100)";
		arrowPopUp.style.filter="alpha(opacity=100)";
	}
	else {
		navtxt.style.MozOpacity=1;		
		arrowPopUp.style.MozOpacity=1;	
	}

	if (bUseIFrame)
	{
		fHide.style.top = (y + 4) + 'px';
		fHide.style.left = (parseInt(navtxt.style.left) + 23) + 'px';
		if (IE5)
		{
			fHide.style.height = (parseInt(navtxt.offsetHeight) - 8) + 'px';
			fHide.style.filter="alpha(opacity=10)";
			fHide.style.filter="alpha(opacity=10)";
		}
		else
		{
			fHide.style.height = (navtxt.offsetHeight - 8) + 'px';
		}
		fHide.style.width = (navtxt.offsetWidth - 28) + 'px';
		fHide.style.visibility = "visible";
	}
}

function writeSmiley(BookId, styleId) {
	var boxheight, yoff, y, getpagescrolly;
	var strBook = document.getElementById('ad' + BookId).value;
	
	ishover=true;
	bLocked = true;
	text = '<table border=0 cellpadding=0 cellspacing=0 width=376>';
	text += '<tr><td><img src="/images/dot.gif" width=32 height=1></td>';
	
	if (strBook != '') {
		text += '<td><strong>Say "Thank You"</strong></td><td><img src="/images/dot.gif" width=8 height=1></td></tr>';
		text += '<tr><td colspan="3"><img src="/images/dot.gif" width=1 height=2></td></tr>';
		text += '<tr><td><img src="/images/dot.gif" width=32 height=1></td><td>Click this icon to say thanks to ' + strBook + ' for sponsoring your book. ';
		text += 'Every "thank you" helps WOWIO to free books and free minds.</td><td><img src="/images/dot.gif" width=8 height=1></td></tr>';
	}
	else {
		text += '<td><strong>Say "Thank You"</strong></td><td><img src="/images/dot.gif" width=8 height=1></td></tr>';
		text += '<tr><td colspan="3"><img src="/images/dot.gif" width=1 height=2></td></tr>';
		text += '<tr><td><img src="/images/dot.gif" width=32 height=1></td><td>Click this icon to say thanks to WOWIO for sponsoring your book. ';
		text += 'Every "thank you" helps WOWIO to free books and free minds.</td><td><img src="/images/dot.gif" width=8 height=1></td></tr>';
	}
	text += '<tr><td colspan="3"><img src=""/images/dot.gif"" width=1 height=2></td></tr></table>';	
	document.getElementById("midPopUp").innerHTML = text;
	
	if (IE5) {
		boxheight = parseInt(navtxt.offsetHeight);
		getpagescrolly = ietruebody().scrollTop;
	}
	else {
		boxheight = navtxt.offsetHeight;
		getpagescrolly = window.pageYOffset;
	}

	if ((w_y / my) > 2)
	{
		yoff = -20;
		yside = 1;
	}
	else
	{
		yoff = 40 - boxheight;
		yside = 2;
	}
	
	if (BrowserDetect.browser == 'Safari' && BrowserDetect.version < 500) {
		y = my + yoff;		
	}
	else {
		y = my + yoff + getpagescrolly;	
	}
	navtxt.style.top = (y - 10) + 'px';
	
	navtxt.style.visibility="visible";
	arrowPopUp.style.visibility="visible";
  	if(IE5)  {
		navtxt.style.filter="alpha(opacity=100)";
		arrowPopUp.style.filter="alpha(opacity=100)";
	}
	else {
		navtxt.style.MozOpacity=1;		
		arrowPopUp.style.MozOpacity=1;	
	}

	if (bUseIFrame)
	{
		fHide.style.top = (y + 4) + 'px';
		fHide.style.left = (parseInt(navtxt.style.left) + 23) + 'px';
		if (IE5)
		{
			fHide.style.height = (parseInt(navtxt.offsetHeight) - 8) + 'px';
			fHide.style.filter="alpha(opacity=10)";
			fHide.style.filter="alpha(opacity=10)";
		}
		else
		{
			fHide.style.height = (navtxt.offsetHeight - 8) + 'px';
		}
		fHide.style.width = (navtxt.offsetWidth - 28) + 'px';
		fHide.style.visibility = "visible";
	}
}

function clearSmiley() {
	if (bUseIFrame)
	{
		fHide.style.visibility = "hidden";
	}
	thanksPopUp.style.visibility="hidden";
 	if(IE5)  {
		thanksPopUp.style.filter="alpha(opacity=0)";
	}
	else {
		thanksPopUp.style.MozOpacity=0;		
	}
	ishover=false;
	bLocked = false;
	clearTimeout(op_id_smiley);
}

function writeInfo(strPlace, InfoId, xOffSet) {
var helpY, helpX;
var w_x = (NS6||window.opera)? window.innerWidth : (IE5)? document.body.clientWidth : 0;
var pos = Position.get(strPlace);
var nId = Math.abs(InfoId);
var strTitle = document.getElementById('infoTitle' + nId).value;
var strBody = document.getElementById('infoBody' + nId).value;

var bMedSize = (InfoId > 0) ? false : true;
var nBodyWidth = (InfoId > 0) ? 200 : 275;
var nRightOffset = (InfoId > 0) ? 75 : 0;
	
	if (bMedSize) {
		document.getElementById("topInfoPopUp").style.backgroundImage = 'url(/images/rollover-bubble-info-med-top.gif)';
		document.getElementById("midInfoPopUp").style.backgroundImage = 'url(/images/rollover-bubble-info-med-middle.gif)';
		document.getElementById("bottomInfoPopUp").style.backgroundImage = 'url(/images/rollover-bubble-info-med-bottom.gif)';
	}
	else {
		text = '<table border=0 cellpadding=0 cellspacing=0 width=200>';
		document.getElementById("topInfoPopUp").style.backgroundImage = 'url(/images/rollover-bubble-info-top.gif)';
		document.getElementById("midInfoPopUp").style.backgroundImage = 'url(/images/rollover-bubble-info-middle.gif)';
		document.getElementById("bottomInfoPopUp").style.backgroundImage = 'url(/images/rollover-bubble-info-bottom.gif)';
	}
	
	document.getElementById("infotxt").style.width = nBodyWidth + 'px';
	document.getElementById("topInfoPopUp").style.width = nBodyWidth + 'px';
	document.getElementById("bottomInfoPopUp").style.width = nBodyWidth + 'px';
	
	text = '<table border=0 cellpadding=0 cellspacing=0 width=' + nBodyWidth + '>';
	text += '<tr><td><img src="/images/dot.gif" width=38 height=1></td>';
	text += '<td><span class="size11"><strong>' + strTitle + '</strong></span></td><td><img src="/images/dot.gif" width=8 height=1></td></tr>';
	text += '<tr><td colspan="3"><img src="/images/dot.gif" width=1 height=6></td></tr>';
	text += '<tr><td><img src="/images/dot.gif" width=32 height=1></td><td><span class="size11">' + strBody + '</span></td>';
	text += '<td><img src="/images/dot.gif" width=8 height=1></td></tr>';	
	text += '<tr><td colspan="3"><img src=""/images/dot.gif"" width=1 height=2></td></tr></table>';	
	
	document.getElementById("midInfoPopUp").innerHTML = text;

	helpX = pos.left;
	helpY = pos.top;
	
	if (IE5) {
		helpY -= 2;
		helpX -= 2;
	}
	if (BrowserDetect.browser == 'Safari') {
		helpX -= 1;
	}
	
	if ((w_x/helpX) > 2) { 
		document.getElementById("arrowPopUp").style.backgroundImage = 'url(/images/rollover-bubble-arrow-left.gif)';
		infoPopUp.style.top = (helpY - 12) + 'px';	// top(-) to bottom(+)
		infoPopUp.style.left = (helpX + xOffSet + 29)+ 'px';	// left(-) to right(+)
		arrowPopUp.style.top = (helpY - 2) + 'px';
		arrowPopUp.style.left = (helpX + xOffSet + 33) + 'px';
	}
	else {
		document.getElementById("arrowPopUp").style.backgroundImage = 'url(/images/rollover-bubble-arrow-right.gif)';
		infoPopUp.style.top = (helpY - 12) + 'px';	// top(-) to bottom(+)
		infoPopUp.style.left = (helpX + nRightOffset + xOffSet - 297)+ 'px';	// left(-) to right(+)
		arrowPopUp.style.top = (helpY - 2) + 'px';
		arrowPopUp.style.left = (helpX + xOffSet - 23) + 'px';
	}
	
	infoPopUp.style.visibility="visible";
	arrowPopUp.style.visibility="visible";
  	if(IE5)  {
		infoPopUp.style.filter="alpha(opacity=100)";
		arrowPopUp.style.filter="alpha(opacity=100)";
	}
	else {
		infoPopUp.style.MozOpacity=1;		
		arrowPopUp.style.MozOpacity=1;		
	}	
}

function clearInfo() {
	if (bUseIFrame)
	{
		fHide.style.visibility = "hidden";
	}
	infoPopUp.style.visibility="hidden";
	arrowPopUp.style.visibility="hidden";
 	if(IE5)  {
		infoPopUp.style.filter="alpha(opacity=0)";
		arrowPopUp.style.filter="alpha(opacity=0)";
	}
	else {
		infoPopUp.style.MozOpacity=0;	
		arrowPopUp.style.MozOpacity=0;		
	}
	ishover=false;
	bLocked = false;
	clearTimeout(op_id_info);
}
				
function moveobj(evt){
	var getpagescrolly, getpagescrollx;
	var arrowPlacement,arrowSide;
	var xPoint, yPoint;
	var boxheight;

	if(isloaded && ishover){
		if (NS6) {
			getpagescrolly = window.pageYOffset;
			getpagescrollx = window.pageXOffset;
			boxheight=parseInt(navtxt.offsetHeight);
		}
		else {
			getpagescrolly = ietruebody().scrollTop;
			getpagescrollx = ietruebody().scrollLeft;
			boxheight= navtxt.offsetHeight;
		}

		margin=(IE5)? 1 : 23;
		if(NS6)if(document.height+27-window.innerHeight<0)margin=15;
		if(NS6){
			mx=evt.clientX
			my=evt.clientY
		}
		else if (IE5){
			mx=event.clientX
			my=event.clientY
		}
		if (!bLocked)
		{
			if ((w_y / my) > 2)
			{
				yoff = -20;
				yside = 1;
			}
			else
			{
				yoff = 40 - boxheight;
				yside = 2;
			}
		}
		else
		{
			if (yside == 1)
			{
				yoff = -20;
			}
			else
			{
				yoff = 40 - boxheight;
			}
		}

		if (!bLocked)
		{
			if ((w_x / mx) < 2) {
				xside = 1;
				xoff = mx-boxwidth-30;	
				document.getElementById("arrowPopUp").style.backgroundImage = 'url(/images/rollover-bubble-arrow-right.gif)';
				arrowSide = 2;
			}
			else {
				xside = 2;
				xoff = mx+15;		
				document.getElementById("arrowPopUp").style.backgroundImage = 'url(/images/rollover-bubble-arrow-left.gif)';
				arrowSide = 1;
			}
		}
		else
		{
			if (xside == 1)
			{
				xoff = mx - boxwidth - 30;
				arrowSide = 2;
			}
			else
			{
				xoff = mx + 15;
				arrowSide = 1;
			}
		}
		
		if (BrowserDetect.browser == 'Safari' && BrowserDetect.version < 500) {
			xPoint = xoff;
			arrowPlacement =  my - 4;
			yPoint =  my + yoff;
		}
		else {
			xPoint = xoff + getpagescrollx;
			arrowPlacement =  my + getpagescrolly - 4;
			yPoint =  my + yoff + getpagescrolly;
		}
		
		movenavtxt(xPoint , yPoint, arrowPlacement, arrowSide);
	}
}

document.onmousemove=moveobj;

function popUpSetUp(){
	navtxt = document.getElementById('navtxt');
	arrowPopUp = document.getElementById('arrowPopUp');
	thanksPopUp = document.getElementById('thanksPopUp');
	infoPopUp = document.getElementById('infotxt');
	fHide = document.getElementById('hidenavtxt');
	getboxwidth();
	getwindowdims();
	isloaded=true;
	if(W3C)navtxt.style.padding='4px';
	if(IE5)navtxt.style.filter="alpha(opacity=0)";
	if(IE5)arrowPopUp.style.filter="alpha(opacity=0)";
}
window.onresize=getwindowdims;

