
/* Modifed by MJ to namespace the functions */

/*

DISCLAIMER: THESE JAVASCRIPT FUNCTIONS ARE SUPPLIED 'AS IS', WITH 
NO WARRANTY EXPRESSED OR IMPLIED. YOU USE THEM AT YOUR OWN RISK. 
NEITHER PAUL STEPHENS NOR PC PLUS MAGAZINE ACCEPTS ANY LIABILITY FOR 
ANY LOSS OR DAMAGE RESULTING FROM THEIR USE, HOWEVER CAUSED. 

Paul Stephens' NetScape-based cookie-handling library

http://web.ukonline.co.uk/paul.stephens/index.htm

TO USE THIS LIBRARY, INSERT ITS CONTENTS IN A <script></script> BLOCK IN THE 
<HEAD> SECTION OF YOUR WEB PAGE SOURCE, BEFORE ANY OTHER JAVASCRIPT ROUTINES.

Feel free to use this code, but please leave this comment block in.

*/


 
/*
toggleChoose function
This is for showing and hiding the choose community 'dropdown'.
This toggles the panel (slides up and down) from the tab button.
*/

function toggleChoose(thisID) {
	if ($(thisID).style.display != 'none') {
		Effect.toggle($(thisID), 'slide', {duration: .4});
	} else {
		Effect.toggle($(thisID), 'slide', {duration: .4});
	}
}



function zeusportalToggleTab(thisPanel, otherPanels) {
    var thisPanelElem = $(thisPanel);
    // load the tabs for the panel elements
    if (thisPanelElem) {
        var thisTabElem = $(thisPanelElem.id+"-tab");
    }

    // toggle the tab styles and the panel visibility
    if (thisPanelElem && thisPanelElem.style.display == 'none') {
		if (thisTabElem) {
            thisTabElem.className = "zeusportal-body-tab zeusportal-body-tabcurrent";
            thisPanelElem.style.display = "block";
        }
        for (var i = 0; i < otherPanels.length; i++) {
            var thatPanelElem = $(otherPanels[i]);
            if (thatPanelElem) {
                var thatTabElem = $(thatPanelElem.id+"-tab");
            }
            if (thatTabElem) {
                thatTabElem.className = "zeusportal-body-tab";
                thatPanelElem.style.display = "none";
            }
        }
    }
}



/*
zeusportaltoggleLogin function
This is for showing and hiding the choose user login form.
*/

function zeusportaltoggleLogin() {

	Element.toggle('zeusportalLoginWelcome');
	Element.toggle('zeusportalLoginForm');

	if ($('zeusportalLoginForm').style.display != 'none' && $('login-username') != null) {
        $('login-username').focus();
	} else if($('login-username') != null) {
        $('login-username').blur();
	}
}



// the timeout variable that will be used to close menu bar
var zeusportalMenuTimeout;
var zeusportalMenuIndex = -1;
var zeusportalMenuID;

function zeusportalKeypressMenuHandler (event) {
    if (Element.visible(zeusportalMenuID)) {
        var key = event.which || event.keyCode;
        switch (key) {
            case Event.KEY_DOWN:
                var links = $(zeusportalMenuID).getElementsByTagName('li');
                if (zeusportalMenuIndex > -1 && zeusportalMenuIndex < (links.length - 1)) {
                    links[zeusportalMenuIndex].className = 'zeusportal-userbar-menu-nohover';
                }

                if (zeusportalMenuIndex < (links.length - 1)) {
                    zeusportalMenuIndex++;
                    links[zeusportalMenuIndex].className = 'zeusportal-userbar-menu-hover';
                }

                break;
            case Event.KEY_UP:
                var links = $(zeusportalMenuID).getElementsByTagName('li');
                if (zeusportalMenuIndex > 0) {
                    links[zeusportalMenuIndex].className = 'zeusportal-userbar-menu-nohover';
                }

                if (zeusportalMenuIndex > 0) {
                    zeusportalMenuIndex--;
                    links[zeusportalMenuIndex].className = 'zeusportal-userbar-menu-hover';
                }

                break;
            case Event.KEY_RETURN:
                listElements = $(zeusportalMenuID).getElementsByTagName('li');
                listElement = listElements[zeusportalMenuIndex];
                link = listElement.getElementsByTagName("a");
                if (link.length > 0) {
                    document.location.href = link[0].href;
                }
                break;
        }
        Event.stop(event);
    }
}


/*
zeusportaltoggleMenu function
This is for showing and hiding the choose user menu 'dropdowns'.
This toggles the panel (slides up and down) from the button.
*/
function zeusportaltoggleMenu(zeusportalMenu) {
    clearTimeout(zeusportalMenuTimeout);

    var open = $(zeusportalMenu).style.display != 'none';
    if (!open) {
        zeusportalCloseAllMenus();
        Element.toggle($(zeusportalMenu));
        $(zeusportalMenu + "Link").className = "zeusportal-userbar-droplink-on";
        zeusportalMenuID = zeusportalMenu;
        Event.observe(document, 'keypress', zeusportalKeypressMenuHandler, true);
    }
}





/*
zeusportalSwapMenu function
This is for showing and hiding the choose user menu 'dropdowns'.
This toggles the panel (slides up and down) from the button.
*/
function zeusportalSwapMenu(zeusportalMenu) {
    clearTimeout(zeusportalMenuTimeout);
    
    var openMenu = null;
    var menus = document.getElementsByClassName('zeusportal-userbar-menu');
    for (var i = 0; i < menus.length; i++) {
        if (menus[i].style.display != 'none') {
            openMenu = menus[i];
            break;
        }
    }
    if (openMenu != null) {
        if (openMenu.id != zeusportalMenu) {
            zeusportalCloseAllMenus();
            Element.toggle($(zeusportalMenu));
            $(zeusportalMenu + "Link").className = "zeusportal-userbar-droplink-on";
        }
    }
}

// cancels any timeout set to close a zeusportal menu bar
function zeusportalInsideMenu(evt) {
    clearTimeout(zeusportalMenuTimeout);
}

// sets a timeout that will close the zeusportal menu bar
function zeusportalOutsideMenu(evt) {
    try {
        var elem = evt.relatedTarget || evt.toElement;
        if (typeof(elem) != 'undefined') {
            while (elem.parentNode && (typeof(elem.tagName) == 'undefined' || elem.tagName.toUpperCase() != 'DIV')) {
                elem = elem.parentNode;
            }
        }
    
        if (typeof(elem) == 'undefined' || !elem.tagName || (!Element.hasClassName(elem, 'zeusportal-userbar-menu'))) {
            zeusportalMenuTimeout = setTimeout('zeusportalCloseAllMenus()', 1500);
        }
    }
    catch (e) {
        zeusportalMenuTimeout = setTimeout('zeusportalCloseAllMenus()', 1500);
    }
    
}

// dynamically loads the zeusportal menu positions
function zeusportalLoadMenus() {
    var menus = document.getElementsByClassName('zeusportal-userbar-menu');
	for (var i = 0; i < menus.length; i++) {
		var link = document.getElementById(menus[i].id + "Link");
		menus[i].style.left = zeusportalGetX(link) + "px"; 
		menus[i].style.top = (zeusportalGetY(link) + 34) + "px";
	}
}

// loops through all open menu bars and closes them
function zeusportalCloseAllMenus() {
    var menus = document.getElementsByClassName('zeusportal-userbar-menu');
	for (var i = 0; i < menus.length; i++) {
		if (menus[i].style.display != "none") {
			Element.toggle(menus[i]);
            $(menus[i].id + "Link").className = "";
            var links = menus[i].getElementsByTagName('li');
            for (var k = 0; k < links.length; k++) {
                links[k].className = 'zeusportal-userbar-menu-nohover';
            }
        }
	}
    Event.stopObserving(document, 'keypress', zeusportalKeypressMenuHandler, true);
    zeusportalMenuIndex = -1;
}

// get pixel position of an object
function zeusportalGetY(o){ var y = 0
	if (o.offsetParent) while (o.offsetParent) { y += o.offsetTop; o = o.offsetParent }
	return y
}
function zeusportalGetX(o){ var x = 0
	if (o.offsetParent) while (o.offsetParent) { x += o.offsetLeft; o = o.offsetParent }
	return x
}

// escape key and body click to close menu bars
if (document.layers) {
	document.captureEvents(Event.KEYDOWN);
}
function zeusportalEscapeKey(evt) {
	var keyCode = document.layers ?
		evt.which : document.all ? event.keyCode : document.getElementById ? evt.keyCode : 0;
	if (keyCode == 27) { // esc - close open menu
		zeusportalCloseAllMenus();
	}
}

function zeusportalBodyClick(evt) {
	evt = evt || window.event; // IE required window.event
	var elem = Event.findElement(evt, 'div');
    // check parent or parent's parent for class dhtmlTreeStyle for tree dropdown in menu
    var parentElem = Event.element(evt).parentNode;
	

	
    if (!elem || !elem.tagName || (elem.id != 'zeusportal-userbar-droplink' && !Element.hasClassName(elem, 'zeusportal-userbar-menu') && !Element.hasClassName(parentElem, "dhtmlTreeStyle") && !Element.hasClassName(parentElem.parentNode, "dhtmlTreeStyle"))) {
        zeusportalCloseAllMenus();
	}	
}


/*
zeusportalToggleOptions function
Function for toggling the state of an options element.
*/
function zeusportalToggleOptions(optionName) {
    if ($(optionName + '-form').style.display != 'none') {
        Element.hide(optionName + '-form');
        $(optionName + '-hdr').className = 'zeusportal-compose-hdr-opt-closed';
    } else {
        $(optionName + '-form').style.display = 'block';
        $(optionName + '-hdr').className = 'zeusportal-compose-hdr-opt';
    }
}

function zeusportalShowTopicFilter(thisID) {
	if ($(thisID).style.display != 'none') {
		Element.toggle($(thisID));
		//Effect.toggle($(thisID), 'slide', {duration: .4});
	} else {
		Element.toggle($(thisID));
		//Effect.toggle($(thisID), 'slide', {duration: .4});
	}
}

function zeusportalToggleSpaceDetails(thisID) {
    Element.toggle($(thisID));

    if ($(thisID).style.display != 'none') {
        $(thisID + '-less').style.display = '';
        $(thisID + '-more').style.display = 'none';
    } else {
        $(thisID + '-more').style.display = '';
        $(thisID + '-less').style.display = 'none'; 
    }
}

function zeusportalToggleSpaceDetails2(thisID) {
    if ($(thisID).className == 'zeusportal-space-namedesc-full') {
        $(thisID).className = '';
        $(thisID + '-more').style.display = '';
        $(thisID + '-less').style.display = 'none';
    } else {
        $(thisID).className = 'zeusportal-space-namedesc-full';
        $(thisID + '-less').style.display = '';
        $(thisID + '-more').style.display = 'none';
    }
}

function zeusportalHideProfile() {
    // hide any existing profile bubbles
    try {
		if ($('pcMain') && $('pcArrow')) {
			Element.remove($('pcMain'));
			Element.remove($('pcArrow'));
		}
	} catch(e) {
		//alert('hidePop error: '+ e + e.message + ' : ' + e.description);
	}
}

function zeusportalShowProfile(rootURL, profilelement, username) {
    zeusportalHideProfile()

    var formatPNGTag = function(properties) {
        var id = (properties.id) ? ' id="' + properties.id + '"' : '';
        if (document.all) {
            return '<img' + id + ' style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale src=\'' + properties.src + '\');" src="' + rootURL + 'images/zeusportal-pnghack.png" border="' + properties.border + '" width="' + properties.width + '" height="' + properties.height + '" />';
        } else {
            return '<img' + id + ' src="' + properties.src + '" border="' + properties.border + '" height="' + properties.height + '" width="' + properties.width + '" />';
        }
    }

    var elem = $(profilelement);
    iconId = elem.id;
    var top = Position.cumulativeOffset(elem)[1];
    var left = Position.cumulativeOffset(elem)[0];

    // alert(top + ' : ' + left)

    var poptop = 0
    var popleft = 0
    var arrowtop = 0
    var arrowleft = 0

    // 2ND ROW
    if (top < 540) {
        if (left < 400) {
            // DOWN RIGHT ARROW
            var arrowPNG = 'zeusportal-profile-bubble-bottom-right.png';
            offsetarrowtop = 3;
            offsetarrowleft = 5;
            if (left > 200) {
                // 2nd ROW
                offsetpoptop = -30;
                offsetpopleft = 45;

            } else {
                // DEFAULT
                offsetpoptop = -10;
                offsetpopleft = 115;
            }
        } else {
            // DOWN LEFT ARROW
            var arrowPNG = 'zeusportal-profile-bubble-bottom-left.png';
            offsetarrowtop = 3;
            offsetarrowleft = -100;
            if (left < 500) {
                // 3rd ROW
                offsetpoptop = -30;
                offsetpopleft = -450;
            } else {
                offsetpoptop = -10;
                offsetpopleft = -530;
            }
        }
    } else {
        // TOP > 540
        if (left < 400) {
            // UP RIGHT ARROW
            var arrowPNG = 'zeusportal-profile-bubble-top-right.png';
            offsetarrowtop = -210;
            offsetarrowleft = 5;
            if (left > 200) {
                // 2nd ROW
                offsetpoptop = -210;
                offsetpopleft = 45;

            } else {
                // DEFAULT
                offsetpoptop = -250;
                offsetpopleft = 115;
            }
        } else {
            // UP LEFT ARROW
            var arrowPNG = 'zeusportal-profile-bubble-top-left.png';
            offsetarrowtop = -210;
            offsetarrowleft = -100;
            if (left < 500) {
                // 3rd ROW
                offsetpoptop = -250;
                offsetpopleft = -450;
            } else {
                // DEFAULT
                offsetpoptop = -250;
                offsetpopleft = -530;
            }
        }
    }

    poptop = top + offsetpoptop;
    popleft = left + offsetpopleft;
    arrowtop = top + offsetarrowtop;
    arrowleft = left + offsetarrowleft;

    var popup = document.createElement('div');
    popup.setAttribute('id','pcMain');
    new Insertion.Top(popup, formatPNGTag({ width: 450, height: 21, border: 0, src: rootURL + 'images/zeusportal-profile-bubble-background-top.png' }) + '<br />');
    new Insertion.Bottom(popup, '<div class="zeusportal-profile-bubble" id="zeusportal-profile-bubble"><div class="pad"><div class="pc"><div id="pcContent"></div></div></div></div>');
    new Insertion.Bottom(popup, formatPNGTag({ width: 450, height: 21, border: 0, src: rootURL + 'images/zeusportal-profile-bubble-background-bottom.png' }));
    Element.setStyle(popup,{display: 'none', top: poptop + 'px', left: popleft + 'px' });

    var arrow = document.createElement('div');
    arrow.setAttribute('id','pcArrow');
    new Insertion.Top(arrow, formatPNGTag({ width: 121, height: 226, border: 0, src: rootURL + 'images/' + arrowPNG }) + '<br />');
    Element.setStyle(arrow,{display: 'none', top: arrowtop + 'px', left: arrowleft + 'px'});

    document.body.appendChild(popup);
    document.body.appendChild(arrow);

    Element.setStyle($('pcMain'),{display: 'block'});
    Element.setStyle($('pcArrow'),{display: 'block'});

    zeusportalGetUserContent(rootURL, username)
}

function zeusportalGetUserContent(rootURL, username) {
    try {
		$('pcContent').innerHTML = '<div class="loading"><img src="' + rootURL + 'images/loading.gif" alt="" /></div>';

		// NOW LOAD DATA VIA AJAX
		var callback = function(originalRequest) {
			$('pcContent').innerHTML = originalRequest.responseText;
		}
		var error = function(originalRequest) {
			$('pcContent').innerHTML = '<span class="error">Oops! There was an error getting this user\'s profile.</span>'
		}
		var url = rootURL + 'profile-short.jspa?username=' + username;
		var myAjax = new Ajax.Request( url, { method: 'get', onComplete: callback, onFailure: error});

    }catch(e) {
		alert(e.message)
	}
}


function callOnLoad(init) {
    if (window.addEventListener)
    {
        window.addEventListener("load", init, false);
    }
    else if (window.attachEvent)
    {
        window.attachEvent("onload", init);
    }
    else
    {
        window.onload = init;
    }
}

zeusportal = Class.create();
zeusportal.AlertMessage = function(element) {
    var options = arguments[1] || {} ;

    new Effect.Appear(element, {
        queue: 'front',
        scope: element,
        duration: 1,
        beforeStart:options.beforeStart,
        afterFinish:function(obj) {
            new Pause(1);
            new Effect.Fade(element, {
                queue: 'end',
                scope: obj,
                duration: 1,
                afterFinish:options.afterFinish
            });
        }
    });
};

function Pause(duration, busy){
  this.duration= duration * 1000;
  this.busywork = null; // function to call while waiting.
  this.runner = 0;

  if (arguments.length == 2) {
     this.busywork = busy;
  }

  this.pause(this.duration);

}

Pause.prototype.pause = function(duration){
  if ( (duration == null) || (duration < 0)) {return;}

  var later = (new Date()).getTime() + duration;

  while(true){
     if ((new Date()).getTime() > later) {
        break;
     }

     this.runner++;

     if (this.busywork != null) {
        this.busywork(this.runner);
     }

  } // while

} // pause method

/*
 * $Revision: 14166 $
 * $Date: 2005-02-07 15:57:29 -0800 (Mon, 07 Feb 2005) $
 *
 * Copyright (C) 1999-2007 zeusportal Software. All rights reserved.
 *
 * This software is the proprietary information of zeusportal Software. Use is subject to license terms.
 */


// -----------------------------------------------------------------------------------
//
//	Lightbox v2.03.3
//	by Lokesh Dhakar - http://www.huddletogether.com
//	5/21/06
//
//	For more information on this script, visit:
//	http://huddletogether.com/projects/lightbox2/
//
//	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
//	
//	Credit also due to those who have helped, inspired, and made their code available to the public.
//	Including: Scott Upton(uptonic.com), Peter-Paul Koch(quirksmode.com), Thomas Fuchs(mir.aculo.us), and others.
//
//
// -----------------------------------------------------------------------------------

//
//	Configuration
//
var fileLoadingImage = _zeusportal_base_url + '/images/zeusportal-image-loading.gif';
var fileBottomNavCloseImage = _zeusportal_base_url + '/images/zeusportal-image-close.gif';

var overlayOpacity = 0.8;	// controls transparency of shadow overlay

var animate = true;			// toggles resizing animations
var resizeSpeed = 7;		// controls the speed of the image resizing animations (1=slowest and 10=fastest)

var borderSize = 10;		//if you adjust the padding in the CSS, you will need to update this variable

// -----------------------------------------------------------------------------------

//
//	Global Variables
//
var imageArray = new Array;
var activeImage;

if(animate == true){
	overlayDuration = 0.2;	// shadow fade in/out duration
	if(resizeSpeed > 10){ resizeSpeed = 10;}
	if(resizeSpeed < 1){ resizeSpeed = 1;}
	resizeDuration = (11 - resizeSpeed) * 0.15;
} else { 
	overlayDuration = 0;
	resizeDuration = 0;
}

// -----------------------------------------------------------------------------------

//
//	Additional methods for Element added by SU, Couloir
//	- further additions by Lokesh Dhakar (huddletogether.com)
//
Object.extend(Element, {
	getWidth: function(element) {
	   	element = $(element);
	   	return element.offsetWidth; 
	},
	setWidth: function(element,w) {
		
		if(element.style == null){
			return;	
		}
		
	   	element = $(element);
    	element.style.width = w +"px";
	},
	setHeight: function(element,h) {
		

		
		
   		element = $(element);
		
		if(element.style == null){
			return;	
		}				
		
    	element.style.height = h +"px";
	},
	setTop: function(element,t) {
	   	element = $(element);
    	element.style.top = t +"px";
	},
	setLeft: function(element,l) {
	   	element = $(element);
    	element.style.left = l +"px";
	},
	setSrc: function(element,src) {
    	element = $(element);
    	element.src = src; 
	},
	setHref: function(element,href) {
    	element = $(element);
    	element.href = href; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
});

// -----------------------------------------------------------------------------------

//
//	Extending built-in Array object
//	- array.removeDuplicates()
//	- array.empty()
//
Array.prototype.removeDuplicates = function () {
    for(i = 0; i < this.length; i++){
        for(j = this.length-1; j>i; j--){        
            if(this[i][0] == this[j][0]){
                this.splice(j,1);
            }
        }
    }
}

// -----------------------------------------------------------------------------------

Array.prototype.empty = function () {
	for(i = 0; i <= this.length; i++){
		this.shift();
	}
}

// -----------------------------------------------------------------------------------

//
//	Lightbox Class Declaration
//	- initialize()
//	- start()
//	- changeImage()
//	- resizeImageContainer()
//	- showImage()
//	- updateDetails()
//	- updateNav()
//	- enableKeyboardNav()
//	- disableKeyboardNav()
//	- keyboardNavAction()
//	- preloadNeighborImages()
//	- end()
//
//	Structuring of code inspired by Scott Upton (http://www.uptonic.com/)
//
var zeusportalImage = Class.create();

zeusportalImage.prototype = {
	
	// initialize()
	// Constructor runs on completion of the DOM loading. Calls updateImageList and then
	// the function inserts html at the bottom of the page which is used to display the shadow 
	// overlay and the image container.
	//
	initialize: function() {	
		
		this.updateImageList();

		// Code inserts html at the bottom of the page that looks similar to this:
		//
		//	<div id="overlay"></div>
		//	<div id="lightbox">
		//		<div id="outerImageContainer">
		//			<div id="imageContainer">
		//				<img id="lightboxImage">
		//				<div style="" id="hoverNav">
		//					<a href="#" id="prevLink"></a>
		//					<a href="#" id="nextLink"></a>
		//				</div>
		//				<div id="loading">
		//					<a href="#" id="loadingLink">
		//						<img src="images/loading.gif">
		//					</a>
		//				</div>
		//			</div>
		//		</div>
		//		<div id="imageDataContainer">
		//			<div id="imageData">
		//				<div id="imageDetails">
		//					<span id="caption"></span>
		//					<span id="numberDisplay"></span>
		//				</div>
		//				<div id="bottomNav">
		//					<a href="#" id="bottomNavClose">
		//						<img src="images/close.gif">
		//					</a>
		//				</div>
		//			</div>
		//		</div>
		//	</div>


		var objBody = document.getElementsByTagName("body").item(0);
		
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','zeusportal-overlay');
		objOverlay.style.display = 'none';
		objOverlay.onclick = function() { myzeusportalImage.end(); }
		objBody.appendChild(objOverlay);
		
		var objLightbox = document.createElement("div");
		objLightbox.setAttribute('id','zeusportal-lightbox');
		objLightbox.style.display = 'none';
		objLightbox.onclick = function(e) {	// close Lightbox is user clicks shadow overlay
			if (!e) var e = window.event;
			var clickObj = Event.element(e).id;
			if ( clickObj == 'zeusportal-lightbox') {
				myzeusportalImage.end();
			}
		};
		objBody.appendChild(objLightbox);
			
		var objOuterImageContainer = document.createElement("div");
		objOuterImageContainer.setAttribute('id','zeusportal-outerImageContainer');
		objLightbox.appendChild(objOuterImageContainer);

		// When Lightbox starts it will resize itself from 250 by 250 to the current image dimension.
		// If animations are turned off, it will be hidden as to prevent a flicker of a
		// white 250 by 250 box.
		if(animate){
			Element.setWidth('zeusportal-outerImageContainer', 250);
			Element.setHeight('zeusportal-outerImageContainer', 250);
		} else {
			Element.setWidth('zeusportal-outerImageContainer', 1);
			Element.setHeight('zeusportal-outerImageContainer', 1);
		}

		var objImageContainer = document.createElement("div");
		objImageContainer.setAttribute('id','zeusportal-imageContainer');
		objOuterImageContainer.appendChild(objImageContainer);
	
		var objLightboxImage = document.createElement("img");
		objLightboxImage.setAttribute('id','zeusportal-lightboxImage');
		objImageContainer.appendChild(objLightboxImage);
	
		var objHoverNav = document.createElement("div");
		objHoverNav.setAttribute('id','zeusportal-hoverNav');
		objImageContainer.appendChild(objHoverNav);
	
		var objPrevLink = document.createElement("a");
		objPrevLink.setAttribute('id','zeusportal-prevLink');
		objPrevLink.setAttribute('href','#');
		objHoverNav.appendChild(objPrevLink);
		
		var objNextLink = document.createElement("a");
		objNextLink.setAttribute('id','zeusportal-nextLink');
		objNextLink.setAttribute('href','#');
		objHoverNav.appendChild(objNextLink);
	
		var objLoading = document.createElement("div");
		objLoading.setAttribute('id','zeusportal-loading');
		objImageContainer.appendChild(objLoading);
	
		var objLoadingLink = document.createElement("a");
		objLoadingLink.setAttribute('id','zeusportal-loadingLink');
		objLoadingLink.setAttribute('href','#');
		objLoadingLink.onclick = function() { myzeusportalImage.end(); return false; }
		objLoading.appendChild(objLoadingLink);
	
		var objLoadingImage = document.createElement("img");
		objLoadingImage.setAttribute('src', fileLoadingImage);
		objLoadingLink.appendChild(objLoadingImage);

		var objImageDataContainer = document.createElement("div");
		objImageDataContainer.setAttribute('id','zeusportal-imageDataContainer');
		objLightbox.appendChild(objImageDataContainer);

		var objImageData = document.createElement("div");
		objImageData.setAttribute('id','zeusportal-imageData');
		objImageDataContainer.appendChild(objImageData);
	
		var objImageDetails = document.createElement("div");
		objImageDetails.setAttribute('id','zeusportal-imageDetails');
		objImageData.appendChild(objImageDetails);
	
		var objCaption = document.createElement("span");
		objCaption.setAttribute('id','zeusportal-caption');
		objImageDetails.appendChild(objCaption);
	
		var objNumberDisplay = document.createElement("span");
		objNumberDisplay.setAttribute('id','zeusportal-numberDisplay');
		objImageDetails.appendChild(objNumberDisplay);
		
		var objBottomNav = document.createElement("div");
		objBottomNav.setAttribute('id','zeusportal-bottomNav');
		objImageData.appendChild(objBottomNav);
	
		var objBottomNavCloseLink = document.createElement("a");
		objBottomNavCloseLink.setAttribute('id','zeusportal-bottomNavClose');
		objBottomNavCloseLink.setAttribute('href','#');
		objBottomNavCloseLink.onclick = function() { myzeusportalImage.end(); return false; }
		objBottomNav.appendChild(objBottomNavCloseLink);
	
		var objBottomNavCloseImage = document.createElement("img");
		objBottomNavCloseImage.setAttribute('src', fileBottomNavCloseImage);
		objBottomNavCloseLink.appendChild(objBottomNavCloseImage);
	},


	//
	// updateImageList()
	// Loops through anchor tags looking for 'lightbox' references and applies onclick
	// events to appropriate links. You can rerun after dynamically adding images w/ajax.
	//
	updateImageList: function() {	
		if (!document.getElementsByTagName){ return; }
        var images = document.getElementsByTagName('img');

        // loop through all image tags
		for (var i=0; i<images.length; i++){
			var image = images[i];

			var relAttribute = String(image.getAttribute('rel'));

			// use the string.match() method to catch 'lightbox' references in the rel attribute
			if (image.getAttribute('src') && (relAttribute.toLowerCase().match('zeusportal-lightbox'))){
				image.onclick = function () {myzeusportalImage.start(this); return false;}
			}
		}
    },
	
	
	//
	//	start()
	//	Display overlay and lightbox. If image is part of a set, add siblings to imageArray.
	//
	start: function(imageLink, imgSrc) {	

		hideSelectBoxes();
		hideFlash();

		// stretch overlay to fill page and fade in
		var arrayPageSize = getPageSize();
		Element.setWidth('zeusportal-overlay', arrayPageSize[0]);
		Element.setHeight('zeusportal-overlay', arrayPageSize[1]);

		new Effect.Appear('zeusportal-overlay', { duration: overlayDuration, from: 0.0, to: overlayOpacity });

		imageArray = [];
		imageNum = 0;		

		if (!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByTagName( imageLink.tagName);

		// if image is NOT part of a set..
		// if((imageLink.getAttribute('rel') == 'lightbox')){
			// add single image to imageArray
        imageArray.push(new Array(imgSrc, imageLink.getAttribute('title')));
		// } 

        /*
        // don't worry about sets right now...
        else {
        // if image is part of a set..

			// loop through anchors, find other images in set, and add them to imageArray
			for (var i=0; i<anchors.length; i++){
				var anchor = anchors[i];
				if (() && (anchor.getAttribute('rel') == imageLink.getAttribute('rel'))){
					imageArray.push(new Array(anchor.getAttribute('src') ? anchor.getAttribute('src') : anchor.getAttribute('href'), anchor.getAttribute('title')));
				}
			}
			imageArray.removeDuplicates();
            // TODO: check against src attribute as well
            while(imageArray[imageNum][0] != imageLink.getAttribute('href')) { imageNum++;}
		}
		*/

		// calculate top and left offset for the lightbox 
		var arrayPageScroll = getPageScroll();
		var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 10);
		var lightboxLeft = arrayPageScroll[0];
		Element.setTop('zeusportal-lightbox', lightboxTop);
		Element.setLeft('zeusportal-lightbox', lightboxLeft);
		
		Element.show('zeusportal-lightbox');
		
		this.changeImage(imageNum);
	},

	//
	//	changeImage()
	//	Hide most elements and preload image in preparation for resizing image container.
	//
	changeImage: function(imageNum) {	
		
		activeImage = imageNum;	// update global var

		// hide elements during transition
		if(animate){ Element.show('zeusportal-loading');}
		Element.hide('zeusportal-lightboxImage');
		Element.hide('zeusportal-hoverNav');
		Element.hide('zeusportal-prevLink');
		Element.hide('zeusportal-nextLink');
		Element.hide('zeusportal-imageDataContainer');
		Element.hide('zeusportal-numberDisplay');
		
		imgPreloader = new Image();
		
		// once image is preloaded, resize image container per
        // http://www.foundmyself.com/forum/viewtopic.php?p=8235
        imgPreloader.onload=function(){
            Element.setSrc('zeusportal-lightboxImage', imageArray[activeImage][0]);
            // Resizing scriptasticness
            var arrayPageSize = getPageSize();
            // If image height is bigger or equal to window height, resize image

            // Don't resize the image, force the browser to scroll to see the image
            /*
            if(imgPreloader.height >= arrayPageSize[3]) {
                // Set new height of image to browser widh minus a 250px buffer
                var newHeight = arrayPageSize[3] - 250;
                // Set width accordingly
                var newWidth = (imgPreloader.width*newHeight)/imgPreloader.height;
                // Do it
                Element.setHeight('zeusportal-lightboxImage',newHeight);
                Element.setWidth('zeusportal-lightboxImage',newWidth);
                myzeusportalImage.resizeImageContainer(newWidth,newHeight);
            }
            // If image width is bigger or equal to window width, resize image
            else if(imgPreloader.width >= arrayPageSize[2]) {
                // Set new width of image to browser widh minus a 250px buffer
                var newWidth = arrayPageSize[2] - 250;
                // Set width accordingly
                var newHeight = (imgPreloader.height*newWidth)/imgPreloader.width;
                // Do it
                Element.setHeight('zeusportal-lightboxImage',newHeight);
                Element.setWidth('zeusportal-lightboxImage',newWidth);
                myzeusportalImage.resizeImageContainer(newWidth,newHeight);
            }
            else {
                Element.setHeight('zeusportal-lightboxImage',imgPreloader.height);
                Element.setWidth('zeusportal-lightboxImage',imgPreloader.width);
                myzeusportalImage.resizeImageContainer(imgPreloader.width, imgPreloader.height);
            }
            */
            Element.setHeight('zeusportal-lightboxImage',imgPreloader.height);
            Element.setWidth('zeusportal-lightboxImage',imgPreloader.width);
            myzeusportalImage.resizeImageContainer(imgPreloader.width, imgPreloader.height);
            
        }

        imgPreloader.src = imageArray[activeImage][0];
	},

	//
	//	resizeImageContainer()
	//
	resizeImageContainer: function( imgWidth, imgHeight) {

		// get curren width and height
		this.widthCurrent = Element.getWidth('zeusportal-outerImageContainer');
		this.heightCurrent = Element.getHeight('zeusportal-outerImageContainer');

		// get new width and height
		var widthNew = (imgWidth  + (borderSize * 2));
		var heightNew = (imgHeight  + (borderSize * 2));

		// scalars based on change from old to new
		this.xScale = ( widthNew / this.widthCurrent) * 100;
		this.yScale = ( heightNew / this.heightCurrent) * 100;

		// calculate size difference between new and old image, and resize if necessary
		wDiff = this.widthCurrent - widthNew;
		hDiff = this.heightCurrent - heightNew;

		if(!( hDiff == 0)){ new Effect.Scale('zeusportal-outerImageContainer', this.yScale, {scaleX: false, duration: resizeDuration, queue: 'front'}); }
		if(!( wDiff == 0)){ new Effect.Scale('zeusportal-outerImageContainer', this.xScale, {scaleY: false, delay: resizeDuration, duration: resizeDuration}); }

		// if new and old image are same size and no scaling transition is necessary, 
		// do a quick pause to prevent image flicker.
		if((hDiff == 0) && (wDiff == 0)){
			if (navigator.appVersion.indexOf("MSIE")!=-1){ pause(250); } else { pause(100);} 
		}

		Element.setHeight('zeusportal-prevLink', imgHeight);
		Element.setHeight('zeusportal-nextLink', imgHeight);
		Element.setWidth( 'zeusportal-imageDataContainer', widthNew);

		this.showImage();
	},
	
	//
	//	showImage()
	//	Display image and begin preloading neighbors.
	//
	showImage: function(){
		Element.hide('zeusportal-loading');
		new Effect.Appear('zeusportal-lightboxImage', { duration: resizeDuration, queue: 'end', afterFinish: function(){	myzeusportalImage.updateDetails(); } });
		this.preloadNeighborImages();
	},

	//
	//	updateDetails()
	//	Display caption, image number, and bottom nav.
	//
	updateDetails: function() {
	
		// if caption is not null
		if(imageArray[activeImage][1]){
			Element.show('zeusportal-caption');
			Element.setInnerHTML( 'zeusportal-caption', imageArray[activeImage][1]);
		}
		
		// if image is part of set display 'Image x of x' 
		if(imageArray.length > 1){
			Element.show('zeusportal-numberDisplay');
			Element.setInnerHTML( 'zeusportal-numberDisplay', "Image " + eval(activeImage + 1) + " of " + imageArray.length);
		}

		new Effect.Parallel(
			[ new Effect.SlideDown( 'zeusportal-imageDataContainer', { sync: true, duration: resizeDuration, from: 0.0, to: 1.0 }),
			  new Effect.Appear('zeusportal-imageDataContainer', { sync: true, duration: resizeDuration }) ],
			{ duration: resizeDuration, afterFinish: function() {
				// update overlay size and update nav
				var arrayPageSize = getPageSize();
				Element.setHeight('zeusportal-overlay', arrayPageSize[1]);
				myzeusportalImage.updateNav();
				}
			} 
		);
	},

	//
	//	updateNav()
	//	Display appropriate previous and next hover navigation.
	//
	updateNav: function() {

		Element.show('zeusportal-hoverNav');

		// if not first image in set, display prev image button
		if(activeImage != 0){
			Element.show('zeusportal-prevLink');
			document.getElementById('zeusportal-prevLink').onclick = function() {
				myzeusportalImage.changeImage(activeImage - 1); return false;
			}
		}

		// if not last image in set, display next image button
		if(activeImage != (imageArray.length - 1)){
			Element.show('zeusportal-nextLink');
			document.getElementById('zeusportal-nextLink').onclick = function() {
				myzeusportalImage.changeImage(activeImage + 1); return false;
			}
		}
		
		this.enableKeyboardNav();
	},

	//
	//	enableKeyboardNav()
	//
	enableKeyboardNav: function() {
		document.onkeydown = this.keyboardAction; 
	},

	//
	//	disableKeyboardNav()
	//
	disableKeyboardNav: function() {
		document.onkeydown = '';
	},

	//
	//	keyboardAction()
	//
	keyboardAction: function(e) {
		if (e == null) { // ie
			keycode = event.keyCode;
			escapeKey = 27;
		} else { // mozilla
			keycode = e.keyCode;
			escapeKey = e.DOM_VK_ESCAPE;
		}

		key = String.fromCharCode(keycode).toLowerCase();
		
		if((key == 'x') || (key == 'o') || (key == 'c') || (keycode == escapeKey)){	// close lightbox
			myzeusportalImage.end();
		} else if((key == 'p') || (keycode == 37)){	// display previous image
			if(activeImage != 0){
				myzeusportalImage.disableKeyboardNav();
				myzeusportalImage.changeImage(activeImage - 1);
			}
		} else if((key == 'n') || (keycode == 39)){	// display next image
			if(activeImage != (imageArray.length - 1)){
				myzeusportalImage.disableKeyboardNav();
				myzeusportalImage.changeImage(activeImage + 1);
			}
		}

	},

	//
	//	preloadNeighborImages()
	//	Preload previous and next images.
	//
	preloadNeighborImages: function(){

		if((imageArray.length - 1) > activeImage){
			preloadNextImage = new Image();
			preloadNextImage.src = imageArray[activeImage + 1][0];
		}
		if(activeImage > 0){
			preloadPrevImage = new Image();
			preloadPrevImage.src = imageArray[activeImage - 1][0];
		}
	
	},

	//
	//	end()
	//
	end: function() {
		this.disableKeyboardNav();
		Element.hide('zeusportal-lightbox');
		new Effect.Fade('zeusportal-overlay', { duration: overlayDuration});
		showSelectBoxes();
		showFlash();
	}
}

// -----------------------------------------------------------------------------------

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// -----------------------------------------------------------------------------------

//
// getKey(key)
// Gets keycode. If 'x' is pressed then it hides the lightbox.
//
function getKey(e){
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();
	
	if(key == 'x'){
	}
}

// -----------------------------------------------------------------------------------

//
// listenKey()
//
function listenKey () {	document.onkeypress = getKey; }
	
// ---------------------------------------------------

function showSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

// ---------------------------------------------------

function showFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "visible";
	}

	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "hidden";
	}

	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "hidden";
	}

}


// ---------------------------------------------------

//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Help from Ran Bar-On [ran2103@gmail.com]
//

function pause(ms){
	var date = new Date();
	curDate = null;
	do{var curDate = new Date();}
	while( curDate - date < ms);
}
/*
function pause(numberMillis) {
	var curently = new Date().getTime() + sender;
	while (new Date().getTime();	
}
*/
// ---------------------------------------------------



function initzeusportalImage() { myzeusportalImage = new zeusportalImage(); }
Event.observe(window, 'load', initzeusportalImage, false);


function getHttpRequest(){

var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
	{
	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
  catch (e)
	{
	try
	  {
	  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	catch (e)
	  {
	  alert("Your browser does not support AJAX!");
	  return false;
	  }
	}
  }

	return xmlHttp;

}

function toggleAjaxVisibility(url,elementid, textTTLoading)
{
	var xmlHttp = getHttpRequest();
	
	loadingContent = '<strong class="zeusportal-tooltip2-loading">' + textTTLoading + '</strong>';	

	xmlHttp.open("GET", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	xmlHttp.send(null);

	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
		 document.getElementById(elementid).innerHTML = loadingContent;    
		 document.getElementById(elementid).innerHTML = xmlHttp.responseText;
		}
		
	}
	
  
 }

