﻿var move = false;
var zoom_div;
var _x = 0;
var _y = 0;

var shade;
var shade_x;
var shade_y;

var image;
var image_x = 0;
var image_y = 0;

function activateZoom(e)
{
	move = true;
	zoom_div = document.getElementById('zoom_div');
	shade = document.getElementById('shade');
	image =  document.getElementById('large_image');

	zoom_div.style.display = "block";
	shade.style.display = "block";
}

function moveImage(e, x)
{
	if (move == true)
	{
		var mouse_pos = mousePos(e);
		var div_pos = getPos(x);
		
		_x = mouse_pos.left;
		_y = mouse_pos.top;
		
		_x = _x - div_pos.left;
		_y = _y - div_pos.top;
		
		
		if ((_x > 50) && (_x < 249))
		{
			shade_x = -250 + _x;
			image_x = (_x-50)*3;
		}
		else if (_x < 51)
		{
			shade_x = -200;
			image_x = 0;
		}
		else if (_x > 248)
		{
			shade_x = -2;
			image_x = 596;
		}
		
		if ((_y > 50) && (_y < 249))
		{
			shade_y = -250 + _y;
			image_y = (_y-50)*3;
		}
		else if (_y < 51)
		{
			shade_y = -200;
			image_y = 0;
		}
		else if (_y > 248)
		{
			shade_y = -2;
			image_y = 596;
		}
		
		image.style.left = '-' + image_x + 'px';
		image.style.top = '-' + image_y  + 'px';
		
		shade.style.top = shade_y + 'px';
		shade.style.left = shade_x + 'px';
		
		//zoom_div.innerHTML = "Top:" + _y + "| Left:" + _x;
		//zoom_div.innerHTML = zoom_div.innerHTML + "<br />y:" + shade_y + "| x:" + shade_x;
	}
}

function deactivateZoom()
{
	move = false;
	zoom_div.style.display = "none";
	shade.style.display = "none";
}

//GET POSITION OF MOUSE
function mousePos(e)
{
	var output = new Object();
	
	var __x = 0;
	var __y = 0;
	
	if (!e) var e = window.event;
			
	if (e.pageX || e.pageY)
	{
		__x = e.pageX;
		__y = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		__x = e.clientX + document.body.scrollLeft+ document.documentElement.scrollLeft;
		__y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	
	output.left = __x;
	output.top = __y;
	
	return output;
}

//GET POSITION OF DIV
function getPos(obj)
{
	var output = new Object();
	var mytop=0, myleft=0;
	while( obj) {
		mytop+= obj.offsetTop;
		myleft+= obj.offsetLeft;
		obj= obj.offsetParent;
	}
	output.left = myleft;
	output.top = mytop;
	return output;
}
