//////////////////////////////////////////////////////////////////////////

// pop-ups
var popUpWindow = null;

function popUpPhoto(url) {
    // maximum photo dimensions
    var w = 1122;
    var h = 748;

//    w += 20; // include scrollbar

    var _left = ( (screen.width-w) >>1 );
    var _top = ( (screen.height-h) >>1 );

    url = "/portfolio/photo-wrapper.shtml?"+url;

    if (popUpWindow) {
        popUpWindow.close();
    }
    popUpWindow = window.open(url,"bartolomeiPopUp","toolbar=no,scrollbars=no,menubar=no,width="+w+",height="+h+",top="+_top+",left="+_left);
    popUpWindow.focus();
}

//////////////////////////////////////////////////////////////////////////

// photo tour
var W3C_DOM_support = (document.getElementById && document.childNodes && document.createElement);

var photosDirPrefix = "/images/portfolio/";
var photosDir = "/images/portfolio/contemporary/magee/";
var currentSection = 'magee';
var numPhotos = 15;
var currentPhoto = 1;
var photoChangeInterval = 4000;
var changeTimer = null;

function startPhotoTour(photoCategory, photoSection, photoCount) {
	photosDir = photosDirPrefix + photoCategory + '/' + photoSection + '/';
	currentSection = photoSection;
	numPhotos = photoCount;
	changeTimer = setTimeout('changePhoto()', photoChangeInterval);
	// preload photos
	var preloadImage = new Array();
	for (var i=2; i<=photoCount; i++) {
    	var preloadNum = i;
    	if (preloadNum < 10) {
    		preloadNum = '0'+preloadNum;
    	}
		preloadImage[i-1] = new Image();
		preloadImage[i-1].src = photosDir+preloadNum+'.jpg';
	}
}

function changePhoto() {
    if (currentPhoto < numPhotos) {
    	var prevPhotoNum = currentPhoto;
    	if (prevPhotoNum == 0) {
    		prevPhotoNum = numPhotos;
    	}
    	if (prevPhotoNum < 10) {
            prevPhotoNum = '0'+prevPhotoNum;
        }
        currentPhoto++;
        var newPhotoNum = currentPhoto;
        if (newPhotoNum < 10) {
            newPhotoNum = '0'+newPhotoNum;
        }
    	var nextPhotoNum = currentPhoto+1;
    	if (nextPhotoNum > numPhotos) {
    		nextPhotoNum = 1;
    	}
     	if (W3C_DOM_support) {
    		crossfade(document.getElementById('photoTour'), photosDir+newPhotoNum+'.jpg', '1');
    		if (document.getElementById('view'+prevPhotoNum)) {
    			document.getElementById('view'+prevPhotoNum).className = '';
    			document.getElementById('view'+newPhotoNum).className = 'current';
    		}
    		if (document.getElementById('viewNext')) {
    			document.getElementById('viewNext').href = '?section='+escape(currentSection)+'&n='+nextPhotoNum;
    		}
    		if (document.getElementById('zoomButtonLink')) {
    			document.getElementById('zoomButtonLink').href = photosDir+'zoom/'+newPhotoNum+'.jpg';
    		}
    	} else {
    	    document['photoTour'].src = photosDir + newPhotoNum + '.jpg';
    	}
        // schedule the next photo transition
        changeTimer = setTimeout('changePhoto()', photoChangeInterval);
    } else {
        // already showing last photo
        currentPhoto = 0;
        changeTimer = setTimeout('changePhoto()', 50);
    }
}

function restartPhotoTour() {
    clearTimeout(changeTimer);

    var newPhotoNum = '01';
    if (W3C_DOM_support) {
    	crossfade(document.getElementById('photoTour'), photosDir + newPhotoNum + '.jpg', '2');
    } else {
        document['photoTour'].src = photosDir + newPhotoNum + '.jpg';
    }
    currentPhoto = 1;

    // schedule the next photo transition
    changeTimer = setTimeout('changePhoto()', photoChangeInterval);
}

//////////////////////////////////////////////////////////////////////////

// drop-down menus
var inMenu = false;
var curMenuLayer = '';
var curMenu = '';
var menuTimeout = null;

function menuItemOn(layerName) {
    clearTimeout(menuTimeout);
    inMenu = true;
}

function menuItemOff(layerName) {
    inMenu = false;
    menuTimeout = setTimeout('hideMenu(curMenuLayer)', 50);
}

function showLayer(layerName) {
    if (navigator.appName == 'Netscape' && !document.getElementById) {
        eval('document.layers.'+layerName+'.visibility = "show"');
    } else if (document.getElementById) {
        document.getElementById(layerName).style.visibility = 'visible';
    } else {
        document.all[layerName].style.visibility = 'visible';
    }
}

function hideLayer(layerName) {
    if (navigator.appName == 'Netscape' && !document.getElementById) {
        eval('document.layers.'+layerName+'.visibility = "hide"');
    } else if (document.getElementById) {
        document.getElementById(layerName).style.visibility = 'hidden';
    } else {
        document.all[layerName].style.visibility = 'hidden';
    }
}

function showMenu(layerName, menuName) {
    if (menuTimeout != null) {
        clearTimeout(menuTimeout);
        hideMenu(curMenuLayer);
    }

    curMenu = menuName;

    showLayer(layerName);

    curMenuLayer = layerName;
}

function hideMenu(layerName) {
    if (!inMenu) {
        hideLayer(layerName);
    }
}

function setMenuTimer() {
    // time after mouse moves away from menu heading before menu is hidden
    menuTimeout = setTimeout('menuTimeUp()',150);
}

function menuTimeUp() {
    if (!inMenu) {
        hideMenu(curMenuLayer);
    }
}

function initializeMenus(menuContainer) {
    var menu = document.getElementById('menu_'+menuContainer);
    var menuRows = menu.getElementsByTagName('li');

    // set menu width to corresponding nav link width
    var nav_width = document.getElementById('nav_'+menuContainer).offsetWidth;
    menu.style.width = nav_width+'px';

    var nav_left = document.getElementById('nav_'+menuContainer).offsetLeft
    + document.getElementById('nav_'+menuContainer).offsetParent.offsetLeft;
    menu.style.left = nav_left+'px';

    for (var i=0; i<menuRows.length; i++) {
        menuRows[i].onmouseover = function() {
            this.className = 'on';
            menuItemOn(this.offsetParent.offsetParent);
            document.getElementById('nav_'+curMenu).className = 'active';
        };
        menuRows[i].onmouseout = function() {
            this.className = 'off';
            menuItemOff(this.offsetParent.offsetParent);
            if (curMenu != navActive) {
                document.getElementById('nav_'+curMenu).className = '';
            }
        };
    }
}
