/***
@ dateTime : 2010.10.13
@ author : yanliang chen
**/

/**
param :
	name  : divname
	align : 水平或垂直对齐（仅vertical,horizontal)
	pos   : 居中或居底对齐（仅bottom,middle)
**/
var analysisBox = function(name,align,pos){
		var boxes = function(){
			var returns = document.getElementsByName(name);
			if(returns.length > 0) return returns;
			returns = new Array();
			var e = document.getElementsByTagName("div");
			for(i = 0; i < e.length; i++) {
				if(e[i].getAttribute("name") == name)
					returns[returns.length] = e[i]; 
			}
			return returns; 
		}(name);
		
		if(align == "vertical"){
			for(ibox = 0;ibox < boxes.length; ibox++){
				box = boxes[ibox];
				try{
					if(pos == "bottom"){
						box.style.marginTop = eval(box.parentNode.parentNode.offsetHeight - box.offsetHeight) + "px";
					}else if(pos == "middle"){
						box.style.marginTop = eval(box.parentNode.parentNode.offsetHeight - box.offsetHeight) / 2 + "px";
					}
				}catch(e){}
			}
		}else if(align == "horizontal"){
			for(ibox = 0;ibox < boxes.length; ibox++){
				box = boxes[ibox];
				boxFrameHeight = box.parentNode.id == "center-offset" ? eval(box.parentNode.parentNode.parentNode.offsetHeight) : eval(box.parentNode.parentNode.offsetHeight);
				for(i = 0; i < box.childNodes.length; i++){
					childBox = box.childNodes.item(i);
					try{
						if(pos == "bottom"){
							childBox.style.marginTop = eval(boxFrameHeight - childBox.offsetHeight) + "px";
						}else if(pos == "middle"){
							childBox.style.marginTop = (boxFrameHeight - childBox.offsetHeight) / 2 + "px";
						}
					}catch(e){}
				}
			}   
		}
		
}

// 垂直方向居中与居底对齐
analysisBox("vbox-middle-panel","vertical","middle");
analysisBox("vbox-bottom-panel","vertical","bottom");
// 水平方向居中与居底对齐
analysisBox("hbox-middle-panel","horizontal","middle");
analysisBox("hbox-bottom-panel","horizontal","bottom");
