// Issue archive toc toggle
$(document).ready(function() {
	if (!$('.archive-toc-toggle').length) return false;
	if (!$('.issue-archive-inside').length) return false;
	
	$('.issue-archive-inside').hide();
	
	$('.archive-toc-toggle').mouseover(function(){
	  $(this).parent().parent().parent().children().filter('.issue-archive-inside').slideDown('slow');
	});
	$('.archive-toc-toggle').mouseout(function(){
	  $(this).parent().parent().parent().children().filter('.issue-archive-inside').slideUp('slow');
	});
	$('.archive-toc-toggle').click(function(){
	  return false;
	});
});

// Login mini-form overlay
$(document).ready(function($) { 

	$('a#login-mini-close').click(function(){
		$('#login-mini').fadeOut('fast');
	});

	$('a#login-link').click(function(){
		if(document.getElementById('login-mini').style.display == "block") {
			$('#login-mini').fadeOut('fast');
		} else {
			$('#login-mini').fadeIn('fast');
			$('#username').focus();
		}
		return false;		  
	});

});

// Archives jump list
$(document).ready(function(){
	 if (!$('#archive-jump').length) return false;
   $("#archive-jump").change(function () {
        var url = $("#archive-jump option:selected").val();
		if(url) location.href = url;
	});
 });

// Automatic photo captions
$(document).ready(function() {
	$(".issue-feature img.photo").each(function() {	
		var title = $(this).attr('title');
		if (title) {
			$(this).wrap('<div class="photo">' + '</div>');
			$(this).parent().width($(this).width());
			$(this).removeClass("photo");
			$(this).parent().append( $('<div class="caption">'+title+'</div>') );
		}
	});
});

// Open external links in new window
$(document).ready(function() {
	$("a[href^=http]").each(function() {
		if(this.href.indexOf(location.hostname.replace(/www./gi, "")) == -1 || $(this).hasClass("external")) {
			$(this).click(function() { window.open(this.href, "_blank"); return false; });
		}
	})
});