// CREDITS:
// Copyright (c) 2001 ASOS.com
// Developer: K Lewis
// Based on:
// MapBlaster(c) 03/07/2001 by Urs Dudli and Peter Gehrig to be found at http://www.24fun.com
// 01/07/2004

//Initialise Variables for Zoom
var shrinkfactor=0

// width and height of the enlarged image's sector (visible part, pixels)
var clipwidth = 400
var clipheight = 450
var clippoints
var cliptop=0
var clipbottom=cliptop+clipheight
var clipleft=0
var clipright=clipleft+clipwidth
	
//Begin ZOOM code
function zoomMe(e){
	document.getElementById("thumb").onmousemove=showMoves
}

function noZooms(e){
	document.getElementById("thumb").onmousemove=null;
}

function showMoves(e){
	if (document.attachEvent) {
		x=event.clientX
		y=event.clientY
	} else {	
		x = parseInt(e.pageX)
		y = parseInt(e.pageY)
	}
	window.status = "x= "+  x + " y= " + y + " amen " +amenFactor
	//x=x-18
	//y=y-18
	x=x-amenFactor
	y=y-amenFactor

	if (amenFactor==34){
		if(x<=60) {x=60}
		if(x>=50+thumbwidth) {x=50+thumbwidth}
		if(y<=100) {y=100}
		if(y>=110+thumbheight) {y=110+thumbheight}
		}
	//	if(x<=77) {x=77}
	//	if(x>=105) {x=105}
	//	if(y<=138) {y=138}
	//	if(y>=166) {y=166}
	//}else if (amenFactor==32){
	//	if(x<=77) {x=77}
	//	if(x>=105) {x=105}
	//	if(y<=138) {y=138}
	//	if(y>=166) {y=166}
	//}else if (amenFactor==24){
	//	if(x<=77) {x=77}
	//	if(x>=119) {x=119}
	//	if(y<=138) {y=138}
	//	if(y>=180) {y=180}
	else{//amenFactor==18
		if(x<=60) {x=60}
		if(x>=50+thumbwidth) {x=50+thumbwidth}
		if(y<=100) {y=100}
		if(y>=110+thumbheight) {y=110+thumbheight}	
	//the eman factor should have a space the size of the thumb. starting at x=76 and y=137 and allowing a cushion of around 15-20 pixels for
	// the edge of the image. so total edging should be (X=76-15) & (x= 76-15 + thumb width ) and (y=137-15) & (y= 137 -15 + thumb height).
	
	}
	
	//if(x<=77) {x=77}
	//if(x>=128) {x=128}
	//if(y<=138) {y=138}
	//if(y>=189) {y=189}	
	
	cliptop = Math.ceil((y-thumbtop)*shrinkfactor)
	clipbottom = cliptop+clipheight
	clipleft = Math.ceil((x-thumbleft)*shrinkfactor)
	clipright = clipleft+clipwidth
	
	clippoints ="rect("+cliptop+" "+clipright+" "+clipbottom+" "+clipleft+")"
	document.getElementById("large").style.top =largetop-cliptop
	document.getElementById("large").style.left=largeleft-clipleft
	document.getElementById("large").style.clip=clippoints
}

function init() {
	largewidth= document.images['largepic'].width
	largeheight= document.images['largepic'].height
	thumbwidth = document.images['thumbpic'].width
	thumbheight = document.images['thumbpic'].height

	wspacing = Math.floor((largewidth-clipwidth)/2)
	hspacing = Math.floor((largeheight-clipheight)/2)

	largeleft = parseInt(document.getElementById("bgWhtLarge").style.left)
	largetop = parseInt(document.getElementById("bgWhtLarge").style.top)
	document.getElementById("large").style.left= largeleft - wspacing 
	document.getElementById("large").style.top= largetop - hspacing

	thumbleft = parseInt(document.getElementById("bgThumb").style.left ) + 1
	thumbtop = parseInt(document.getElementById("bgThumb").style.top) + 1 
		
	document.getElementById("thumb").style.left=thumbleft
	document.getElementById("thumb").style.top=thumbtop

	cliptop = cliptop + hspacing
	clipbottom = clipbottom + hspacing
	clipleft = clipleft + wspacing 
	clipright = clipright + wspacing 
	clippoints = "rect("+cliptop+" "+clipright+" "+clipbottom+" "+clipleft+")"

	document.getElementById("large").style.clip=clippoints

	document.getElementById("large").style.visibility="visible"
	document.getElementById("bgThumb").style.visibility="visible"
	document.getElementById("thumb").style.visibility="visible"
	
	shrinkfactor=(Math.round((largewidth/thumbwidth)*100))/100
	amenFactor = Math.round(225/shrinkfactor)
	//why 225?
}



//End ZOOM code


