/* Denis Leary */
/* Photo Viewer Javascript
----------------------------------------------------------------------------- */


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

	$(window).load(function() {


/* INITIALIZE PLUG-INS
----------------------------------------------------------------------------- */

	if (page == "why_we_suck" || page == "rescue_me_comedy_tour") {

		slideshow('div.widget-photo ul.photos');
		$('div.widget-photo ul.photos li').css('position','absolute');
		
	}
		

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

	if (page == "photos") {

		$('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
----------------------------------------------------------------------------- */

	});



/* FUNCTION: SLIDESHOW
----------------------------------------------------------------------------- */

	function slideshow(selector) {

		$(selector).show();

		// CHANGE MARKUP
		$(selector).children('a, h3, dl, ul.paging, ul.pages, ul.actions').remove();
		$(selector).siblings('ul.paging, ul.pages, ul.actions').remove();

		$(selector).children('h4').each(function() {

			$(this).insertAfter($(this).prev().children('a'));	

		});

		$(selector).parent().append('<a id="next" class="action next" href="#">Next</a>');
		$(selector).parent().append('<a id="prev" class="action prev" href="#">Previous</a>');

		// START SLIDESHOW
		if (page == "rescue_me_comedy_tour") {

			$(selector).cycle({ 
				fx:      'fade', 
				speed:    "fast", 
				next:    '#next',
				prev:    '#prev'
	
			});
		
		}

		else {

			$(selector).cycle({ 
				fx:      'fade', 
				speed:    "fast", 
				timeout:  0,
				next:    '#next',
				prev:    '#prev'
	
			});

		}

	}


/* FUNCTION: CLOSE PHOTO VIEWER
--------------------------------------------------------------------------- */

	function closeViewer() {

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

			return false;		

		}
