﻿/// <reference path="jquery/jquery-vsdoc.js"/>

/*
	The style of the website is to have pieces of paper strewn on an
	desktop. These papers overlap to some extent to further the illusion.
	This allows documents on the bottom to rise to the top when the mouse
	goes over them.
*/
$(document).ready(function() {
	/*
		First find the largest z-index of all the elements marked as stackable.
	*/
	var maxZ = -10;
	$('.stack').each(function(i) {
		
		var ndx = $(this).css('z-index');
		if (ndx == 'auto') {
			$(this).css('z-index','0')
			ndx = 0;
		}
		if (parseInt(ndx) > maxZ)
			maxZ = parseInt(ndx);
	});
	
	maxZ += 1;
	/*
		When the mouse enters a stackable element, save its old z-index and width.
		Then move the z-index to the top.
	*/
	$('.stack').mouseenter(function(ev) {
		var y = $(this).height();
		
		$(this).data('height', y);
		$(this).data('oldZ', $(this).css('z-index'));
		
		$(this).css("z-index", maxZ);
		$(this).height(parseInt(y) + 1);	//This is an IE7 hack - z-index doesn't always 'take'
	});
	/*
		When the mouse leaves, put the z-index back.
	*/
	$('.stack').mouseleave(function(ev) {
		$(this).css("z-index", $(this).data('oldZ'));
		$(this).height( $(this).data('height') );
	});
});
