﻿// JavaScript Document
var img_id = "floatpicture";
var picleft = 0 , pictop = 200 , picahead = "bottom";
function piccing() {
	var pic = document.getElementById(img_id);
	if ( picleft <= document.documentElement.scrollLeft ) {
		if ( picahead == "bottom" ) {
			picahead = "left";
		}
		else if ( picahead == "_top" ) {
			picahead = "_left";
		}
		else if ( picahead == "right" ) {
			picahead = "_left";
		}
		else if ( picahead == "_right" ) {
			picahead = "left";
		}
	}
	else if ( pictop <= document.documentElement.scrollTop ) {
		if ( picahead == "left" ) {
			picahead = "top";
		}
		else if ( picahead == "_right" ) {
			picahead = "_top";
		}
		else if ( picahead == "bottom" ) {
			picahead = "_top";
		}
		else if ( picahead == "_bottom" ) {
			picahead = "top";
		}
	}
	else if ( picleft >= document.documentElement.clientWidth - 300 + document.documentElement.scrollLeft ) {
		if ( picahead == "top" ) {
			picahead = "right";
		}
		else if ( picahead == "_bottom" ) {
			picahead = "_right";
		}
		else if ( picahead == "left" ) {
			picahead = "_right";
		}
		else if ( picahead == "_left" ) {
			picahead = "right";
		}
	}
	else if ( pictop >= document.documentElement.clientHeight - 210 + document.documentElement.scrollTop ) {
		if ( picahead == "right" ) {
			picahead = "bottom";
		}
		else if ( picahead == "_left" ) {
			picahead = "_bottom";
		}
		else if ( picahead == "top" ) {
			picahead = "_bottom";
		}
		else if ( picahead == "_top" ) {
			picahead = "bottom";
		}
	}
	if ( picahead == "left" || picahead == "_bottom" ) {
		picleft++ , pictop--;
	}
	else if ( picahead == "top" || picahead == "_left" ) {
		picleft++ , pictop++;
	}
	else if ( picahead == "right" || picahead == "_top" ) {
		picleft-- , pictop++;
	}
	else if ( picahead == "bottom" || picahead == "_right" ) {
		picleft-- , pictop--;
	}
	pic.style.left = picleft + "px";
	pic.style.top = pictop + "px";
}
setInterval(piccing,10);