
var offset_x = 0;
var offset_x_max = 0;
var offset_y = 0;
var offset_y_max = 0;

var rotate_angle = 0;
var mirror_angle = 0;
var special_angle = 1;

function BoxPosition()
{
	var p = AbsolutePosition(document.getElementById("imgAvatar"));
	$("#box").css("display", "");
	$("#box").css("left", (p.x-2) + "px");
	$("#box").css("top", (p.y-2) + "px");

	offset_x = 0;
	offset_x_max = $("#imgAvatar").width() - 90;
	offset_y = 0;
	offset_y_max = $("#imgAvatar").height() - 90;
}

function ImageOk() 
{
	setTimeout("BoxPosition()", 1000);
}

function box_right()
{
	if(offset_x < offset_x_max) {
		var p = AbsolutePosition(document.getElementById("box"));
		$("#box").css("left", (p.x+1) + "px");
		offset_x++;
	}
}

function box_left()
{
	if(offset_x > 0) {
		var p = AbsolutePosition(document.getElementById("box"));
		$("#box").css("left", (p.x-1) + "px");
		offset_x--;
	}
}

function box_up()
{
	if(offset_y > 0) {
		var p = AbsolutePosition(document.getElementById("box"));
		$("#box").css("top", (p.y-1) + "px");
		offset_y--;
	}
}

function box_down()
{
	if(offset_y < offset_y_max) {
		var p = AbsolutePosition(document.getElementById("box"));
		$("#box").css("top", (p.y+1) + "px");
		offset_y++;
	}
}

function box_rotate()
{
	rotate_angle++;
	rotate_angle = rotate_angle % 4;
	document.getElementById("imgAvatar").src = "/Computer/Include/AvatarShow.aspx?rnd=" + Math.random() + "&r=" + rotate_angle + "&m=" + mirror_angle + "&s=" + special_angle;
	ImageOk();
}

function box_mirror()
{
	mirror_angle++;
	mirror_angle = mirror_angle % 3;
	document.getElementById("imgAvatar").src = "/Computer/Include/AvatarShow.aspx?rnd=" + Math.random() + "&r=" + rotate_angle + "&m=" + mirror_angle + "&s=" + special_angle;
	ImageOk();
}

function box_special()
{
	special_angle++;
	special_angle = special_angle % 2;
	document.getElementById("imgAvatar").src = "/Computer/Include/AvatarShow.aspx?rnd=" + Math.random() + "&r=" + rotate_angle + "&m=" + mirror_angle + "&s=" + special_angle;
	ImageOk();
}

function box_ok(obj)
{
	document.getElementById("imgAvatar").src = "/Computer/Include/AvatarShow.aspx?rnd=" + Math.random() + "&r=" + rotate_angle + "&m=" + mirror_angle + "&s=" + special_angle + "&f=1&x=" + offset_x + "&y=" + offset_y;
	
	obj.src = "/images/ajax-loader.gif";
	setTimeout("window.location = '/Computer/Detail.aspx';", 2000);
}
