var is;
var doc;
var sty;
var htm;
function initAll()
{
    is = new Is();

    if(is.ns4 && (is.minor>=4.5)) {
        doc = "document";
        sty = "";
        htm = ".document"
        available_width=innerWidth;
        available_height=innerHeight;
        preLoad();
    } else if(is.ie4) {
        doc = "document.all";
        sty = ".style";
        htm = ""
        available_width=document.body.clientWidth;
        available_height=document.body.clientHeight;
        preLoad();
    } else {
        location.replace('get_a_life.html');
    }
}



function set_next(x,y)
{
	next_x=parseInt(x)+parseInt(binocObj.left);

    if(is.ns4) {
	next_y=parseInt('0')+parseInt(binocObj.top);
    } 
    else if(is.ie4) {
	next_y=parseInt(y)+parseInt(binocObj.top);
    }

}

function positionLayers() {
    arrObj = eval(doc + '["divLink"]' + sty);
    arrObj.left = Math.round(available_width/2)-200;
    arrObj.top = Math.round(available_height/2)+140;
    arrObj.width = 400;
    arrObj.height = 400;
    arrObj.visibility = "visible";


    binocObj = eval(doc + '["divBinoc"]' + sty);
    binocObj.left = Math.round(available_width/2)-125;
    binocObj.top = Math.round(available_height/2)-125;
    binocObj.visibility = "visible";

    bgzObj = eval(doc + '["divBg"]' + sty);
    bgzObj.left = parseInt(binocObj.left);
    bgzObj.top = parseInt(binocObj.top);

    current_x=parseInt(bgzObj.left);
    current_y=parseInt(bgzObj.top);
    next_x=current_x;
    next_y=current_y;

	var temptop = parseInt(binocObj.top) - parseInt(current_y) + 5;
	var templeft = parseInt(binocObj.left) - parseInt(current_x) + 5;


    bgz_clipTo(temptop, templeft+245, temptop+245, templeft);

    bgzObj.visibility = "visible";

    var tempstr="moveBg(" + parseInt(next_x) + "," + parseInt(next_y) + ");"
    setTimeout(tempstr, 1000);
}

function bgz_clipTo(t,r,b,l){
	if(is.ns)
	{
		bgzObj.clip.top=parseInt(t);
		bgzObj.clip.right=parseInt(r);
		bgzObj.clip.bottom=parseInt(b);
		bgzObj.clip.left=parseInt(l);
	}
	else
	{
		bgzObj.clip="rect("+t+","+r+","+b+","+l+")";
	}
}

function moveBg(x,y)
{
	x=parseInt(x);
	y=parseInt(y);
	var dist_to_go = Math.abs(Math.sqrt(Math.abs(((current_x-x)^2) + ((current_y-y)^2))));	
	if(parseInt(dist_to_go)==NaN) alert('dtg');

	if(parseInt(x)==NaN) alert('x');
	if(parseInt(y)==NaN) alert('y');

	if (Math.abs(dist_to_go) < 5)
	{
		current_x=x;
		current_y=y;
	}
	else
	{
		if(dist_to_go==0)
		{
			current_x=x;
			current_y=y;
		}
		else
		{
			current_x=current_x - parseInt(((current_x-x)/dist_to_go)*1);
			current_y=current_y - parseInt(((current_y-y)/dist_to_go)*1);
		}
	}
	
	var temptop = parseInt(binocObj.top) - parseInt(current_y) + 5;
	var templeft = parseInt(binocObj.left) - parseInt(current_x) + 5;

	if(parseInt(temptop)==NaN) alert('tt');
	if(parseInt(templeft)==NaN) alert('tl');
	
	bgz_clipTo(temptop, templeft+245, temptop+245, templeft);
	

	bgzObj.left=parseInt(current_x);
	bgzObj.top=parseInt(current_y);
	
	var tempstr="moveBg(" + parseInt(next_x) + "," + parseInt(next_y) + ")";
	setTimeout(tempstr, 1);
}

function geoPos()
{
    if(is.ns4) {
        available_width=innerWidth;
        available_height=innerHeight;
	left_offset=parseInt(window.pageXOffset);
	top_offset=parseInt(window.pageYOffset);
    } 
    else if(is.ie4)
    {
        available_width=document.body.clientWidth;
        available_height=document.body.clientHeight;
	left_offset=document.body.scrollLeft;
	top_offset=document.body.scrollTop;
    }

    var divBrand = eval(doc + '["divBrand"]' + sty);
    divBrand.left = (left_offset + available_width) - ( 130 + 5 );
    divBrand.top = (top_offset + available_height) - ( 100 + 0 );
    divBrand.visibility = "visible";
}

function Is() {
    var agent = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.ns  = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
    this.ns2 = (this.ns && (this.major == 2));
    this.ns3 = (this.ns && (this.major == 3));
    this.ns4b = (this.ns && (this.minor < 4.04));
    this.ns4 = (this.ns && (this.major >= 4));
    this.ie   = (agent.indexOf("msie") != -1);
    this.ie3  = (this.ie && (this.major == 2));
    this.ie4  = (this.ie && (this.major >= 4));
    this.op3 = (agent.indexOf("opera") != -1);
    this.win   = (agent.indexOf("win")!=-1);
    this.mac   = (agent.indexOf("mac")!=-1);
    this.unix  = (agent.indexOf("x11")!=-1);
}
function onerror() {
    document.location.href = "javascript:";
}

var count = 0;

function preLoad() {
    binoc = new Image();
    binoc.src = "images/black_circle.gif";

    bgz = new Image();
    bgz.src = "images/bg7.jpg";

    positionLayers();
}

var current_x=0;
var current_y=0;

var next_x=0;
var next_y=0;
