var zoom_zoomboxwid, zoom_zoomboxhei, zoom_zoomboxsubx, zoom_zoomboxsuby, zoom_zoomboxmaxx, zoom_zoomboxmaxy;
var zoom_zoomimagemult;
var zoom_onspotx = -1, zoom_onspoty = -1;

var zoom_statusflags = 0;



function Zoom_StartupZoomRegion() {
	zoom_onspotx = -1;
	zoom_onspoty = -1;

	if (!zoom_zoomimagewid || !zoom_zoomimagehei || !zoom_mainimagewid || !zoom_mainimagehei) {
		alert('Image size parameters not properly set! Aborting setup of the zoom region.');
	}

	if ((!InIE || BrowserVerMajor <= 4) && !DOMCompatible && !InNS6)
		return;

	zoom_zoomimagemult = zoom_zoomimagewid / zoom_mainimagewid;

	zoom_zoomboxwid = Math.floor(zoom_mainimagewid / (zoom_zoomimagewid / zoom_viewportwid));
	zoom_zoomboxhei = Math.floor(zoom_mainimagehei / (zoom_zoomimagehei / zoom_viewporthei));
	zoom_zoomboxsubx = zoom_zoomboxwid >> 1;
	zoom_zoomboxsuby = zoom_zoomboxhei >> 1;
	zoom_zoomboxmaxx = Math.floor((zoom_zoomimagewid - zoom_viewportwid) / zoom_zoomimagemult);
	zoom_zoomboxmaxy = Math.floor((zoom_zoomimagehei - zoom_viewporthei) / zoom_zoomimagemult);

	MeMSOObjectSetSize(zoom_bigimageouterdiv, zoom_viewportwid, zoom_viewporthei);

	if (!(zoom_statusflags & 0x02)) {
		ZoomSetupZoomImage();
		zoom_statusflags |= 0x02;
	}
	zoom_statusflags |= 0x01;

	if (zoom_bigimagetablediv != '') {
		MeMSOObjectMove(zoom_bigimagetablediv,
			zoom_displayxposition,
			zoom_displayyposition);
		zoom_statusflags |= 0x04;
	}

	Event_AddHandler('mousemove', 'Zoom_MouseTester();');
}



function Zoom_EndZoomRegion() {
	if (zoom_statusflags & 0x10) {
		MeMSOObjectSetVisible(zoom_highlightdiv, 0);
		MeMSOObjectSetVisible(zoom_bigimagediv, 0);
		if (zoom_statusflags & 0x04)
		{
			ctball.style.display='';
			MeMSOObjectSetVisible(zoom_bigimagetablediv, 0);
		}
	}

	zoom_statusflags = 0;
}



function Zoom_MouseTester() {
	//alert(zoom_statusflags & 0x01);
	if (zoom_statusflags & 0x01) {
		if (mousex >= zoom_miniimagex && mousex <= (zoom_miniimagex + zoom_mainimagewid - 1) &&
			mousey >= zoom_miniimagey && mousey <= (zoom_miniimagey + zoom_mainimagehei - 1)) {
			//alert(mousex+","+mousey);
			Zoom_ChangeToSpot(mousex - zoom_miniimagex, mousey - zoom_miniimagey, 0);

			if (!(zoom_statusflags & 0x10)) {
				MeMSOObjectSetVisible(zoom_highlightdiv, 1);
				MeMSOObjectSetVisible(zoom_bigimagediv, 1);
				if (zoom_statusflags & 0x04)
				{
					ctball.style.display='none';
					MeMSOObjectSetVisible(zoom_bigimagetablediv, 1);
				}
				zoom_statusflags |= 0x10;
			}

		} else if (zoom_statusflags & 0x10) {
			MeMSOObjectSetVisible(zoom_highlightdiv, 0);
			MeMSOObjectSetVisible(zoom_bigimagediv, 0);
			if (zoom_statusflags & 0x04)
			{
				ctball.style.display='';
				MeMSOObjectSetVisible(zoom_bigimagetablediv, 0);
			}
			zoom_statusflags &= 0xFFEF;

		}
	}
}



function ZoomSetupZoomImage() {
	var newcontent;

	newcontent = '<img src="' + zoom_zoomimageurl + '" width="' + zoom_zoomimagewid + '" height="' + zoom_zoomimagehei + '" border="0" alt="" />';
	MeMSOObjectUpdate(zoom_bigimagediv, newcontent);

	ZoomSetupHighlightRegion();
}



function ZoomSetupHighlightRegion () {
	var position, newcontent;
	
	
	
	
	
	
	
	
	newcontent = '<table border="0" cellpadding="0" cellspacing="0" width="' + zoom_zoomboxwid + '" height="'+ zoom_zoomboxhei +'">' +
  '<tr>'+ 
    '<td align="center" valign="top" height="9" width="15"><img src="js/A1.gif" width="15" height="9"></td>'+
    '<td align="center" valign="middle" height="9"></td>'+
    '<td align="center" valign="top" height="9" width="15"><img src="js/A2.gif" width="15" height="9"></td>'+
  '</tr>'+
  '<tr>'+
    '<td align="center" valign="top" width="15"></td>'+
    '<td align="center" valign="middle"><img src="js/A_centro.gif">'+
    '</td>'+
    '<td align="center" valign="top" width="15"></td>'+
  '</tr>'+
  '<tr>'+
    '<td align="center" valign="top" height="9" width="15"><img src="js/A3.gif" width="15" height="9"></td>'+
    '<td align="center" valign="middle" height="9"></td>'+
    '<td align="center" valign="top" height="9" width="15"><img src="js/A4.gif" width="15" height="9"></td>'+
  '</tr>'+
'</table>';
	
	
	
	
	
	
	
	
	
	

	
	MeMSOObjectUpdate(zoom_highlightdiv, newcontent);
}



function Zoom_ChangeToSpot(zoom_newspotx, zoom_newspoty) {
	var viewposition;

	if (pageloaded) {
		MeMSOObjectMove(zoom_bigimageouterdiv,
			zoom_displayxposition + zoom_bigimagetablexoffset,
			zoom_displayyposition + zoom_bigimagetableyoffset);
		zoom_newspotx -= zoom_zoomboxsubx;
		zoom_newspoty -= zoom_zoomboxsuby;

		if (zoom_newspotx > zoom_zoomboxmaxx)
			zoom_newspotx = zoom_zoomboxmaxx;
		else if (zoom_newspotx < 0)
			zoom_newspotx = 0;

		if (zoom_newspoty > zoom_zoomboxmaxy)
			zoom_newspoty = zoom_zoomboxmaxy;
		else if (zoom_newspoty < 0)
			zoom_newspoty = 0;

		if (zoom_onspotx != zoom_newspotx || zoom_onspoty != zoom_newspoty) {
			zoom_onspotx = zoom_newspotx;
			zoom_onspoty = zoom_newspoty;

			MeMSOObjectMove(zoom_bigimagediv, -(zoom_zoomimagemult * zoom_onspotx), -(zoom_zoomimagemult * zoom_onspoty));
			MeMSOObjectSetClipping(zoom_bigimagediv, (zoom_zoomimagemult * zoom_onspotx), (zoom_zoomimagemult * zoom_onspoty),
				(zoom_zoomimagemult * zoom_onspotx) + zoom_viewportwid, (zoom_zoomimagemult * zoom_onspoty) + zoom_viewporthei);
			MeMSOObjectMove(zoom_highlightdiv, zoom_miniimagex + zoom_newspotx, zoom_miniimagey + zoom_newspoty);
		}
	}
}

