// JavaScript Document
// conf/js/contWin.js
// Content Window Control (Only)
function bringContentToFront(id) {
	var obj=document.getElementById(id);
	if (obj!=null) {
		for (var i=0; i<contDivIdArray.length; i++) {
			if (contDivIdArray[i]==id) {		
				obj.style.zIndex=99;
			} else {
				var obj2=document.getElementById(contDivIdArray[i]);
				if (obj2 != null) {
					obj2.style.zIndex--;
				}
			}
		}	
	}
}
function dragContDiv(obj,e) {
	if (obj !=null) {
		switch(e) {
			case "start":
				animatePageActive=true;
				currentDragDiv=obj;
				bringContentToFront(obj.id);
				obj.style.position="absolute";
				dragDivStartPositionX = parseInt(obj.style.left);
				dragDivStartPositionY = parseInt(obj.style.top);		
				offsetX = tempX-dragDivStartPositionX;
				offsetY = tempY-dragDivStartPositionY;
			break;
			case "stop":
				animatePageActive=false;
				currentDragDiv=obj;
				var str = obj.style.top;
				str=parseInt(str.substr(0,str.length-2));
				str=tempY-offsetY;
			break;
		}
	}
}







function resizeContDiv(obj,e,cont,scr) {
	switch(e) {
		case "start":
			resizeContDivActive=true;
			currentResizeDiv=obj;
			currentResizeContent=cont;
			currentResizeScrollbar=scr;
			bringContentToFront(currentResizeDiv.id);
		break;
		case "stop":
			var found=false;
			if (currentResizeDiv != null) {
				for(var i=0; i<contDivIdArray.length;i++) {
					if (contDivIdArray[i]==currentResizeDiv.id) {
						contDivMaxHeightArray[i]=currentResizeDiv.offsetHeight;
						found=true;
					}
				}
				if (!found) {
					contDivIdArray.push(currentResizeDiv.id);
					contDivMaxHeightArray.push(currentResizeDiv.offsetHeight)
				}
			}
			resizeContDivActive=false;
			currentResizeDiv=null;
			currentResizeContent='';
			currentResizeScrollbar='';
		break;
	}
}

function stopContentResize() {
	if (currentResizeDiv) {
	for(var i=0; i<contDivIdArray.length;i++) {
		if (contDivIdArray[i]==currentResizeDiv.id) {
			contDivMaxHeightArray[i]=currentResizeDiv.offsetHeight;
		}
	}
	}
	resizeContDivActive=false;
	currentResizeDiv=null;
}

function contentOpen(id) {
	if (!id) return;
	var obj = document.getElementById(id);
	if (obj != null) {
		bringContentToFront(id);
		currentContentDivId=id;
		obj=obj.style;
		if (obj.display != 'block') {
			animateContentDivOpening=true;
			animateContentDiv();
			obj.display='block';
		}
	}
}



function contentClose(id,com) {
	if (!id) return;
	var obj = document.getElementById(id);
	if (obj != null) {
		var container = obj.parentNode;
		if (container != null) {
			// remove the entire xml node
			container.removeChild(obj);
		}
	}
}

function contCollapse(divId,collapseImgId,cont,scr) {
	if (!divId) return;
	var obj = document.getElementById(divId);
	if (obj != null) {
		currentContentDivId=divId;
		
		currentResizeContent=cont;
		currentResizeScrollbar=scr;
		
		obj=obj.style;
		if (obj.height == '60px') {
			animateContentDivOpening=true;
			var imgObj=document.getElementById(collapseImgId);
			if (imgObj != null) {
				imgObj.src=contWinIsOpenImage; 
			}
			animateContentDiv();
		} else {
			animateContentDivOpening=false;
			animateContentDiv();
			var imgObj=document.getElementById(collapseImgId);
			if (imgObj != null) {
				imgObj.src=contWinIsCollapsedImage; 
			}
		}
	}
}



function animateContentDiv() {
	var obj=document.getElementById(currentContentDivId);
	if (obj != null) {
		var objHeightValue=obj.offsetHeight; 
		var found=false;
		for(var i=0; i<contDivIdArray.length; i++) {
			if (contDivIdArray[i]==currentContentDivId) {
				contentDivMaxHeight=contDivMaxHeightArray[i];
				found=true;
			}
		}
		if (obj.offsetHeight<=60 && !animateContentDivOpening) {
			window.clearTimeout(animateContDivTimeId);
			return false;
		}
//for (var i=0; i<contDivIdArray.length; i++) {
//	trace(contDivIdArray[i]+" " +contDivMaxHeightArray[i]);
//}
//		if (!found) {
//			contDivIdArray.push(currentContentDivId);
//			contDivMaxHeightArray.push(objHeightValue)
//		}
	
		if (animateContentDivOpening) {
			var n = ((contentDivMaxHeight - objHeightValue)/2);
			if (!n || isNaN(n) || n<1) {
				window.clearTimeout(animateContDivTimeId);
				return false;
				
			} else {
				objHeightValue += n;
			}
		} else {
			objHeightValue = Math.floor(objHeightValue/2);
			if (objHeightValue<=60) {
				objHeightValue=60;
			}
		}
		
		if ((!animateContentDivOpening && objHeightValue<1) 
			 || (animateContentDivOpening && objHeightValue>contentDivMaxHeight-1)) {
			
			window.clearTimeout(animateContDivTimeId);
			if (!animateContentDivOpening) {
				obj.style.display='none';
				obj.style.height='0px';
			} else {
				obj.style.height=contentDivMaxHeight+'px';
			}
		} else {
			obj.style.height=String(objHeightValue+'px');
			var cont=document.getElementById(currentResizeContent);
			var scr=document.getElementById(currentResizeScrollbar);
			if (cont!=null) {
				cont.style.height=(objHeightValue-60)+'px';
			}
			if (scr!=null) {
				scr.style.height=(objHeightValue-60)+'px';
			}
			animateContDivTimeId = window.setTimeout('animateContentDiv()',100);
		}
	} else {
	//	alert("Error! "+currentContentDivId+" Not Found");
	}
	return true;
}

