// Scroll image script
// Written by Shawn Hill 
// for Silpada Designs 12/19/2003

smImg = 'small.jpg'
lgImg = 'big.jpg'
detailBoxWidth=400
detailBoxHeight=300
scrollDelay = 20

//preload the images
sI = new Image()
sI.src = smImg
lI = new Image()
lI.src = lgImg

var x,y,zBox,dBox, zoomInt
var isZoom = false
function init(){
	if(document.getElementById){
		zBox = document.getElementById('zoomBox')
		dBox = document.getElementById('detailBox')
		mBox = document.getElementById('mapBox')
		
		// set detailBox to specified size 
		dBox.style.width = detailBoxWidth+'px'
		dBox.style.height = detailBoxHeight+'px'
		
		// set ZoomBox to specified size
		zBox.style.width = sI.width+'px'
		zBox.style.height = sI.height+'px'
		
		zBox.L = findPosX(zBox)
		zBox.T = findPosY(zBox)
		dBox.L = findPosX(dBox)
		dBox.T = findPosY(dBox)
		
		dBox.xRat = (lI.width / sI.width)
		dBox.yRat = (lI.height / sI.height)
		
		dBox.W = detailBoxWidth
		dBox.H = detailBoxHeight
		
		zBox.onmouseover=zoom
		zBox.onmouseout=nozoom		
		document.onmousemove=setcursor
	}	
}
function setcursor(event){
	if(isZoom){
		if (window.event) {
			x = window.event.clientX + document.documentElement.scrollLeft+ document.body.scrollLeft;
			y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
		}
		else {
			x = event.clientX + window.scrollX;
			y = event.clientY + window.scrollY;
		}
	}
}
function nozoom(){
	isZoom=false
	clearInterval(zoomInt)
}
function zoom(){
	isZoom = true
	zoomInt = setInterval('track()',scrollDelay)
}
function track(){
	bgL = -1* Math.round(((x-zBox.L)*dBox.xRat)-(dBox.W/2))
	bgT = -1* Math.round(((y-zBox.T)*dBox.yRat)-(dBox.H/2))
	
	if(!isNaN(bgL) && !isNaN(bgT)){
		lowL = dBox.W-lI.width
		hiL = 0
		lowT = dBox.H-lI.height
		hiT = 0
		
		if(bgL<lowL)bgL=lowL
		if(bgL>hiL)bgL=hiL
		
		if(bgT<lowT)bgT=lowT
		if(bgT>hiT)bgT=hiT
		
		mBox.style.left = bgL+'px'
		mBox.style.top = bgT+'px'
	}
}
function findPosX(obj){
	var curleft=0
	while(obj.offsetParent){
		curleft+=obj.offsetLeft
		obj=obj.offsetParent
	}
	return curleft
}
function findPosY(obj){
	var curtop=0
	while(obj.offsetParent){
		curtop+=obj.offsetTop
		obj=obj.offsetParent
	}
	return curtop
}
window.onload=init
