/* Photomosaic and Homepage-specific Effects (requires jQuery) */
/* by White Whale Web Services for Kenyon College */
// Departments
var departments = Array(
	{title:'African and African-American Studies',url:'x12366.xml'},
	{title:'American Studies',url:'americanstudies.xml'},
	{title:'Anthropology',url:'http://www2.kenyon.edu/Depts/Anthropology/'},
	{title:'Art',url:'http://art.kenyon.edu/'},
	{title:'Art History',url:'x33986.xml'},
	{title:'Asian Studies',url:'asianstudies.xml'},
	{title:'Biochemistry',url:'bmb.xml'},
	{title:'Biology',url:'http://biology.kenyon.edu/'},
	{title:'Chemistry',url:'http://chemistry.kenyon.edu/'},
	{title:'Classics',url:'classics.xml'},
	{title:'Dance and Drama',url:'danceanddrama.xml'},
	{title:'Economics',url:'http://economics.kenyon.edu/'},
	{title:'English',url:'english.xml'},
	{title:'Environmental Studies',url:'environmentalstudies.xml'},
	{title:'History',url:'history.xml'},
	{title:'Integrated Program in Humane Studies',url:'iphs.xml'},
	{title:'International Studies',url:'internationalstudies.xml'},
	{title:'Law and Society',url:'x16975.xml'},
	{title:'Mathematics',url:'math.xml'},
	{title:'Modern Languages and Literatures',url:'mll.xml'},
	{title:'Molecular Biology',url:'bmb.xml'},
	{title:'Music',url:'music.xml'},
	{title:'Neuroscience',url:'neuroscience.xml'},
	{title:'Philosophy',url:'philosophy.xml'},
	{title:'Physics',url:'http://physics.kenyon.edu'},
	{title:'Political Science',url:'x2214.xml'},
	{title:'Psychology',url:'http://psychology.kenyon.edu/'},
	{title:'Public Policy',url:'x16925.xml'},
	{title:'Religious Studies',url:'http://www2.kenyon.edu/Depts/Religion/Welcome/'},
	{title:'Scientific Computing',url:'x16875.xml'},
	{title:'Sociology',url:'http://www2.kenyon.edu/Depts/Sociology/'},
	{title:'Women’s and Gender Studies',url:'http://www2.kenyon.edu/Depts/WMNS/'}
);

var departmentlist,photomosaic,captionTimer=new Object;

$(document).ready(function() { // on load
	// prep mosaic
	photomosaic = $('#photomosaic');
	$('.mosaic_photo').css('cursor','pointer').click(zoomIn).each(function() {
		$(this).html('<div class="overlay">'+this.title.replace('&lt;','<').replace('&gt;','>')+'</div>').removeAttr('title');
	});
	
	// prep feature
	feature = $('#feature'),featureCaptions = $('.feature_caption');
	if(!featureCaptions.length) feature.append('<div class="feature_image_area" style="width:900px;"></div>'); // or add a single hover area if no caption is present
	else featureCaptions.each(function() { feature.append('<div class="feature_image_area" style="width:'+$(this).width()+'px;"><div class="caption"><div class="captiontext">'+$(this).html()+'<div class="captionlinks"><a href="http://www-2.kenyon.edu/contact.xml">More About the Photo Wall</a> &bull; <a href="http://www.kenyon.edu/contact.xml">Submit Photos</a></div></div></div></div>'); $(this).remove(); }); // add hover areas for each captionable image
	$('.feature_image_area').each(function() {
		for(i=0;i<$(this).width()/100*3;i++) $(this).append('<div class="mosaic_photo"><div class="overlay"></div></div>'); // then add the appropriate number of overlays to each
	}).hover(function() {
		$(this).find('.caption').show().stop().fadeTo('slow',1);
	}, function() {
		$(this).find('.caption').stop().fadeTo('slow',0);
	});
	$('#feature .mosaic_photo').click(function() { window.location=$('#feature a').eq(0).attr('href'); });
	$('.overlay').css('cursor','pointer').fadeTo(0,0.001).hover(function() { $(this).stop().css('opacity',0.25); }, function() { $(this).stop().fadeTo(1000,0.001); });
	// prep department dropdown
	$('body').click(hideDeptList);
	$('#departments>a').addClass('dropdown').click(showDeptList).after(departmentlist).next().click(hideDeptList);
});

function zoomIn() {
	photomosaic.prepend('<div class="zoom"><img src="/Images/photomosaic/300/' + this.style.backgroundImage.replace(/.*\/photomosaic\/100\/(.*)\)/,'$1') + '" width="300" height="300" alt="Caption"/><div class="caption"><div class="captiontext">'+$(this).children().eq(0).html()+'<div class="captionlinks"><a href="http://www.kenyon.edu/contact.xml">More About the Photo Wall</a> &bull; <a href="http://www-2.kenyon.edu/contact.xml">Submit Photos</a></div></div></div></div>').children().eq(0).css('left',Math.floor(($(this).parent().children().index(this))/3)*300)
		.children().eq(0).load(function() {
		$(this).parent().fadeIn(function() {
			var caption = $(this).children().eq(1);
			captionTimer = setTimeout(function() { caption.fadeIn('slow'); },500);
			$(this).hover(function() {
				caption.stop().fadeTo('slow',1);
			},function() {
				caption.stop().fadeTo('slow',0);
			});
		});
	}).click(function() { $(this).parent().fadeOut(function() { $(this).remove(); }); }); // add div for, attach onload and onclick events
}

function showCaption() {
	$(this).children().eq(1).fadeIn();
}


function showDeptList() {
	$('body').prepend('<div id="whiteout"></div>');
	$('#whiteout').click(hideDeptList);
	$('#departmentlist').show('medium');
	return false; // cancel the link click
}

function hideDeptList() {
	$('#departmentlist').hide('fast');
	$('#whiteout').remove();
}
