// JavaScript Document

var galleryid = '.d9_flickr_gallery';

// 1. add event to gallery links


// onload
$(document).ready(function () {
							
							//alert("hello world");

$(galleryid + ' a').click(function(){
								   
		var thelink = $(this);	
		var medsrc= $(this).children('img').attr('src');
		medsrc =  medsrc.replace(/_s\.jpg$/g, '.jpg');
		var alt = $(this).children('img').attr('alt');
		var lnk = $(this).attr('href');
			
		if ( ! $('.d9_slideshow').length ){
			
			$(galleryid).before("<div class='d9_slideshow'><a href='#' class='d9_close' title='close'>[X]</a><\/div>");
			
			if (alt == '' ){
				alt = '[untitled]';	
			}
			
			// get rid of the _t to get the med URL
			
			//alert (medsrc);
			$('.d9_slideshow').append('<div class="d9_med_img"><div class="d9_mid"><div class="d9_inner"><img src="' + medsrc + '" alt="' + alt + '"/><\/div><\/div><\/div>');
			$('.d9_inner').append('<div class="d9_img_description"><span class="d9_imgtitle">' + unescape(alt) + '<\/span> <a href="' + lnk + '" class="d9_flickrlink">view on Flickr</a><\/div>');
		
			$('.d9_slideshow').slideDown();	
		
		} else {
			// if it already exists
			// change the src &alt of image, url of link and title text
			$('.d9_slideshow .d9_med_img img').attr('src', medsrc);
			$('.d9_slideshow .d9_med_img img').attr('alt', alt);
			$('.d9_slideshow .d9_imgtitle').html(unescape(alt));
			$('.d9_slideshow .d9_flickrlink').attr('href', lnk);
			
		} // end if image holder exists
		
		// add events to the close button
		$('.d9_slideshow a.d9_close').click(function(){
			$('.d9_slideshow').slideUp('', function(){ $('.d9_slideshow').remove();});				
			
			return false;
		});
		return false;					  
	});
//
//

}); // end onload