// mouseover preloads
if (!mouseoverImagesPrefix) {
    var mouseoverImagesPrefix = '/images';
}
var mouseovers = new Array();
if (document.images) {
	var mouseoversList = new Array('about_us', 'services', 'resource_center', 'partners', 'get_involved', 'contact', 'home');
	for (var i=0; i<mouseoversList.length; i++) {
		mouseovers[mouseoversList[i]+'Off'] = new Image();
		mouseovers[mouseoversList[i]+'Off'].src = mouseoverImagesPrefix+"/nav/"+mouseoversList[i]+".gif";
		mouseovers[mouseoversList[i]+'On'] = new Image();
		mouseovers[mouseoversList[i]+'On'].src = mouseoverImagesPrefix+"/nav/"+mouseoversList[i]+"-over.gif";
	}
}

// mouseover image functions
function imgOn(imgName) {
    // don't turn on current section's nav link
    if (document.images && (imgName != curSection)) { document[imgName].src = mouseovers[imgName+'On'].src; }
}

function imgOff(imgName) {
    // don't turn off current section's nav link
    if (document.images && (imgName != curSection)) { document[imgName].src = mouseovers[imgName+'Off'].src; }
}

var W3C_DOM_support = (document.getElementById && document.childNodes && document.createElement);

function navOn(navObj, setSelected) {
	if (W3C_DOM_support) {
		var listItem = navObj.parentNode;
		if (listItem.tagName.toUpperCase() == 'LI') {
			if (listItem.className == '') {
				if (setSelected) {
					listItem.className = 'selected';
				} else {
					listItem.className = 'over';
				}
			}
		}
	}
}

function navOff(navObj) {
	if (W3C_DOM_support) {
		var listItem = navObj.parentNode;
		if (listItem.tagName.toUpperCase() == 'LI') {
			if (listItem.className == 'over') {
				listItem.className = '';
			}
		}
	}
}

// home page random photos
var photosDir = new Array();
photosDir[0] = '/images/home_photos/left/';
photosDir[1] = '/images/home_photos/center/';
photosDir[2] = '/images/home_photos/right/';

var photos = new Array();
photos[0] = new Array('01', '02', '05', '06', '07', '08', '10');
photos[1] = new Array('01,02', '03', '04', '05', '06', '07', '08', '09,10', '11');
photos[2] = new Array('03', '04', '09', '12', '13', '14');

var currentPhoto = new Array();
currentPhoto[0] = '';
currentPhoto[1] = '';
currentPhoto[2] = '';

var lastRotated = '';

var photoRotateInterval = 4000;

function rotatePhoto(forceImageNum) {
    var imageNum;
    if (forceImageNum == null) {
		do {
        	imageNum = Math.floor(Math.random() * photosDir.length);
		} while (imageNum == lastRotated);
    } else {
        imageNum = forceImageNum;
    }

    var newPhoto = '';
    while (!newPhoto.length) {
        do {
            newPhotoIndex = Math.floor(Math.random() * photos[imageNum].length);
            newPhoto = photos[imageNum][newPhotoIndex];
        } while (newPhoto == currentPhoto[imageNum]);

        var newPhotoPeople = newPhoto.split(',');
        findConflicts :
        for (var j=0; j<newPhotoPeople.length; j++) {
            var person = newPhotoPeople[j];
            for (var k=0; k<photosDir.length; k++) {
                if ((k != imageNum) &&
                    (currentPhoto[k].indexOf(person) >= 0)) {
                    // person already appears in another photo
                    newPhoto = '';
                    break findConflicts;
                }
            }
        }
    }
    currentPhoto[imageNum] = newPhoto;
	if ((forceImageNum == null) && W3C_DOM_support) {
		crossfade(document.getElementById('rotatePhoto'+imageNum), photosDir[imageNum] + newPhoto + '.jpg', '2');
	} else {
	    document['rotatePhoto'+imageNum].src = photosDir[imageNum] + newPhoto + '.jpg';
	}

    if (forceImageNum == null) {
		lastRotated = imageNum;
        // schedule the next photo rotation
        setTimeout('rotatePhoto()', photoRotateInterval);
    }
}

// subpage random photos
function randomizePhoto(imgName) {
	var numPhotos = 6;
	var randomPhoto = 1 + Math.floor(Math.random() * numPhotos);
	if (document.images && imgName) { document[imgName].src = "/images/photos/photo"+randomPhoto+".jpg"; }
}

// Suckerfish Dropdowns: http://www.htmldog.com/articles/suckerfish/dropdowns/
sfHover = function(id) {
	var sfEls = document.getElementById('menu').getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		if (!sfEls[i].className || (sfEls[i].className != 'ignore')) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


function setCheckboxState(formName,checkboxName,state) {
    var checkboxObj = eval('document.'+formName+'.elements["'+checkboxName+'"]');
    for (var i=0; i<checkboxObj.length; i++) {
        checkboxObj[i].checked = state;
    }
    if (checkboxObj && !checkboxObj.length) { checkboxObj.checked = state; }
}

var photoPopUp = null;

function popUpPhoto(photo, width, height) {
    var _left = ( (screen.width-width) >>1 );
    var _top = ( (screen.height-height) >>1 );
    if (photoPopUp) {
        photoPopUp.close();
    }
    photoPopUp = window.open("/image_wrapper.shtml?"+escape(photo),"photo","toolbar=no,scrollbars=no,menubar=no,width="+width+",height="+height+",top="+_top+",left="+_left);
    photoPopUp.focus();
}

var videoPopUp = null;

function popUpVideo(video, width, height) {
    var _left = ( (screen.width-width) >>1 );
    var _top = ( (screen.height-height) >>1 );
    if (videoPopUp) {
        videoPopUp.close();
    }
    videoPopUp = window.open(video,"video","toolbar=no,scrollbars=no,menubar=no,width="+width+",height="+height+",top="+_top+",left="+_left);
    videoPopUp.focus();
}

