$(function() {
	/*
	// Test code for CSS:

	$('#topright a').hover(function() {
		$(this).parent().addClass('hover');
	}, function() {
		$(this).parent().removeClass('hover');
	})

	return;
	*/

	var styles = {},
		speed = 250,
		fake = $('#header').clone().css('visibility', 'hidden');

	function style_info($div, $bg, $fore)
	{
		var obj = {
				div: {
					left: $div.css('left'),
					top: $div.css('top'),
					width: $div.css('width'),
					height: $div.css('height')
				},
				bg: {
					left: $bg.css('left'),
					top: $bg.css('top')
				},
				fore: {
					left: $fore.css('left'),
					top: $fore.css('top')
				}
			};

		// Remove "auto" -- really just IE
		$.each(obj, function(index, info) {
			for (var i in info) {
				if (info[i] == 'auto') {
					info[i] = 0;
				}
			}
		});

		return obj;
	}

	$('body').append(fake);
	fake.find('#topright > div').each(function() {
		var $this = $(this),
			$bg = $this.find('img.bg'),
			$fore = $this.find('img.fore');

		$this.addClass('hover');
		styles[this.id] = {
			hover: style_info($this, $bg, $fore)
		};

		styles.hover = {
			zIndex: $this.css('z-index'),
			opacity: 1.0
		}
	});
	fake.remove();

	$('#topright > div').each(function() {
		var $this = $(this),
			$bg = $this.find('img.bg'),
			$fore = $this.find('img.fore');

		styles[this.id].normal = style_info($this, $bg, $fore);
		styles.normal = {
			zIndex: $this.css('z-index'),
			opacity: 0.65
		}
	});

	if (typeof(console) != 'undefined')
		console.log(styles);

	$('#topright a').each(function() {
		var $this = $(this),
			$div = $this.parent(),
			$bg = $this.find('img.bg'),
			$fore = $this.find('img.fore'),
			style_info = styles[$div[0].id];

		$div.hover(function() {
			$div.stop(true).animate(style_info.hover.div, speed, function() { $div.css({overflow: 'visible'}) }).css({zIndex: styles.hover.zIndex, overflow: 'visible'});
			$bg.css('opacity', styles.hover.opacity).stop(true).animate(style_info.hover.bg, speed);
			$fore.stop(true).animate(style_info.hover.fore, speed);
		}, function() {
			$div.css({zIndex: styles.normal.zIndex}).stop(true).animate(style_info.normal.div, speed, function() { $div.css({overflow: 'hidden'}) }).css('overflow', 'visible');
			$bg.css('opacity', styles.normal.opacity).stop(true).animate(style_info.normal.bg, speed);
			$fore.stop(true).animate(style_info.normal.fore, speed);
		});
	});

});

