jQuery(function ($) {

/* Home slideshow */
$.fn.Slideshow = function() {
	var settings = {
		delay: 3000,
		speed: 1200, // integer, not keyword
		nav: 1
	};
	return this.each(function() {
		var $div = $(this), activeslide = 0, imgs = $('img', $div).length, autoplay = 1;
		$('.slide', $div).bind('In', function() {
			$(this).fadeIn(settings.speed).addClass('current');
		}).bind('Out', function() {
			$(this).fadeOut(settings.speed).removeClass('current');
		}).find('img').attr('title','');
		function advanceslide() {
			if(settings.nav) {
				$('.trigger.current', $div).removeClass('current');
				$('.trigger:eq('+ activeslide +')', $div).addClass('current');
			};
			$('.slide.current', $div).trigger('Out');
			$('.slide:eq('+ activeslide +')', $div).trigger('In');
		};
		function doslideshow() {
			if(autoplay) {
				(activeslide+1 == imgs) ? activeslide = 0 : activeslide++;
				advanceslide();
			};
			setTimeout(doslideshow, settings.delay+settings.speed);
		};
		function startshow() {
			if(settings.nav) $('.trigger:eq(0)', $div).addClass('current');
			$('.slide:eq(0)', $div).addClass('current');
			setTimeout(doslideshow, settings.delay);
		};
		$div.hover(function(){autoplay=0;},function(){autoplay=1;});
		if(settings.nav) {
			$div.append('<div class="nav" />');
			$('.slide', $div).each(function(i) {
				$('.nav', $div).append('<a class="trigger" href="#" title="Go to slide '+(i+1)+'" />').find('.trigger:eq('+i+')').bind('click', function(e) {
					e.preventDefault();
					activeslide = i;
					advanceslide();
				});
			});
		};
		startshow();
	});
};


$(document).ready(function() {

/* h1, h2 border-after */
	$('body.page div.entry-content h2').add('h2.entry-title').add('body.single div.post h1').add('.border-after').css('borderBottom', 'none').wrapInner('<span class="border" />').after('<b class="after-h2" />');


/* Accordion menu */
	$('li','#menu-main-navigation').has('ul.sub-menu').each(function(){
		var $this = $(this);
		$this.find('a:first').mouseover(function(){
			$('>ul', $this).slideDown().addClass('menu-open');
		});
	});
	$('#primary ul.nav').mouseleave(function(){
		$('.menu-open:not(.current-menu-parent>ul)').delay(800).slideUp().removeClass('menu-open');
	});


/* Highlight Shop in menu when viewing subpages */
	if (typeof shopPage != 'undefined' && shopPage)
		$('#menu-item-134').addClass('current-menu-item');

/* Move 'Small' size to top of menu */
	$('select.wpsc_select_variation option[value="9"]').each( function(){
		$(this).prependTo($(this).parent());
	});


/* NextGen Gallery */
	// breadcrumbs
	$('span.ngg').appendTo('h2 span.border');
	// click anywhere to close image popup (doesn't work why??)
	//$('#shShutter').live('click',function(){shutterReloaded.hideShutter();});


/* Header submit button rollover */
	$('#maillist-header input[type=submit]').add('#maillist-header .cc_textbox_button').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});

/* Add icon to cc_caption in header */
	$('#maillist-header .cc_caption').prepend($('<b />'));


/* Join Us by mail toggle */
	$(this).find('span.hide').hide();
	$('p.toggle').click(function(e){
		e.target.blur();
		e.preventDefault();
		$(this).find('span.hide').toggle('slow');
	});


/* Publications page */
	$('#post-22 span.read-more').parent().after('<p class="read-more-link"><a href="#">READ MORE</a></p>')
	.next().find('a').click(function(e){
		e.preventDefault();
		$(this).parent().hide().prev().find('.read-more').show('slow');
	});

	
}); //document.ready

$(window).load(function(){
	$("#home-slideshow").Slideshow();
});

}); //jQuery

/*
    Based on Email Antileech Script by Frederic Andrieux & Boweries Inc. Ltd. (c)2002
*/
function sendmail (address, subject) {
address = address.split("( at )");
address = address.join("@");
mail_win = window.open ('mailto:'+address+'?subject='+subject);
mail_win.close();
}

