function getWidth() {
	if (typeof(window.innerWidth) == 'number') {
		return window.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		return document.documentElement.clientWidth;
	} else if (document.body && document.body.clientWidth) {
		return document.body.clientWidth;
	}
}
function getHeight() {
	if (typeof(window.innerHeight) == 'number') {
		return window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		return document.documentElement.clientHeight;
	} else if (document.body && document.body.clientHeight) {
		return document.body.clientHeight;
	}
}

function getMouseX(e) {
	return ((document.all) ? event.clientX : e.pageX);
}
function getMouseY(e) {
	return ((document.all) ? event.clientY : e.pageY);
}



__cam = 1;
__sit = 0;
__int = 0;

__top = 0;
__left = 0;
__width = getWidth();
__height = getHeight();
__midWidth = __width/2;
__midHeight = __height/2;
__maxDiffWH = 100;
__maxDiffO = 50;



function chaseAndMove(e) {
	if (__cam == 1) {
		var __r = Math.round(Math.pow(Math.pow(__midWidth-getMouseX(e),2)+Math.pow(__midHeight-getMouseY(e),2),1/2));
		var __diffWH = Math.round((__maxDiffWH*__r)/_r);
		var __diffO = Math.round((__maxDiffO*__r)/_r);

		var img_ke = document.getElementById("img_ke");
		img_ke.width = _orgWH - __diffWH;
		img_ke.height = _orgWH - __diffWH;
		img_ke.style.filter = "alpha(opacity="+(100-__diffO)+")";
		img_ke.style.MozOpacity = (100-__diffO)/100;

		updatePositions(0);

		//window.status = getMouseX(e)+","+getMouseY(e);
	}
}

function sendItTo(x,y,z,ls) {
	if (__int == 0) {
		__cam = 0;
		var _divX = 10;
		var _divY = 6;
		if (z == __sit || z == 0) {
			__sit = 0;
			var _t = 0;
			var _l = 0;
			document.getElementById("img_ke").className = "cur_default";
		} else {
			__sit = z;
			var _t = ((getHeight()*y)/_divY)-(getHeight()/2);
			var _l = ((getWidth()*x)/_divX)-(getWidth()/2);
			document.getElementById("img_ke").className = "cur_hand";
		}
		for (i=1;i<=4;i++) {
			if (i == __sit) {
				var _cn = "light";
				var _da = "";
			} else {
				var _cn = "dark";
				var _da = "none";
			}
			document.getElementById("div_line"+i).className = "lines "+_cn;
			document.getElementById("div_area"+i).style.display = _da;
			document.getElementById("div_area"+i).style.width = document.getElementById("div_area"+i).style.height = "5px";
			document.getElementById("div_area"+i).style.top = document.getElementById("div_area"+i).style.left = "-50px";
		}
		__int = setInterval("moveItTo("+_t+","+_l+")",25);
	}
}

function moveItTo(t,l) {
	__top += (t-__top)/10;
	__left += (l-__left)/10;
	if (Math.abs(l-__left) < 1 && Math.abs(t-__top) < 1) {
		clearInterval(__int);
		__int = 0;
		__cam = 1;
	}
	updatePositions(0);
}



function updatePositions(f) {
	var div_line1_outer = document.getElementById("div_line1_outer");
	var div_line1 = document.getElementById("div_line1");
	var div_line2_outer = document.getElementById("div_line2_outer");
	var div_line2 = document.getElementById("div_line2");
	var div_line3_outer = document.getElementById("div_line3_outer");
	var div_line3 = document.getElementById("div_line3");
	var div_line4_outer = document.getElementById("div_line4_outer");
	var div_line4 = document.getElementById("div_line4");
	var div_ke = document.getElementById("div_ke");
	var img_ke = document.getElementById("img_ke");

	if (img_ke.style.display == "none") {
		img_ke.style.display = "";
	}

	if (f == 1) {
		_orgWH = img_ke.width;
	}

	_width = getWidth();
	_height = getHeight();

	div_ke.style.top = (__top+(__height-img_ke.height)/2) + "px";
	div_ke.style.left = (__left+(__width-img_ke.width)/2) + "px";

	div_line1.style.width = "5px";
	div_line1.style.height = div_line1_outer.style.height = (parseInt(div_ke.style.top)+img_ke.height+5) + "px";
	div_line1_outer.style.top = "0px";
	div_line1_outer.style.left = (parseInt(div_ke.style.left)-14) + "px";

	div_line2.style.width = div_line2_outer.style.width = (parseInt(div_ke.style.left)+img_ke.width+5) +"px";
	div_line2.style.height = "5px";
	div_line2_outer.style.top = (parseInt(div_ke.style.top)+img_ke.height-parseInt(div_line2.style.height)-5) + "px";
	div_line2_outer.style.left = "0px";

	div_line3.style.width = "5px";
	div_line3.style.height = div_line3_outer.style.height = (parseInt(div_ke.style.top)+img_ke.height-2+(_height-__height)-(__top*2)) + "px";
	div_line3_outer.style.top = (_height-parseInt(div_line3.style.height)) + "px";
	div_line3_outer.style.left = (parseInt(div_ke.style.left)+img_ke.width-parseInt(div_line3.style.width)-5) + "px";

	div_line4.style.width = div_line4_outer.style.width = (parseInt(div_ke.style.left)+img_ke.width-2+(_width-__width)-(__left*2)) +"px";
	div_line4.style.height = "5px";
	div_line4_outer.style.top = (parseInt(div_ke.style.top)-14) + "px";
	div_line4_outer.style.left = (_width-parseInt(div_line4.style.width)) + "px";

	if (__sit > 0) {
		var div_area = document.getElementById("div_area"+__sit);
		if (__sit == 1) {
			div_area.style.width = (_width-parseInt(div_line1_outer.style.left)+22) + "px";
			div_area.style.height = (parseInt(div_line4_outer.style.top)+15) + "px";
			div_area.style.left = (parseInt(div_line1_outer.style.left)+18) + "px";
			div_area.style.top = "0px";
		} else if (__sit == 2) {
			div_area.style.width = (parseInt(div_line1_outer.style.left)+19) + "px";
			div_area.style.height = (parseInt(div_line2_outer.style.top)+17) + "px";
			div_area.style.left = "0px";
			div_area.style.top = "0px";
		} else if (__sit == 3) {
			div_area.style.width = (parseInt(div_line3_outer.style.left)+17) + "px";
			div_area.style.height = (_height-parseInt(div_line2_outer.style.top)+22) + "px";
			div_area.style.left = "0px";
			div_area.style.top = (parseInt(div_line2_outer.style.top)+18) + "px";
		} else if (__sit == 4) {
			div_area.style.width = (_width-parseInt(div_line3_outer.style.left)+20) + "px";
			div_area.style.height = (_height-parseInt(div_line4_outer.style.top)+20) + "px";
			div_area.style.left = (parseInt(div_line3_outer.style.left)+20) + "px";
			div_area.style.top = (parseInt(div_line4_outer.style.top)+20) + "px";
		}
		div_area.style.lineHeight = div_area.style.height;
	}

	__midWidth = (__width/2)+__left;
	__midHeight = (__height/2)+__top;

	if (__left < 0) {
		_midWidth = _width-__midWidth;
	} else {
		_midWidth = __midWidth;
	}
	if (__top < 0) {
		_midHeight = _height-__midHeight;
	} else {
		_midHeight = __midHeight;
	}

	_r = Math.round(Math.pow(Math.pow(_midWidth,2)+Math.pow(_midHeight,2),1/2));
}


_GET = new Object();
function parseLS() {
	var _queryString = location.search.substring(1);
	var _eachQuery = _queryString.split("&");
	for (q=0;q<_eachQuery.length;q++) {
		var _kv = _eachQuery[q].split("=");
		_GET[_kv[0]] = _kv[1];
	}
}



window.onload = function() {
	updatePositions(1);
	parseLS();
	
	if (_GET["url"] != undefined) {
		var _ls = _GET["ls"];
	} else {
		var _ls = "";
	}
	if (_GET["section"] == 1) {
		sendItTo(2,5,1,_ls);
	} else if (_GET["section"] == 2) {
		sendItTo(8,5,2,_ls);
	} else if (_GET["section"] == 3) {
		sendItTo(8,1,3,_ls);
	} else if (_GET["section"] == 4) {
		sendItTo(2,1,4,_ls);
	}
}

window.onresize = function() {
	updatePositions(0);
}

if (document.layers) {
	document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = function(e) {
	chaseAndMove(e);
}