$(document).ready(function() {
	//Newsletter drop-down
	$('div#newsletter').find('a.open').click(function(){
		$('div#newsletter_form').slideToggle();
		$('div#pictures').empty();
		return false;
	});
	$('div#newsletter').find('a.mc_embed_close').click(function(){
		$('div#newsletter_form').slideUp();
		return false;
	});
	//Streaming modal
	$('a.load-stream').click(function(){
		var popup = $(this).attr('rel').replace('.txt', '.html');
		/*var link = $('<a>').attr('href', '#').attr('id', 'stream_popup').text('Open in a separate window').click(function(){
			$('div#player').empty();
			window.open(popup, $(this).attr('title'), 'width=220,height=220,scrollbars=no,toolbar=no,resizable=no,location=no,status=no,menubar=no');
			return false;
		});*/
		$('div#player').empty().append('<div class="embed"><p>Loading...</p></div>'); //.append(link);
		$('div#player').find('div.embed').load($(this).attr('rel'));
		$('div#pictures').html('<img src="' + $(this).find('img').attr('src').replace('100x100', '300x300') + '" alt="' + $(this).attr('title') + '" />');
		$('div#player').find('a.close').show();
		return false;
	});
	$('div#player').find('a.close').click(function(){
		$('div#player').find('embed').remove();
		$('div#player').find('a.close').hide();
		$('div#pictures').empty();
		return false;
	});
	
	//video player
	$('div.video-thumbs').find('div.handle').each(function(){
		var handle = $(this).find('a');
		var video_id = handle.attr('id') + '_full';
		var video = $(this).parent().parent().find('div#' + video_id);
		handle.click(function(){
			$('div.full').hide();
			video.show();
			return false;
		});
	});
	
	//mainnav active links
	$('ul.mainnav li a').each(function(){
		var url = location.pathname.split('/');
		if(url[1] == $(this).attr('class')){
			$(this).addClass('current');
		}
	});
	
	$('a.back').click(function(){
		window.history.back();
		return false;
	});
	$('a.refresh').click(function(){
		window.location.reload();
		return false;
	});
});
