$(document).ready(function()
{
	// Dropdown menus
	$('#menu li.top').each(function()
	{
		var sub  = $(this).find('ul');
		var link = $(this).find('a:first');

		if (sub.length > 0 && typeof sub._h == 'undefined')
		{
			var p_top = sub.css('padding-top');
			var p_bot = sub.css('padding-bottom');

			// Set the expanded height
			sub._h = sub.height() + parseInt(p_top) + parseInt(p_bot);

			// Add top padding to the first child
			sub.find('li:first').css('padding-top', p_top);

			// Remove top/bottom padding
			sub.css('padding-bottom', 0).css('padding-top', 0);

			// Prepare to animate
			sub.css({ height: 0 });
		}

		$(this).hover(function()
		{
			// Activate top level
			$(this).addClass('active');

			// Go to full height
			sub.stop().animate({ height: sub._h }, 300);
		},
		function()
		{
			// Go to 0 height
			sub.stop().animate({ height: 0 }, 300);

			// Deactivate top level
			$(this).removeClass('active');
		});
	});

	// Striped tables
	$('table.stripe tr:nth-child(odd)').addClass('alt');

	// Striped lists
	$('ol.stripe li:nth-child(odd)').addClass('alt');
	$('li.stripe li:nth-child(odd)').addClass('alt');

	// sIFR text headers
	$('.sifr').flash(
		{
			src: base_url + 'media/flash/caslon.swf',
			flashvars: {
				css: [
					'* { color: #605b59; }',
					'a { color: #141571; text-decoration: underline; }',
					'a:hover { color: #17198a; }'
				].join(' ')
			}
		},
		{ version: 7 },
		function(options) {
			var self = $(this).html('<div>'+ this.innerHTML +'</div>');
			var text = $(this.firstChild);
			// Set flash options
			options.flashvars.txt = text.text().toLowerCase(); // Text must be lowercase with this font
			options.height = text.height();
			options.width = text.width();
			options.wmode = 'transparent';
			// Add the alt class
			text.addClass('alt');
			// Transform the text
			self.prepend($.fn.flash.transform(options));
		}
	);
});
