/* ROOM FOR TWO */
/* Common Functions
----------------------------------------------------------------------------- */


	function closeViewer() {

		$('#enlarged').fadeOut();
		$('#enlarged img').attr('src','#');
		$('#enlarged h4').text('');

		return false;		

	}


/* BEFORE PAGE FULLY LOADS
----------------------------------------------------------------------------- */


	$(document).ready(function() {
	
	$('#blog ul.stories').jScrollPane();
	$('#lyrics ul.stories').jScrollPane();
	
		if (page == "journal") {
		
			$('div.widget-editorial ul.stories').hide();
			
		}

	});	



/* AFTER PAGE FULLY LOADS
----------------------------------------------------------------------------- */

	
	$(window).load(function() {	
		
		if (section == "whatsnew") {
	
			$('#audio div.flash div').empty();
	
			$('div#player ul.tabs').tabs({

				show: function(ui) {

					if ($('#video:visible').length > 0) {
					
						$('#audio div.widget-advertising').hide();
						$('#audio div.flash div').empty();
		
						var video_player = $('#video div.flash div').attr('id');
						eval(video_player)();
					
					} else {
					
						$('#audio div.widget-advertising').show();
						$('#video div.flash div').empty();
		
						var audio_player = $('#audio div.flash div').attr('id');
						eval(audio_player)();
					
					}

				}

			});
	
		}
	
  		$('ul.photos li > a img').each(function() {
		
			if ($(this).hasClass('portrait')) {
			
				$(this).parent().parent().addClass('portrait');
			
			}
		
		});

		$('div.widget-event.program ul.events li > strong').each(function() {
		
			var date = $(this).text().replace(', 2008','').replace(', 2009','');
			var month = date.match(/[a-zA-Z]{3}/);
			var day = date.match(/\d{1,2}/);
		
			$(this).text('');
			$(this).prepend('<abbr>' + month + '</abbr> ');
			$(this).append('<span>' + day + '</span>');
			
			$(this).show();
		
		});
	

/* NEWS BYLINE THUMBNAILS
----------------------------------------------------------------------------- */


	if (page == "journal") {
	
		$('div.widget-editorial ul.stories li').each(function() {

			$(this).children('h4').clone().prependTo(this);
			$(this).children('h4:last').remove();

			var insertion = $(this).children('em');

			$(this).children('strong').clone().appendTo(insertion);
			$(this).children('strong:first').remove();


			var byline = $(this).children('em').text();
			
			if (byline.match('Adam') || byline.match('adam')) {
			
				$(this).children('em').addClass('adam');
			
			} else if (byline.match('Niki') || byline.match('niki')) {
			
				$(this).children('em').addClass('niki');

			}

		});

		$('div.widget-editorial ul.stories').show();

	}


/* ENLARGED PHOTO VIEWER
----------------------------------------------------------------------------- */


	$('div.widget-photo.thumbnails ul.photos li a').click(function() {

		var photo = $(this).parent().children('a:first-child').children('img').attr('src').replace('thumb.',''); 
		var caption = $(this).parent().children('a:first-child').children('img').attr('title');

		if ($('#enlarged').hasClass('portrait')) {
		
			$('#enlarged').removeClass('portrait');
		
		}
		
		if ($(this).children('img').hasClass('portrait')) {
		
			$('#enlarged').addClass('portrait');
		
		}
		
		$('#enlarged img').attr('src',photo);
		$('#enlarged img').attr('title',caption);
		$('#enlarged h4').text(caption);
		$('#enlarged').fadeIn();
		
		return false;

	});

	$('#enlarged img').click(closeViewer);
	$('#enlarged a').click(closeViewer);


/* END LOAD FUNCTION
----------------------------------------------------------------------------- */


	});
