// Start up Shadowbox.
Shadowbox.init();

$(function()
{
	// Ezine tabs.
	$('.d-ezine').each(function()
	{
		// Wrap the h1 and h2 content.
		$(this).find('h1:first').nextUntil('h1').wrapAll('<div class="tabs"></div>');
		$(this).find('h2').each(function(i)
		{
			$(this).nextUntil('h2').wrapAll('<div class="tabbody"></div>');
		});
		$(this).find('.tabs').accessibleTabs({
			tabhead: 'h2',
			fx: 'show',
			fxspeed: 0,
			delay: 0,
                  autoAnchor:true
		});
		// Fix for IE6 and 7. Where the front cover does not show because of the position relative blocks.
		var el = $(this).find('ul.tabs-list>li:first');
		if ($(el).hasClass('current'))
		{
			$(el).find('a').trigger('click');
		}
	});
	
	// Image map highligher: http://davidlynch.org/js/maphilight/docs/
	// PHP template makes IE8 render in IE7 Compatibility Mode for the pages this exists for.
	$('body.o-image-map img[usemap]').each(function()
	{
		$(this).addClass('no-border').maphilight();
	});
	
	// Run the site search box plugin.
	$('form.site-search').each(function()
	{
		$(this).site_search_box({query_message: 'Search this site'});
	});

	// Thumbnail galleries.
	$('.mc .gallery').each(function()
	{
		$(this).link_thumbnailer();
	});
	
	// Events page gallery cycle.
	$('.d-events .mc .cycle, .mc .spot-d').each(function()
	{
		$(this)
		.cycle({ 
			fx:     'fade',
			speed:   1000,
			timeout: 3000,
			pause: true,
			delay: -1500
		})
		.link_thumbnailer();
	});
	
	var to_linkify = $('.d-home .section-news .item, .d-about .mc .provost, .d-home .columns-2 .section, .mc .spot, .mc .spot-f, .d-home .section-details');
	if (to_linkify.length && $.fn.linkify)
	{
		to_linkify.linkify();
	}

	//movie for provost
	$('.media').each(function()
	{
		$(this).media();
	});
	
	// Prep.
	var len = $('.ofnotes')
	.find('.ofnote')
	.each(function(i)
	{
		$(this).css({zIndex: i + 1});
	})
	.length;
	
	var rotate = function()
	{
		var section3 = this;
		var top;
		$(section3)
		.find('.ofnote')
		.each(function()
		{
			var z = $(this).css('zIndex');
			if (z == len)
			{
				top = this;
			}
			$(this).css({zIndex: ((z*1) + 1)});
		});
		$(top)
		.animate({opacity: 1}, {duration: 5000, queue: false, complete: function()
			{
				$(top).animate({opacity: 0}, {duration: 500, queue: false, complete: function()
					{
						$(top).css({zIndex: 1, opacity: 1});
						rotate.call(section3);
					}
				});
			}
		});
	};
	$('.ofnotes').each(function()
	{
		rotate.call(this);
	});
	
});




