// // Simple follow the mouse script
// copyright Stephen Chapman, 30th September 2005
// you may copy this script provided that you retain the copyright notice

var divName = 'mydiv'; // div that is to follow the mouse
var offX = 15;         // X offset from mouse position
var offY = 15;         // Y offset from mouse position

// no changes required below this line
function mouseX(evt) {
	if (!evt)
		evt = window.event; 
	if (evt.pageX)
		return evt.pageX;
	else if (evt.clientX)
		return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft); 
	else return 0;
} 

function mouseY(evt) {
	if (!evt) 
		evt = window.event; 
	if (evt.pageY) 
		return evt.pageY; 
	else if (evt.clientY)
		return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); 
	else 
		return 0;
	} 
function follow(evt) {
	if (document.getElementById) {
		var obj = document.getElementById(divName).style; 
		obj.visibility = 'visible'; 
		obj.left = (parseInt(mouseX(evt))+offX) + 'px';  
		obj.top = (parseInt(mouseY(evt))+offY) + 'px';
	}
} 

//document.onmousemove = follow;

function handleOut() {
	//alert('ryan');
	var obj = document.getElementById(divName).style;
	obj.visibility = 'hidden';
}
function handleOver(img) {
	src = img.src;
	new_src = src.replace('s.jpg','m.jpg');
	div = document.getElementById('mydiv');
	div.innerHTML = img.title + '<br/><img src="' + new_src + '"/>';
	img.onmousemove = follow;
}

var busy     = new Array();
var how_many = Array(3);

/* Photo Class */
function Photo(img,dest_x,dest_y) {
	//class properties
	Photo.regex = /[0-9]{2,4}/;
	Photo.second = 1000;
	Photo.refresh_rate = 50;
	
	//instance properites
	this.image  = img;
	this.cur_x = Number(Photo.regex.exec(this.image.style.left));
	this.cur_y = Number(Photo.regex.exec(this.image.style.top));
	this.dest_x = dest_x;
	this.dest_y = dest_y;
	this.seconds = Math.round(Math.random() * 6) + 4;
	this.movements = (Photo.second/Photo.refresh_rate) * this.seconds;
	
	//determine velocity
	this.vel_x = (this.dest_x - this.orig_x) / this.movements;
	this.vel_y = (this.dest_y - this.orig_y) / this.movements;
	
	//determine destination boundaries
	this.y1 = this.dest_y - 5;
	this.y2 = this.dest_y + 5;
}
Photo.prototype.get_interval_id = function() {
	this.interval_id = window.setInterval("move_image()",Photo.refresh_rate);
}
Photo.prototype.move_image = function() {
	this.orig_x += this.vel_x;
	this.orig_y += this.vel_y;
	
	this.image.style.left = this.orig_x + 'px';
	this.image.style.top  = this.orig_y + 'px';

	if((this.y1 < this.cur_y) &&  (this.cur_y < this.y2)) {
		this.image.style.top  = this.dest_y + 'px';
		this.image.style.left = this.dest_x + 'px';
		window.clearInterval(this.interval_id);
	}
}
function move_image() {
	//alert (this.image);	
}
/*var img = Math.round(Math.random() * photos.length) + 1;
var element = document.getElementById(photos[img]);
gee = new Photo(element,900,900);
gee.get_interval_id();
var regex = /[0-9]{2,4}/;
var origx = Number(regex.exec(element.style.left));
var origy = Number(regex.exec(element.style.top));
var destx = 500;
var desty = 500;
var seconds = 10;
var second = 1000;
var rate = 50;
var movements = (second/rate) * seconds;
var xtravel = destx - origx;
var ytravel = desty - origy;
var velx = xtravel / movements;
var vely = ytravel / movements;*/
