$(document).ready(function() {
	$('div#leftcol').css('height',$('div#rightcol').height());
	$('li.navigation').hover(function() {		
		if ($(this).is('.home') && !$('body').is('#homepage')) {
			$('h2.rollovertitle').children().eq(0).text('Homepage')
		}
		else if ($(this).is('.people') && !$('body').is('#people')) {
			$('h2.rollovertitle').children().eq(0).text('People')
		}
		else if ($(this).is('.resources') && !$('body').is('#resources')) {
			$('h2.rollovertitle').children().eq(0).text('Resources')
		}
		else if ($(this).is('.publications') && !$('body').is('#publications')) {
			$('h2.rollovertitle').children().eq(0).text('Publications')
		}
		else if ($(this).is('.links') && !$('body').is('#links')) {
			$('h2.rollovertitle').children().eq(0).text('Links')
		}
		else if ($(this).is('.contact') && !$('body').is('#contact')) {
			$('h2.rollovertitle').children().eq(0).text('Contact')
		}
		else if ($(this).is('.annex1') && !$('body').is('#annex1')) {
			$('h2.rollovertitle').children().eq(0).text('MochiView')
		}
		else if ($(this).is('.annex2') && !$('body').is('#annex2')) {
			$('h2.rollovertitle').children().eq(0).text('')
		}
		else {
			$('h2.rollovertitle').children().eq(0).text(' ');
		}
	}, function() {
		$('h2.rollovertitle').children().eq(0).text(' ');
	});
});
$(document).ready(function(){
	$("div#modalOverlay").click(closeEvent);
	$("div.popup-close a").click(closeEvent);
	
	
	function closeEvent() {
		$("div.current-popup").fadeOut("fast",function(){
			$("div.current-popup").appendTo("div.popup-container").removeClass("current-popup");
			$("#modalOverlay").fadeOut("fast");
		})
	}
	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;
		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;
		}
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
		return arrayPageSize;
	}
	
	var arrPageSizes = ___getPageSize();
	$('#modalOverlay').css({
		width:		arrPageSizes[0],
		height:		arrPageSizes[1]
	});

	$("div.people-popup").css('left',((arrPageSizes[0]/2)-300));

	
	$(window).resize(function() {
		// Get page sizes
		var arrPageSizes = ___getPageSize();
		// Style overlay and show it
		$('#modalOverlay').css({
			width:		arrPageSizes[0],
			height:		arrPageSizes[1]
		});
	});
	
	
	$("body#people div#leftcontent a").click(function(){
		
		var detailsId = $(this).attr('href');
		
		$('#modalOverlay').css('display', 'block').fadeTo("slow",0.6,function(){
			$("div.people-popup"+detailsId).addClass("current-popup").appendTo("body");
			$("div.people-popup"+detailsId).css('display','block').fadeIn("fast");
			

		});
		return false;
	})
});
