// -----------------------------------------------------------------------------
// getDocObj
// 
// A basic document object constructor - taken from JavaScript + CSS + DOM Magic
// 
// Usage: variablename = eval(getDocObj(elementidvalue));
// -----------------------------------------------------------------------------
function getDocObj(elem,parent) {
	if (document.layers) {
	    if (parent) {
	     return "document."+parent+".document."+elem;
	      }
	    else {
		return "document."+elem;
		     }
		
	  } 
	    else if (document.all) {
		return "document.all."+elem;
	} 
	    else if (document.getElementById) {
		return "document.getElementById('"+elem+"')";
	}
}




// -----------------------------------------------------------------------------
// getStyleObj
// 
// A basic document style object constructor - taken from 
// JavaScript + CSS + DOM Magic
// 
// Usage: variablename = eval(getStyleObj(elementidvalue));
// -----------------------------------------------------------------------------
function getStyleObj(elem,parent) {
	if (document.layers) {
	    if (parent) {
	     return "document."+parent+".document."+elem;
	      }
	    else {
		return "document."+elem + ".style";
		     }
		
	  } 
	    else if (document.all) {
		return "document.all."+elem + ".style";
	  } 
	    else if (document.getElementById) {
		return "document.getElementById('"+elem+"').style";
		
	}
}





// -----------------------------------------------------------------------------
// adjustPositions(columnName)
//
// Determine the coords of the top of item then go through the
// array and set the location of each item based on the longTextVisible
// values of the preceding items
//
// note: for this function to work correctly there must be a global array 
// 		 with the same name as columnName that contains the names of all 
// 		 the other containers
//		 
//		 The names of the items are very important if the column name is 
//		 'events' the item names will be 'event1fullText' 'event1date' etc
//		 if this naming convention is not followed everything breaks
// 		 (nice and flexible huh =))
//
//
// AS OF v2.5 of embeddedNewsAndArticlesDynamic.php this function is no longer
//		needed. Its being kept around for reference right now but will probably
//		be deleted shortly
//
// 2004.03.05 - modifying this to just postion the info boxes. This is now
// 				complicated by the text boxes being positioned relative. That
//				means that the top left coords of each box is (0,0) even though
//				the second box is say, 20px below the first, etc. So to 
//				accurately position the info boxes we must keep track of the 
//				heights of the text boxes together and use that value to
//				position the info boxes. 
//
//				NOTE: This is designed to work with v2.5 or later of the 
//						embeddedNewsAndArticlesDynamic.php script.
// -----------------------------------------------------------------------------
function adjustPositions(columnName)
{
	var xOffset = 25;
	var yOffset = 15;
	

	// the DIV container for the text box items
	var columnDivName = columnName;

	
	// make the columnName into a variable that points
	// to the global variable with the name contained in columnName
	// i.e. if columnName contains the text 'events' the variable columnName will 
	// actually get a copy of the global variable named 'events'
	var columnItemsArray = eval(columnName);
	
	
	// if there are no items in the array we should exit here
	if(columnItemsArray.length == 0)
		return 1;
	
		
	// y will be used to keep track of the bottom of the list
	var y = 0;


	// for each item place and adjust its info box properly
	// ----------------------------------------------------
	for(var count = 0; count < columnItemsArray.length; count++)
	{		
		// place the info box at the specified offset from the top left
		// corner of the current item.
		placeIt(columnItemsArray[count] + 'infoBox',xOffset, (y + yOffset));

		
		// sum up the height of all this item's visible sub-containers
		// -----------------------------------------------------------
		alwaysVisibleArray = eval(columnName + 'ColumnAlwaysVisible');
		
		for(var i = 0; i < alwaysVisibleArray.length; i++)
		{
			// get the docObj for the current subcontainer
			var alwaysVisibleDocObj = eval(getDocObj(columnItemsArray[count] + alwaysVisibleArray[i]));	
		
		
			// determine what height var is used by the browser and get it
			// -----------------------------------------------------------
			if (alwaysVisibleDocObj.height)
				var height = alwaysVisibleDocObj.height;
		
			else if (alwaysVisibleDocObj.offsetHeight)
				var height = alwaysVisibleDocObj.offsetHeight;
			
			else
				var height = 0;
			
			// update y to refelect the location of the bottom of this item
			y = y + height;
		}
	}
}



// -----------------------------------------------------------------------------
// findTopLeftCoords(elem)
//
// return an array containing x,y - the coords of the top left corner of the 
// specified object (elem)
// -----------------------------------------------------------------------------
function findTopLeftCoords(elem)
{
	styleObj = eval(getStyleObj(elem));
	docObj= eval(getDocObj(elem));



	// figure out the element's location on the screen
	// -----------------------------------------------
	if (document.all) 
	{
		var x = styleObj.pixelLeft;
		var y = styleObj.pixelTop;
	}
	
	else 
	{
		var x = styleObj.left;
		var y = styleObj.top;


		// if a browser (like Safari) does somthing lame like add 'px' to the 
		// end of the coord remove it
		// ------------------------------------------------------------------
		var reg = new RegExp("px", "gi");			
		
		x = x.replace(reg, '');
		y = y.replace(reg, '');

		// if a browser (like mozilla) does somthing lame like add 'pt' to the 
		// end of the coord remove it
		// ------------------------------------------------------------------
		var reg2 = new RegExp("pt", "gi");			
		
		x = x.replace(reg2, '');
		y = y.replace(reg2, '');


	}


	// if we are unable to determine the coords of the element - assume they're 0,0
	if( x == '')
		x = 0;
	if( y == '')
		y = 0;
	

	
	// make the array
	var coord = new Array();
	coord.x = new Number(x);
	coord.y = new Number(y);
	
	return coord;
}





// -----------------------------------------------------------------------------
// showInfoBox(columnName,itemNumber)
// 
// pop up a little info box for the current item
// -----------------------------------------------------------------------------
function showInfoBox(columnName,itemNumber) 
{
	hideInfoBoxes(columnName);
	
	// make the columnName into a variable that points
	// to the global variable with the name contained in columnName
	// i.e. if columnName contains the text 'events' the variable columnName will actuall
	// get a copy of the global variable named 'events'	
	columnItemsArray = eval(columnName);
				
			
	// show infoBox		
	var infoBoxStyleObj = eval(getStyleObj(columnItemsArray[itemNumber] + 'infoBox'));
	
	infoBoxStyleObj.visibility = "visible";

}





// -----------------------------------------------------------------------------
// hideInfoBoxs(columnName)
// 
// hides all the info boxes for a given column (called at the beginning of
// showInfoBox() and when nessecary to clean up the column).
// -----------------------------------------------------------------------------
function hideInfoBoxes(columnName)
{
	// get a copy of the global variable named 'events'
	var columnItemsArray = eval(columnName);
	
	
	// if there are no items in the array we should exit here
	if(columnItemsArray.length == 0)
		return 1;

	// for each item place and adjust its sub-containers properly
	// ----------------------------------------------------------
	for(var count = 0; count < columnItemsArray.length; count++)
	{		
		// hide the infoBox		
		var infoBoxStyleObjName = getStyleObj(columnItemsArray[count] + 'infoBox');
		var infoBoxStyleObj = eval(infoBoxStyleObjName);
		infoBoxStyleObj.visibility = "hidden";
	}	
		
}


// -----------------------------------------------------------------------------
// placeIt(elem, leftPos, topPos)
// 
// a simple function taken from JavaScript + CSS + DOM Magic that places an 
// object somewhere on the screen
//
// leftPos and topPos are the coords of the top left corner of the item
// -----------------------------------------------------------------------------
function placeIt(elem,leftPos,topPos) 
{
//alert("placing " + elem + " at " + leftPos + ", " + topPos);
	styleObj = eval(getStyleObj(elem));
	
	if (document.all) 
	{
		styleObj.pixelLeft = leftPos;
		styleObj.pixelTop = topPos;
	}
	
	else 
	{
		styleObj.left = leftPos;
		styleObj.top= topPos;
	}
}

