  // JavaScript Document

var animatePageActiveA5=true;
var noAnimation=false;
var currentDragDiv=null;
var currentResizeDiv=null;
var currentResizeContent=null;
var resizeDivActive=false;
var animateActive=false;
var tempX;
var tempY;
var offsetX;
var offsetY;
var animateBublicationDivOpening=true;
var currentBublicationDivId='';
var bublicationDivMaxHeight=180;
var bublicationDivMaxWidth=800;
var animateBubDivTimeId='';
var collapseTrigger = 44;
var bubDivIdArray= new Array();
if ( !isDockedArray ) {
	var isDockedArray= new Array('','','','','','','','','',''); // this is set by conducta
}
var bubbleBarContentsArray = new Array();
var contentDivIdArray = new Array();
var bubDivMaxHeightArray= new Array(); //225
var topOffset = 147;
var bottomOffset = 32;
var bottomOffsetOpenBub = 205;
var bottomOffsetClosedBub = bottomOffset;
var bubWinIsCollapsedImage='';
var bubWinIsOpenImage='';
var IE=false;
var bubWinIsOpenImage = "/lib/aria5/graphics/skin/default/bubbleCollapseButtonIsOpen.png";
var bubWinIsCollapsedImage = "/lib/aria5/graphics/skin/default/bubbleCollapseButtonIsCollapsed.png";
var mouseIsDown = false;
// document.addEventListener('mousemove', getMouseXY, true);
document.addEventListener('mousedown', mouseIsDownSet, true);
document.addEventListener('mouseup', mouseIsUpSet, true);
function mouseIsDownSet() {
	mouseIsDown = true;
}
function mouseIsUpSet() {
	mouseIsDown = false;	
}
function recordBubPosition(obj) {
//	trace(obj.id);
if (!conducta) {
	if (obj != null) {
		var bubbleName = obj.id;
		bubbleName = bubbleName.substr(0,bubbleName.length-3);
		var bubbleX = obj.offsetLeft;
		var bubbleY = obj.offsetTop;
		var bubbleZ = obj.style.zIndex;
		var bubbleW = obj.offsetWidth;
		var bubbleH = obj.offsetHeight;
		var bubbleState = 1;
		var ltwhz = '';
		if (bubbleH <= collapseTrigger) {
			var heightStoreObj = document.getElementById(bubbleName+"DivHeight");
			if (heightStoreObj != null) {
				bubbleH = heightStoreObj.value;
				bubbleState = 0;
			} else {
//				trace('not found: '+bubbleName+"DivHeight");
			}
		}
		if (bubbleH <= collapseTrigger) {
			var widthStoreObj = document.getElementById(bubbleName+"DivWidth");
			if (widthStoreObj != null) {
				bubbleW = widthStoreObj.value;
				bubbleState = 0;
			} else {
//				trace('not found: '+bubbleName+"DivWidth");
			}
		}
		// ltwhz
		// div restore object holds a string L,T,W,H,Z, save to bubPos.
		if (bubbleH > collapseTrigger) {
			var ltwhzStoreObj = document.getElementById(bubbleName+"DivRestore");
			if (ltwhzStoreObj != null) {
				ltwhz = ltwhzStoreObj.value;
			} else {
//				trace('not found: '+bubbleName+"DivRestore");
			}
		}
		var params = "&bubName="+bubbleName;
		params += "&bubX="+bubbleX;
		params += "&bubY="+bubbleY;
		params += "&bubZ="+bubbleZ;
		params += "&bubW="+bubbleW;
		params += "&bubH="+bubbleH;
		params += "&bubState="+bubbleState;
		params += "&ltwhz="+ltwhz;
		var bubbleSplurge = getAllBubbles();
		zIndexList='';
		for (var i=0; i<bubbleSplurge.length; i++) {
			name = bubbleSplurge[i].id;
			name = name.substr(0,name.length-3);
			zIndexList += name + "," + bubbleSplurge[i].style.zIndex + ",";
		}
		params += "&zIndexes="+zIndexList;
//		trace(params);
		var str = "func=recordBubPos"	+ params;
		str = dataSourcePathA5 + "?" + str;
		sendToServerAria5(str);
	}
}
}
function bubCollapse(divId,collapseImgId) {
	if (divId) {
		var obj = document.getElementById(divId);
		var str = divId.substr(0,divId.length-3);
		var contentDiv = document.getElementById(str);
		if (obj != null) {
			
			bringBubToFront(divId);
			
//			if (!isInDock(divId)) {
			currentBublicationDivId=divId;
			
			if (obj.offsetHeight <= collapseTrigger) {
				
				// open it
				
				animateBublicationDivOpening=true;
				if (collapseImgId) {
					var imgObj=document.getElementById(collapseImgId);
					
					if (imgObj != null) {
						imgObj.src=bubWinIsOpenImage; 
					}
					
				}
				if (contentDiv != null) {
		//			contentDiv.style.height="85%";
					contentDiv.style.display="block";
					var scrl = getCurrentBubbleScrollBar();
					if (scrl != null) {
						scrl.style.display="block";
					}
				}
				animateBublicationDiv();
			
			} else {
				
				// close it.
				
				var dh = getCurrentBubbleDragHandle();
				if (dh != null) {
					dh.style.display="none";
				}
				
				
				animateBublicationDivOpening=false;
				animateBublicationDiv();
				if (contentDiv != null) {
//					contentDiv.style.height='1px';
					
				}
				var scrl = getCurrentBubbleScrollBar();
						if (scrl != null) {
							scrl.style.display="none";
						}
				var imgObj=document.getElementById(collapseImgId);
				if (imgObj != null) {
					imgObj.src=bubWinIsCollapsedImage; 
				}
			}
//			}
		}
	}
}
function bubClose(divId) {
	if (divId) {
		var obj = document.getElementById(divId);
		if (obj != null) {
			// see aria5/js/lib.js
			dropNode(divId);
		}
	}
}
function popBubble(divId) {
	currentDragHandle = null;
	if (divId) {
		var obj = document.getElementById(divId);
		if (obj != null) {
			// see aria5/js/lib.js
			dropNode(divId);
			if ( !conducta ) {
			var str = "func=popBubble&name="	+ divId.substr(0,divId.length-3);
	//		trace('pop: '+str);
			str = dataSourcePathA5 + "?" + str;
			sendToServerAria5(str);
			}
			
			
		}
	}
}
function bubOpen(divId,collapseImgId) {
	if (divId) {
		var obj = document.getElementById(divId);
		var str = divId.substr(0,divId.length-3);
		var contentDiv = document.getElementById(str);
		if (obj != null) {
			
			var scrl = getCurrentBubbleScrollBar();
			if (scrl != null) {
				scrl.style.display="block";
			}
			
			bringBubToFront(divId);
			currentBublicationDivId=divId;
			var objStyle=obj.style;
			if (objStyle.height == collapseTrigger+'px') {
				animateBublicationDivOpening=true;
				if (contentDiv != null) {
		//			contentDiv.style.height="85%";
					contentDiv.style.display="block";
				}
				if (collapseImgId) {
					var imgObj=document.getElementById(collapseImgId);
					if (imgObj != null) {
						imgObj.src=bubWinIsOpenImage; 
					}
				}
				animateBublicationDiv();
			}
		}
	}
}
function setCurrentDragHandle(id) {
	if ( !mouseIsDown ) {
		currentDragHandle = id;
	}
}
function getCurrentBubbleScrollBar() {
	//    currentBublicationDivId	
	var scrollBarObject = null;
	if (currentBublicationDivId) {
		var obj=document.getElementById(currentBublicationDivId);
		if (obj != null) {
			for (var i=0; i<obj.childNodes.length; i++) {
				if (obj.childNodes[i].className == "ergoScroll") {
					scrollBarObject = obj.childNodes[i];
				}
			}
		}
	}
	if (!scrollBarObject) { trace('no ergoScroll in '+currentBublicationDivId); }
//	trace('currentBublicationDivId: '+currentBublicationDivId);
	return scrollBarObject;
}
function getCurrentBubbleDragHandle() {
	//    currentBublicationDivId	
	var dragHandleObj = null;
	var obj=getCurrentBubbleScrollBar();
	if (obj != null) {
		for (var i=0; i<obj.childNodes.length; i++) {
		
			if (obj.childNodes[i].className == "scrDrag") {
				dragHandleObj = obj.childNodes[i];
				//trace('dragHandleObj: ');
			}
			
		}
	}
	
	return dragHandleObj;
}
function animateBublicationDiv() {
	if (currentBublicationDivId) {
		var obj=document.getElementById(currentBublicationDivId);
		if (obj != null) {
			
			var heightStoreObj = document.getElementById(currentBublicationDivId+"Height");
			if (heightStoreObj != null) {
				bublicationDivMaxHeight = heightStoreObj.value;
			}
			var objHeightValue = obj.offsetHeight;
			
			var widthStoreObj = document.getElementById(currentBublicationDivId+"Width");
			if (widthStoreObj != null) {
				bublicationDivMaxWidth = widthStoreObj.value;
			} else {
				trace('cannot find '+currentBublicationDivId+"Width");	
			}
			var objWidthValue = obj.offsetWidth;
			
			
			
			if (objHeightValue<1 || !objHeightValue ) {objHeightValue=1;}
			if (objWidthValue<1 || !objWidthValue ) {objWidthValue=1;}
			
			if (animateBublicationDivOpening) {
				objHeightValue += ((bublicationDivMaxHeight - objHeightValue)/2);
				objWidthValue += ((bublicationDivMaxWidth - objWidthValue)/2);
			} else {
				objHeightValue = Math.floor(objHeightValue/2);
				if (!isInDock(currentBublicationDivId) && objHeightValue<(collapseTrigger+5)) {
					objHeightValue=collapseTrigger;
				}
			}
	
			if ((!animateBublicationDivOpening && objHeightValue<1) 
				 || (animateBublicationDivOpening && objHeightValue>bublicationDivMaxHeight-1)) {
				
				
				window.clearTimeout(animateBubDivTimeId);
				recordBubPosition(obj);
				if (!animateBublicationDivOpening) {
					obj.style.height='0px';
					
					
					
				} else {
					obj.style.height=bublicationDivMaxHeight+'px';
					obj.style.width=bublicationDivMaxWidth+'px';




					var dh = getCurrentBubbleDragHandle();
					if (dh != null) {
//trace('show '+dh.id);
						dh.style.display="block";
					}
				}
				
			} else {
				
				obj.style.height=String(objHeightValue+'px');
				obj.style.width=String(objWidthValue+'px');
				
				if (obj.offsetHeight < bublicationDivMaxHeight-1 && obj.offsetHeight > collapseTrigger) {
					animateBubDivTimeId = window.setTimeout('animateBublicationDiv()',100);
					// big - and just finished animating
					
					
					
				} else {
					
					// small - and just finished animating
					if (obj.offsetHeight <= collapseTrigger) {
					
						var str = currentBublicationDivId.substr(0,currentBublicationDivId.length-3);
						var contentDiv = document.getElementById(str);
						if (obj != null) {
//trace('hide '+str);
							contentDiv.style.display="none";
						}
						
						// hide the scroll bar contents
	
						var scrl = getCurrentBubbleScrollBar();
						if (scrl != null) {
//trace('hide '+scrl.id);
							scrl.style.display="none";
						}
						
						
					}
					
					if (animateBublicationDivOpening ) {
						var dh = getCurrentBubbleDragHandle();
						if (dh != null) {
//trace('show '+dh.id);
							dh.style.display="block";
						}
					}
					window.clearTimeout(animateBubDivTimeId);
					recordBubPosition(obj);
				}
			}
		} else {
		//	alert("Error! "+currentBublicationDivId+" Not Found");
		}
	}
}


function bringBubToFront(id) {
	var currentZ = 0;
//	trace('bringBubToFront: '+id);
	if (id) {
		var obj=document.getElementById(id);
	//	var str = id; //+ 'Container'; //id.substr(0,id.length-3);
	//	trace(str);
	//	var contentDiv = document.getElementById(str);
		if (obj != null) {
			currentBublicationDivId = id;
			var container = document.getElementById(targetDivA5);
			var zArray = getAllDepthBubbles();
			
			for (var i=0; i<zArray.length; i++) {
				
				if (zArray[i].id == id) {
					
					zArray[i].style.zIndex = 1000;
					zArray[i].style.opacity = 1;
				} else {
					zArray[i].style.zIndex--;
					if (zArray[i].style.zIndex < 1) {
						zArray[i].style.zIndex = 1;	// crucial to prevent things getting unclickable behind container (but still visible!)
					}
					zArray[i].style.opacity = 0.8;
				}
		
			}
//			recordBubPosition(obj);
		} else {
	//		trace('bringBubToFront: '+id);
		}
	}
}
function removeFromDock(obj) {
	for (var i=0; i<isDockedArray.length; i++) {
		if (obj.id==isDockedArray[i]) {
			//isDockedArray[i]='';
			isDockedArray.splice(i,1);
			return;
		}
	}
}
function removeFromBubbleBar(obj) {
	for (var i=0; i<bubbleBarContentsArray.length; i++) {
		if (obj.id==bubbleBarContentsArray[i]) {
			bubbleBarContentsArray.splice(i,1);
//			trace('rem: '+obj.id);
			return;
		}
	}
}

var bubBarFrameLimit = 10;
var bubBarFrameCounter = 1;
var currentBubble = null;
var bubBarAnimTimeoutObj = null;
var bubBarTarget = new Array(4); // left, top, width, height, zIndex
var bubRestoreTarget = new Array(4); // left, top, width, height, zIndex
var currentBubblePos = new Array(4); // offsetLeft, offsetTop, width, height
var currDeflIncr = new Array(4); // current Deflate Increments - left, top, w, h

function deflateToBubbleBar(id) {
	var obj = document.getElementById(id);
	currentDragHandle=null;
	if (obj != null) {
//		addToDock(obj);	
		currentBubble = obj;
		
		if (!inBubbleBar(id)) {
			getTargetDeflateCoords();
			currentBubblePos = Array(obj.offsetLeft, obj.offsetTop, obj.offsetWidth, obj.offsetHeight);
//			monitorPosition(currentBubble);
			var a = (currentBubblePos[0]-bubBarTarget[0]) / bubBarFrameLimit;
			var b = (bubBarTarget[1]-currentBubblePos[1]) / bubBarFrameLimit;
			var c = (currentBubblePos[2]-bubBarTarget[2]) / bubBarFrameLimit;
			var d = (currentBubblePos[3]-bubBarTarget[3]) / bubBarFrameLimit;
			currDeflIncr = Array(a,b,c,d);
//			monitorIncrements();
			bubBarAnimTimeoutObj = window.setInterval(deflateStep,10);
		 } else {
			reflateFromBubbleBar(id);
		 }
	} else {
		trace('not found: '+id);	
	}
}
function reflateFromBubbleBar(id) {
	var obj = document.getElementById(id);
	
	if (obj != null) {
		removeFromBubbleBar(obj);
		currentBubble = obj;
		getTargetReflateCoords();
		currentBubblePos = Array(obj.offsetLeft, obj.offsetTop, obj.offsetWidth, obj.offsetHeight);
//		monitorPosition(currentBubble);
		var a = (currentBubblePos[0]-bubRestoreTarget[0]) / bubBarFrameLimit;
		var b = (bubRestoreTarget[1]-currentBubblePos[1]) / bubBarFrameLimit;
		var c = (currentBubblePos[2]-bubRestoreTarget[2]) / bubBarFrameLimit;
		var d = (currentBubblePos[3]-bubRestoreTarget[3]) / bubBarFrameLimit;
		currDeflIncr = Array(a,b,c,d);
//			monitorIncrements();
		bubBarAnimTimeoutObj = window.setInterval(reflateStep,10);
	}
}
function deflateStep() {
	// Deflate repeat function
	if (bubBarFrameCounter < bubBarFrameLimit) {
		var obj = document.getElementById(currentBubble.id+"Restore");// currentBubble.id+"Restore"
		setRestoreValues(obj);// record this before a deflate occurs (should already be there tho '
		
//		if (restoreStoreObj != null) {
			// record the value for bubPos.ltwhz
//			var str = currentBubble.offsetLeft+','+currentBubble.offsetTop+','+currentBubble.offsetWidth+','+currentBubble.offsetHeight+','+currentBubble.style.zIndex; 
//			restoreStoreObj.value = str;
//		}
		
		setBubblePosition(1);
		var n = ( 1- (bubBarFrameCounter / bubBarFrameLimit ))*100;
		setBubbleOpacity(n);
		bubBarFrameCounter++;
	} else {
		setBubblePosition(2);
		addToBubbleBar();
		window.clearInterval(bubBarAnimTimeoutObj);
		bubBarFrameCounter = 1;
		var id = currentBubble.id;
		// this is a hack
		var str = id.substr(0,id.length-3); // as in take 'Div'
	//	bubCollapse(id,str+'WinCollapseImg');
		// record Bubble Position
		recordBubPosition(currentBubble);
		
	}
}
function reflateStep() {
	// Reflate repeat function
	if (bubBarFrameCounter < bubBarFrameLimit) {
		setBubblePosition(1);
		var n = (bubBarFrameLimit / bubBarFrameCounter)*100;
		setBubbleOpacity(n);
		bubBarFrameCounter++;
	} else {
		setBubblePosition(0);
		window.clearInterval(bubBarAnimTimeoutObj);
		bubBarFrameCounter = 1;
	
//		var id = currentBubble.id;
		// this is a hack
//		var str = id.substr(0,id.length-3); // as in take 'Div'
//		bubCollapse(id,str+'WinCollapseImg');
		// record Bubble Position
		recordBubPosition(currentBubble);
		
	}
}
function setBubbleOpacity(n) {

	 currentBubble.style.opacity = (n / 100);
	
}
function setBubblePosition(n) {
	switch(n) {
		case 0:
			// start
	currentBubble.style.left=bubRestoreTarget[0]+'px';
	currentBubble.style.top=bubRestoreTarget[1]+'px';
	currentBubble.style.width=bubRestoreTarget[2]+'px';
	currentBubble.style.height=bubRestoreTarget[3]+'px';
	currentBubble.style.zIndex=bubRestoreTarget[4];	
//	monitorRestoreTarget();
		break;
		case 1:
			// in progress
	currentBubble.style.left=(currentBubblePos[0]-currDeflIncr[0])+'px';
	currentBubble.style.top=(currentBubblePos[1]+currDeflIncr[1])+'px';
	currentBubble.style.width=(currentBubblePos[2]-currDeflIncr[2])+'px';
	currentBubble.style.height=(currentBubblePos[3]-currDeflIncr[3])+'px';
//	monitorPlacement();
	currentBubblePos = Array(currentBubble.offsetLeft, currentBubble.offsetTop, currentBubble.offsetWidth, currentBubble.offsetHeight);
	//monitorPosition(currentBubble);
		break;
		case 2:
			// final
	currentBubble.style.left=bubBarTarget[0]+'px';
	currentBubble.style.top=bubBarTarget[1]+'px';
	currentBubble.style.width=bubBarTarget[2]+'px';
	currentBubble.style.height=bubBarTarget[3]+'px';
	currentBubble.style.zIndex=bubBarTarget[4];	
		break;
	}
}
function monitorRestoreTarget() {
	var str = "rest: L: "+bubRestoreTarget[0]+'px';
	str += ", T: "+bubRestoreTarget[1]+'px';
	str += ", W: "+bubRestoreTarget[2]+'px';
	str += ", H: "+bubRestoreTarget[3]+'px';
	str += ", Z: "+bubRestoreTarget[4]+'px';
	trace(str);
}
function monitorIncrements() {
	var str = "inc: L: "+currDeflIncr[0];
	str += ", T: "+currDeflIncr[1];
	str += ", W: "+currDeflIncr[2];
	str += ", H: "+currDeflIncr[3];
	trace(str);
}
function monitorPlacement() {
	var str = "place: L: "+(currentBubblePos[0]-currDeflIncr[0])+'px';
			str += ", T: "+(currentBubblePos[1]+currDeflIncr[1])+'px';
			str += ", W: "+(currentBubblePos[2]-currDeflIncr[2])+'px';
			str += ", H: "+(currentBubblePos[3]-currDeflIncr[3])+'px';
	trace(str);
}
function monitorPosition(obj) {
	var str = 'pos: L: '+obj.offsetLeft+', T: '+obj.offsetTop+', W: '+obj.offsetWidth+', H: '+obj.offsetHeight;
	trace(str);
}
function getTargetDeflateCoords() {
	// look up the next 'slot' in the bubbleBar
	// x leftOffset, bottomOffset, z index (x is the important one)
	var n = bubbleBarContentsArray.length;
//	trace('n: '+n);
	var bubBar = document.getElementById('bubbleBarContainerBox');
	if (bubBar != null) {
		bubBarTarget = Array(n*160,bubBar.offsetTop-20,160,45,100);  // left, top, width, height, zIndex
	} else {
		trace('no bubble bar !');	
	}
}
function getTargetReflateCoords() {
	var restoreStoreObj = document.getElementById(currentBubble.id+"Restore");
	if (restoreStoreObj != null) {
		var str = restoreStoreObj.value;
//		trace('rest: '+str);
		bubRestoreTarget = str.split(',');
	} else {
		trace('not found: '+currentBubble.id+"Restore");	
	}
}
function addToBubbleBar() {
	bubbleBarContentsArray.push(currentBubble.id);
}
function addToDock(obj) {
	if (obj != null) {
		isDockedArray.push(obj.id);
		obj.style.bottom="0px";
		obj.style.top="auto";
	}
}
function inBubbleBar(id) {
	for (var i=0; i<bubbleBarContentsArray.length; i++) {
		if (bubbleBarContentsArray[i]==id) {
			return true;
		}
	}
	return false;
}
function isInDock(id) {
	for (var i=0; i<isDockedArray.length; i++) {
		if (isDockedArray[i]==id) {
			return true;
		}
	}
	return false;
}
function dragDivA5(obj,e) {
	// drag a bubble around
	//trace('dragDiv');
	if (obj != null) {
		switch(e) {
			case "start":
				animatePageActiveA5=true;
				currentDragDiv=obj;
			//	trace(currentDragDiv.id);
	//			removeFromDock(currentDragDiv);
				bringBubToFront(currentDragDiv.id);
				currentDragDiv.style.position="absolute";
				dragDivStartPositionX = parseInt(currentDragDiv.style.left);
				dragDivStartPositionY = parseInt(currentDragDiv.style.top);		
				offsetX = tempX-dragDivStartPositionX;
				offsetY = tempY-dragDivStartPositionY;
				removeFromBubbleBar(obj);
			break;
			case "stop":
				animatePageActiveA5=false;
				currentDragDiv=obj;
				recordBubPosition(obj);
			//	var str = currentDragDiv.style.top;
			//	str=parseInt(str.substr(0,str.length-2));
			//	str = currentDragDiv.offsetTop;
			//	str=tempY-offsetY;
				if ((tempY-currentDragDiv.offsetTop) > -220) {
					// magnetic attract to the dock.
	//				currentDragDiv.style.top=null;
//					addToDock(currentDragDiv);
				}
				setRestoreValues(obj);
				currentDragDiv=null;
			break;
		}
	}
}

function resizeBubDiv(obj,e,cont) {
	//trace('obj: '+obj+', e: '+e+', cont: '+cont);
	if (obj != null) {
		switch(e) {
			case "start":
				var anch=document.getElementById(targetDivA5);
			// right of the div x coord
				var divRightX = obj.offsetWidth + obj.offsetLeft;
//				trace('divRightX: '+divRightX);
//				trace('anch.offsetLeft: '+anch.offsetLeft);
			// bottom of the div y coord
				var divBotY = obj.offsetHeight + obj.offsetTop;
				clickOffsetWidth = (divRightX-tempX+anch.offsetLeft);
				clickOffsetHeight = (divBotY-tempY);
				resizeDivActive=true;
				currentResizeDiv=obj;
				currentResizeContent=cont;
				bringBubToFront(currentResizeDiv.id);
				var handle = document.getElementById(obj.id+"ResizeHandle");
				if (handle != null) {
	//				handle.style.border="1px Solid Red";
				}
				// BottomRight
				/*
				var obj1 = document.getElementById(obj.id+'BottomRight');
				if (obj1 !=null) {
					obj1.style.width='100%';
					obj1.style.height='100%';
				} */
			//	animatePageActiveA5=true;
			break;
			case "stop":
				currentResizeDiv=obj;
			/*	for(var i=0; i<bubDivIdArray.length;i++) {
				if (bubDivIdArray[i]==currentResizeDiv.id) {
				bubDivMaxHeightArray[i]=currentResizeDiv.offsetHeight;
				}
				}*/
				setRestoreValues(obj);
				resizeDivActive=false;
				currentResizeDiv=null;
				currentResizeContent=null;
				recordBubPosition(obj);
				var heightStoreObj = document.getElementById(obj.id+"Height");
				if (heightStoreObj != null && obj.offsetHeight > collapseTrigger) {
					heightStoreObj.value = obj.offsetHeight;
				} else {
					trace('height not saved: '+obj.id+"Height");	
				}
				var widthStoreObj = document.getElementById(obj.id+"Width");
				if (widthStoreObj != null) {
					widthStoreObj.value = obj.offsetWidth;
		//			trace('width: '+widthStoreObj.value);
				} else {
					trace('width not saved: '+obj.id+"Width");	
				}
				
				var handle = document.getElementById(obj.id+"ResizeHandle");
				if (handle != null) {
//					handle.style.border="none";
				}/*
				var obj1 = document.getElementById(obj.id+'BottomRight');
				if (obj1 !=null) {
					obj1.style.width='120px';
					obj1.style.height='32px';
				} */
			//	animatePageActiveA5=false;
				
			break;
		}
	} else {
		trace('currentResizeDiv / currentResizeDiv not found!');
	}
}
function setRestoreValues(obj) {
	var restoreStoreObj = document.getElementById(obj.id+"Restore");// currentBubble.id+"Restore"
	if ( restoreStoreObj != null && !inBubbleBar(obj.id) ) {
		// record the value for bubPos.ltwhz
		var str = obj.offsetLeft+','+obj.offsetTop+','+obj.offsetWidth+','+obj.offsetHeight+','+obj.style.zIndex; 
		restoreStoreObj.value = str;
	}
}
function stopResize() {
	/*
			check that the mouse is up - if it is ok otherwise keep the resize going.
	*/
	if (!mouseIsDown) {
		resizeDivActive=false;
	//	setRestoreValues(obj);
		currentResizeDiv=null;
		
		recordBubPosition();
	}
}

function getMouseXYA5(e) {
	if (IE) { 
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	} else { 
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0}  
	
	if (animatePageActiveA5) {
		animateA5Page();
	}
	if (resizeDivActive) {
		animateA5Page();
	}
	return true
}

var clickOffsetWidth = 0;
var clickOffsetHeight =0;

function animateA5Page() {
	if (!noAnimation && (currentDragDiv!=null || currentResizeDiv!=null)) {
		if (animatePageActiveA5) {
			
			if (!resizeDivActive) {
				
				if (isNaN(tempY-offsetY)) {
					//offsetY=tempY*1.47;
					//offsetY=tempY+200;
					if (currentDragDiv) {
						var divHeight = currentDragDiv.offsetHeight;
					//	divHeight=parseInt(divHeight.substr(0,divHeight.length-2));
						offsetY=tempY+divHeight+20;
					} else {
						trace('no currentDragDiv');
					}
				}
				if (isNaN(tempX-offsetX)) {
					//offsetX=tempX*1.47;
					offsetX=100;
				}
				if (tempX-offsetX) {
					currentDragDiv.style.left = (tempX-offsetX)+'px';
		//			trace(currentDragDiv.style.left);
				}
				if (tempY-offsetY) {
					currentDragDiv.style.top = (tempY-offsetY)+'px';
				}
				var str = ""; //(tempX-offsetX) + ' ' + (tempY-offsetY);
				//populate('content01',str);
				for (var i=0; i<isDockedArray.length; i++) {
					str += "<li>"+isDockedArray[i]+"</li>";
					
				}
				str="<ul>"+str+"</ul>";
			//	populate('content01',str);
			}
			
		}
		if (resizeDivActive) {
			var anch=document.getElementById(targetDivA5);
			var anchorLeft=anch.offsetLeft;//+containerLeftSpace;
			var anchorTop=anch.offsetTop;
			var farInWidth=currentResizeDiv.offsetwidth+currentResizeDiv.offsetLeft-tempX;
			var farInHeight=currentResizeDiv.offsetHeight+currentResizeDiv.offsetTop-tempY;
			var newWidth=tempX-currentResizeDiv.offsetLeft-anchorLeft;
			var newHeight=tempY-currentResizeDiv.offsetTop-anchorTop;
			var changeWidth=newWidth-currentResizeDiv.offsetWidth;
			var changeHeight=newHeight-currentResizeDiv.offsetHeight;

			// so the 'padding'  is:
			newWidth += clickOffsetWidth;
			newHeight += clickOffsetHeight;
			// now resize the contents & scrolll bar
			if (currentResizeContent) {

				if (newWidth < 200) { newWidth=200; }
				if (newHeight < 250) { newHeight=250; }
				
				var str = currentResizeDiv.id;
				var contentID = str.substr(0,str.length-3);
				var contentObject = document.getElementById(contentID); 
				if (contentObject != null) {
					contentObject.style.width = newWidth-54 + 'px';
					contentObject.style.height = newHeight-64 + 'px';
					positionDragHandle();
				}
				
				if (newWidth < 1300) {
					currentResizeDiv.style.width=newWidth+'px';
				} else {
					currentResizeDiv.style.width='1300px';
				}
				if (!isInDock(currentResizeDiv.id)){
					if (newHeight < 700) {
						currentResizeDiv.style.height=newHeight+'px';
					} else {
						currentResizeDiv.style.height='700px';
					}
				}
				
				
			}
		}
	}
}

function bubOpenClose(id,com) {
//	trace('bubOpenClose: id: '+id);
	if (!id) {
		return;
	}
	var obj = document.getElementById(id);
	if (obj != null) {
		
//		trace('found: '+id + ' is in dock: '+isInDock(id));
		bringBubToFront(id);
		
		if (isInDock(id)) {
			// run through the bubDivIdArray hiding all others
			for (var i=0; i<bubDivIdArray.length; i++) {
		//		trace(bubDivIdArray[i]);
				if (isInDock(bubDivIdArray[i])) {
					var eachObj = document.getElementById(bubDivIdArray[i]);
					if (eachObj != null && id != bubDivIdArray[i]) {
						eachObj=eachObj.style;
						eachObj.display='none';
						eachObj.height='0px';
					}	
				}
			}
			currentBublicationDivId=id;
			
			obj=obj.style;
			if (obj.display != 'block') {
				animateBublicationDivOpening=true;
				animateBublicationDiv();
				obj.display='block';
			} else {
				animateBublicationDivOpening=false;
				animateBublicationDiv();
			}
			
			if (!com) return;
			
			switch(com) {
				case "showBasket":
					viewBasket(); // see shop.js
				break;
				case "showOrders":
					viewOrders();// see shop.js
				break;
				case "showProfile":
					getInterface(profileDisplayPath,'profile');
				break;
				case "showMessages":
					getInterface(msgFormPath,'messages');
					setMsgCheckCycle();
					//msgCheckCommand;
				break;
				case "showRelationships":
				
				break;
				case "showMediaPlayer":
				
				break;
				case "showMediaLibrary":
					getInterface(mediaLibraryPath,'mediaLibrary');
				break;
				case "showFavorites":
				
				break;
			}
			
		} else {
			// not in dock
			obj.style.top=null;
			addToDock(obj);
			bubOpenClose(obj.id,'');
	//		trace('not in dock: '+id);
		}
	} else {
//		trace('not found id: ' + id);
		return;
	}
}

/*
		Many thanks to Quirksmode for the following excellent Browser Detect tool
		www.quirksmode.org

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.bubVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.vendor,
			subString: "Buble",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{	// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 	// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};*/
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

BrowserDetect.init();
browserVersion=BrowserDetect.version;
operatingSystem=BrowserDetect.OS;	
browser=BrowserDetect.browser;
if (browser=="Explorer") { IE=true;  }  //alert(browser);