﻿$(function()
{
	var box = function(jex, yF, xF, type)
	{
		if (xF && xF.constructor == String)
		{
			type = xF;
			xF = null;
		}
		var jo = $(jex);
		if (yF)
			jo.y = yF();
		if (xF)
			jo.x = xF();
		jo.isEmpty = function()
		{
			return jo.length==0;
		};
		jo._height = jo.height;
		jo.height = function(px)
		{
			if (typeof px != "undefined")
				jo._height(px+"px");
			else
				return jo._height();
		};
		jo.bottom = function(px)
		{
			if (typeof px != "undefined")
				jo.top(px-jo.height());
			else
				return jo.top()+jo.height();
		};
		jo.top = function(px)
		{
			if (typeof px != "undefined")
				jo.css("top", px+"px");
			else
				return jo.css("top");
		};
		jo.go = function()
		{
			if (!yF || jo.isEmpty())
				return;
			var offset = yF()-jo.y;
			if (offset < 0)
				jo.y = yF() - $.PageModel.y();
			else
				jo.y += offset;
			eval("jo."+type+"(jo.y)");
			if (xF)
				jo.css("left", xF()+"px");
		};
		return jo;
	};
	var loading = box("#loading", function()
		{
			return $.PageModel.y()+$.PageModel.h()-32;
		},
		"top");
	var f_box = box("#foot_box", function()
		{
			return $.PageModel.y()+$.PageModel.h()-11;
		},
		"bottom");
	var e_check = box(".e_check",
		function()
		{
			return $.PageModel.y()+($.PageModel.h()/2);
		},
		function()
		{
			return $.PageModel.w()/2;
		},
		"top");
	if (loading.isEmpty() && f_box.isEmpty() && e_check.isEmpty())
		return;
	
// 	$("#page_top").append("<a href='/gb/w2/userreport.asp' target='_blank'"
// 		+ " style='float:right;margin:5px 5px'>提交测试报告</a>");
	
	layout_go = function()
	{
		loading.go();
		f_box.go();
		e_check.go();
	};
	setInterval("layout_go()", 100);
});
