//DHTML Window script- Copyright Dynamic Drive (http://www.dynamicdrive.com)
//For full source code, documentation, and terms of usage,
//Visit http://www.dynamicdrive.com/dynamicindex9/dhtmlwindow.htm
var w3c=(document.getElementById)? true: false;
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all
var slideAmountPerFrame = 10; // Pixel distance window moves each fram of animation
var frameLength = 5; // Milliseconds each frame of animation lasts
var slideX = 0;
var slideY = 0;
var scrollX = 0;
var scrollY = 0;
var popWidth = 500
var popHeight = 450
var windowWidth = ns6 ? window.innerWidth : document.body.clientWidth;
var windowHeight = ns6 ? window.innerHeight : document.body.clientHeight;
var slideXFinal = Math.round((windowWidth / 2) - (popWidth / 2));
slideXFinal = (slideXFinal < 0) ? 0 : slideXFinal;
var slideYFinal = Math.round((windowHeight / 2) - (popHeight / 2));
slideYFinal = (slideYFinal < 0) ? 0 : slideYFinal;
var slideXInterval = 0;
var slideYInterval = 0;
var slideStop;

var dragapproved=false
var minrestore=0
var initialwidth,initialheight
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}
function iecompattest()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function drag_drop(e)
{
	if (ie5&&dragapproved&&event.button==1)
	{
		document.getElementById("dwindow").style.left=tempx+event.clientX-offsetx+"px"
		document.getElementById("dwindow").style.top=tempy+event.clientY-offsety+"px"
	}
	else if (ns6&&dragapproved)
	{
		document.getElementById("dwindow").style.left=tempx+e.clientX-offsetx+"px"
		document.getElementById("dwindow").style.top=tempy+e.clientY-offsety+"px"
	}
}

function initializedrag(e)
{
	offsetx=ie5? event.clientX : e.clientX
	offsety=ie5? event.clientY : e.clientY
	document.getElementById("dwindowcontent").style.display="none" //extra
	tempx=parseInt(document.getElementById("dwindow").style.left)
	tempy=parseInt(document.getElementById("dwindow").style.top)

	dragapproved=true
	document.getElementById("dwindow").onmousemove=drag_drop
}

function loadwindow(url,width,height,delay,seconddelay)
{
	subscriptionSet = readCookie('subscription');
	if ( subscriptionSet == 'set' )
	{
		//dont show if set
	}
	else
	{
		if ( delay == "" ) delay = 50000;
		
		if ( seconddelay != undefined )
		{
			delay = seconddelay;
		}
		delay = 50000;
		
		window.setTimeout( function() { showSubscription(url,width,height); }, delay);
		createCookie('subscription','set',1);
	}
}

function maximize()
{
	if (minrestore==0)
	{
		minrestore=1 //maximize window
		document.getElementById("maxname").setAttribute("src","http://homeofebooks.com/images/restore.gif")
		document.getElementById("dwindow").style.width=ns6? window.innerWidth-20+"px" : iecompattest().clientWidth+"px"
		document.getElementById("dwindow").style.height=ns6? window.innerHeight-20+"px" : iecompattest().clientHeight+"px"
	}
	else
	{
		minrestore=0 //restore window
		document.getElementById("maxname").setAttribute("src","http://homeofebooks.com/images/max.gif")
		document.getElementById("dwindow").style.width=initialwidth
		document.getElementById("dwindow").style.height=initialheight
		document.getElementById("dwindow").style.top=slideYFinal
		document.getElementById("dwindow").style.left=slideXFinal
	}
	document.getElementById("dwindow").style.left=ns6? window.pageXOffset+"px" : iecompattest().scrollLeft+"px"
	document.getElementById("dwindow").style.top=ns6? window.pageYOffset+"px" : iecompattest().scrollTop+"px"
}

function closeit()
{
	document.getElementById("dwindow").style.display="none"
}

function stopdrag()
{
	dragapproved=false;
	document.getElementById("dwindow").onmousemove=null;
	document.getElementById("dwindowcontent").style.display="" //extra
}
function showbox()
{
	document.getElementById("dwindow").style.display='block';
}
function showSubscription(url,width,height)
{
	initialwidth = width
	initialheight = height
	document.getElementById("dwindow").style.width=width+"px";
	document.getElementById("dwindow").style.height=height+"px";
	document.getElementById("dwindow").style.left="20px"
//	document.getElementById("dwindow").style.top=document.body.scrollTop+"px";
	document.getElementById("cframe").src=url
	document.getElementById("cframe").style.height=(parseInt(height)-14)+"px";
	slideboxin("dwindow","top");
}
function slidebox(id, direction) 
{
	slideX += slideXInterval;
	slideY += slideYInterval;
	movePopup("dwindow", slideX, slideY);

	if ( document.documentElement && document.documentElement.scrollTop )
	{
		scrollX = document.documentElement.scrollLeft;
		scrollY = document.documentElement.scrollTop+90;
	}
	else if (document.body)
	{
		scrollX = document.body.scrollLeft;
		scrollY = document.body.scrollTop+90;
	}

	if((direction == "top") && ( slideY > (slideYFinal + scrollY) )) 
	{
		window.clearInterval(slideStop);
	} 
	else if((direction == "bottom") && ( slideY < (slideYFinal + scrollY) )) 
	{
		window.clearInterval(slideStop);
	} 
	else if((direction == "left") && ( slideX > (slideXFinal + scrollX) )) 
	{
		window.clearInterval(slideStop);
	} 
	else if((direction == "right") && ( slideX < (slideXFinal + scrollX) )) 
	{
		window.clearInterval(slideStop);
	} 
	else if((direction == "diag") && ( slideY > (slideYFinal + scrollY) )) 
	{
		window.clearInterval(slideStop);
	}
}

function slideboxin(id, direction) 
{
	if(w3c)
	{
		if(direction == "top") 
		{
			slideX = Math.round((windowWidth / 2) - (popWidth / 2));
			slideX = (slideX < 0) ? 0 : slideX;
			slideY = -windowHeight;
			slideXInterval = 0;
			slideYInterval = slideAmountPerFrame;
			movePopup("dwindow", slideX, slideY);
			showbox("dwindow");
			slideStop = setInterval('slidebox("dwindow", "top")', frameLength)
		} 
		else if(direction == "bottom") 
		{
			slideX = Math.round((windowWidth / 2) - (popWidth / 2));
			slideX = (slideX < 0) ? 0 : slideX;
			slideY = windowHeight;
			slideXInterval = 0;
			slideYInterval = -slideAmountPerFrame;
			movePopup("dwindow", slideX, slideY);
			showbox("dwindow");
			slideStop = setInterval('slidebox("dwindow", "bottom")', frameLength)
		} 
		else if(direction == "left") 
		{
			slideX = -windowWidth;
			slideY = Math.round((windowHeight / 2) - (popHeight / 2));
			slideY = (slideY < 0) ? 0 : slideY;
			slideXInterval = slideAmountPerFrame;
			slideYInterval = 0;
			movePopup("dwindow", slideX, slideY);
			showbox("dwindow");
			slideStop = setInterval('slidebox("dwindow", "left")', frameLength)
		} 
		else if(direction == "right") 
		{
			slideX = windowWidth;
			slideY = Math.round((windowHeight / 2) - (popHeight / 2));
			slideY = (slideY < 0) ? 0 : slideY;
			slideXInterval = -slideAmountPerFrame;
			slideYInterval = 0;
			movePopup("dwindow", slideX, slideY);
			showbox("dwindow");
			slideStop = setInterval('slidebox("dwindow", "right")', frameLength)
		} 
		else 
		{ // Slide in diagonally from the top left
			slideX = 0;
			slideY = 0;
			slideXInterval = slideAmountPerFrame;
			slideYInterval = slideAmountPerFrame;
			movePopup("dwindow", slideX, slideY);
			showbox("dwindow");
			slideStop = setInterval('slidebox("dwindow", "diag")', frameLength)
		}
	}
}
function movePopup(ids,x,y)
{
	if(w3c)
	{
		var ids=document.getElementById(ids);
		ids.style.left='20px';
		ids.style.top=y+8+'px';
	}
}
function checkSub()
{
	if (document.signup.email.value.indexOf('@', 0) == -1) {
	alert("Please fill in your valid Email address.\nYour email should be in the following format: email@address.com")
	document.signup.email.focus()
	return false}
	if (document.signup.fname.value == "") {
	alert("Please fill in your First name.")
	document.signup.fname.focus()
	return false}                          
}
//write the layer
layer = "<style type=\"text/css\">";
layer += "#dwindow {top:0;left:0;width:600px;position:absolute;background:#DEDEDE;display:none;border:1px solid #CCCCCC;z-index:999999}";
layer += ".dwindow_icons {height:14px;cursor:move;text-align:right;background:#DEDEDE;text-align:right;clear:both}";
layer += ".dwindow_icons img {cursor:pointer;}";
layer += "#cframe {}";
layer += ".dwindowcontent {display:block;}";
layer += "</style>";
layer += "<div id=\"dwindow\" onMousedown=\"initializedrag(event)\" onMouseup=\"stopdrag()\" onSelectStart=\"return false\">";
layer += "<div class=\"dwindow_icons\">";
layer += "<img src=\"http://homeofebooks.com/images/max.gif\" id=\"maxname\" onClick=\"maximize()\">";
layer += "<img src=\"http://homeofebooks.com/images/close.gif\" onClick=\"closeit()\">";
layer += "</div>";
layer += "<div id=\"dwindowcontent\">";
layer += "<iframe id=\"cframe\" src=\"\" vspace=\"0\" hspace=\"0\" marginwidth=\"0\" marginheight=\"0\" height=\"100%\" width=\"100%\" frameborder=\"0\"></iframe>";
layer += "</div>";
layer += "</div>";
document.write(layer);