$(document).ready(function()
{
	$('#navigation 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');
		});
	});

	// PNGfix
	$.ifixpng(base_url +'media/img/blank.gif');
	$('#logo img, #banner img').ifixpng();

	// sIFR text headers
	$('h1, h2, h3, h4, h5, h6').not('.nosifr').flash(
		{
			src: base_url + 'media/flash/text_garamond.swf',
			flashvars: { css: '* { color: #04522d; }' }
		},
		{ version: 8 },
		function(options) {
			var self = $(this);
			// Set flash options
			options.flashvars.txt = self.text().toUpperCase();
			options.height = self.height() * 1.25;
			options.width = self.width();
			options.wmode = 'transparent';
			// Transform the text
			self.html('<div class="text-replaced">'+ this.innerHTML +'</div>').prepend($.fn.flash.transform(options));
		}
	);

	// Require confirmation
	$('a.confirm').click(function()
	{
		return confirm('This action cannot be undone, continue?');
	});

	// "Popin" modal windows
	$("a[class='popin']").prettyPopin(
	{
		modal : true,
		width : 400,
		followScroll: true,
		loader_path: base_url +'media/js/popin/images/prettyPopin/loader.gif'
	});
});

