
var IE6, IE5_6, IE5_5, IE5, N4, N5, NS6, NS6_1, NS7, MOZ, MAC_IE5, OPERA, OMNI, MAC, WIN;
var determineUserAgent_called = false;

function determineUserAgent() {
	var ua= navigator.userAgent;
	OPERA= (ua.indexOf("Opera") > 0);
	OMNI= (ua.indexOf("Omni") > 0);
	MAC= (navigator.platform.indexOf("PPC") > 0);
	WIN= (navigator.platform=="Win32");


	if (!OPERA && !OMNI) {
		
		IE6= (ua.indexOf("MSIE 6") > 0);
		
		// IE 5.5 and IE 5.6 are similar. IE 5.6 is released on WindowsXP
		IE5_6= (ua.indexOf("MSIE 5.6") > 0);
		IE5_5= (ua.indexOf("MSIE 5.5") > 0 || IE5_6);
		
		// IE5 is true for IE5.5, IE5.6, and IE6.
		IE5= (ua.indexOf("MSIE 5") > 0  || IE6);
		
		N4= (document.layers);
		NS6= N5= (ua.indexOf("Gecko") > 0);
		NS6_1 = (N5 && ua.indexOf("6.1") != -1);
		NS7 = (N5 && ua.indexOf("7.0") != -1);
		MOZ= N5 && !(ua.indexOf("Netscape") > 0);
		MAC_IE5= (MAC && IE5);
	}
	
	determineUserAgent_called = true;
}

function getIE5() {
	if (!determineUserAgent_called)
		determineUserAgent();
	return IE5;
}
function getIE6() {
	if (!determineUserAgent_called)
		determineUserAgent();
	return IE6;
}
function getNS() {
	if (!determineUserAgent_called)
		determineUserAgent();
	return(NS6 || NS6_1|| NS7);
}

/*+++++ AUTO MAXIMIZE +++++*/
function maximize_window() {
	top.window.moveTo(0,0);
	if (document.all) {
		top.window.resizeTo(screen.availWidth,screen.availHeight);
		alert(screen.availWidth + 'x' + screen.availHeight);
	} else if (document.layers||document.getElementById) {
		if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth) {
			top.window.outerHeight = screen.availHeight;
			top.window.outerWidth = screen.availWidth;
			alert(screen.availWidth + 'x' + screen.availHeight);
		}
	}

}
/*----- AUTO MAXIMIZE -----*/

/*+++++ placeObject +++++*/
// Object1 is the actual object to place
// invoker is the object to place beside
// pos is where to place relative to invoker.
//			left, right, top, bottom
//
// align is the direction in wich the object vill be displayed, relative to invoker:
//			left, right, up, down
//				
function placeObject(object1, invoker, pos, align) {
	var t_coords = {x: 0, y: 0};
	
	var inv = getAbsCoords(invoker);
	
	if ( pos == 'left' ) {
		t_coords.x = inv.x - object1.offsetWidth ;
	}if ( pos == 'right' ) {
		t_coords.x = inv.x +inv.w + 5;
	} else if ( pos == 'top' ) {
		t_coords.y = inv.y - object1.offsetHeight;
	}if ( pos == 'bottom' ) {
		t_coords.y = inv.y + inv.h;
	}

	var margin = 2;

	if ( align == 'up') {
		t_coords.y = inv.y + inv.h - object1.offsetHeight - margin;
	} else if ( align == 'down') {
		t_coords.y = inv.y + margin;
	} else if ( align == 'left') {
		t_coords.x = inv.x + inv.w- object1.offsetWidth - margin;
	} else if ( align == 'right') {
		t_coords.x = inv.x + margin;
	}
	object1.style.position = 'absolute';
	object1.style.left  = t_coords.x;
	object1.style.top = t_coords.y ;
}

/*
 * Returns an coords object containing coords of the supplied object.
 * coords has the following properties
 * x  - the left most coord of the object
 * x2 - the right most coord of the object
 * y  - the top most coord of the object
 * y2 - the top most coord of the object
 * w  - the width of the object
 * h  - the height of the object.
 */ 
function getAbsCoords (element) {
	var coords = {x: 0, y: 0, h: 0, w: 0, x2: 0, y2: 0};
	coords.w = element.offsetWidth;
	coords.h = element.offsetHeight;
	do {
		coords.x += element.offsetLeft;
		coords.y += element.offsetTop;
	}
	while ((element = element.offsetParent));
	
	coords.x2 = coords.x + coords.w;
	coords.y2 = coords.y + coords.h;
	
	return coords;
} 

/*
 * Returns true if the frontItem (first param) is placed on top of backItem (the second parm).
 * NOTE : the objects doesnt have to be vissible, but the display style muste be set (ex : 'backItem.sytle.display = "block"' )
 */
function checkOverlap( frontItem, backItem) {
	if ( frontItem && backItem ) {
		frontPos = getAbsCoords(frontItem);
		backPos = getAbsCoords(backItem);
		
		if (( backPos.x2 ) <= frontPos.x );
		else if (( backPos.y2 ) <= frontPos.y );
		else if ( backPos.y >= ( frontPos.y2 )) ;
		else if ( backPos.x >= ( frontPos.x2 )) ;
		else {					
			return true;
		}
	}
	
	return false;
}

/*
 * Vector class.
 * Methods :
 * addElement( theElement ) - Adds an element
 * removeElement( theElement ) - Removes an element
 * getElementAt( pos ) - Returns an element at the specified pos
 * removeElementAt( pos ) - Removes an Element at the specified ps.
 * contains( theElement ) - Return true if the specified element is contained.
 * size( ) - Returns the size.
 */
function Vector () {
	array = new Array();

	function addElement( elm ) {		
		for ( i=0 ; i<array.length ;i++ ) {
			
			if ( array[i] == elm ) {
				return;
			}
		}
		
		array[array.length] = elm;
	}
	
	function getElementAt( pos ) {
		if (array.length > pos)
			return array[pos];
		
		return null;
	}
	
	function removeElement( elm ) {
		for ( i=0 ; i<array.length ;i++ ) {
			
			if ( array[i] == elm ) {
				if ( IE5_5 || IE6 || NS7) {
					array.splice(i,1);	
				} else {
					old = array;
					array = new Array();
					found = 0;
					for ( j=0 ; j < old.length -1 ; j++) {
						if ( j != i ) {
							array[j] = old[j+found];
						} else {
							found = 1;
						}					
					}					
				}			
				return;
			}
		}
		alert ('not removed');
	}
	
	function removeElementAt( pos ) {
		
		if (array.length > pos)
			array.slice(pos, pos);			
	}
	
	function contains ( elm ) {
		for ( i=0 ; i<array.length ;i++ ) {
			
			if ( array[i] == elm ) {
				return true;				
			}
		}
		
		return false;
	}
	
	function size() {
		return array.length;
	}
	
	this.removeElement = removeElement; 
 	this.removeElementAt = removeElementAt; 
 	this.getElementAt = getElementAt; 
 	this.addElement = addElement; 
 	this.size = size; 
 	this.contains = contains;
}

