$(document).ready(function(){

	// bind clicks on thumbnails
	var bindClickThumbnails = function() {

		$('#musicWrap img').each(

			// For each item, bind the onclick behavior.
			function() {

				// Bind the onclick event 
				$(this).click(
					function() {
						
						var theId = $(this).attr('id'); // get ID of clicked element
						
						// load flash music player for this release
						$.ajax({
							type: 'POST',
							url: '/ajax/music.php',
							data: 'playlist=' + theId,
							success: function(html){
								$('#rightCol').html(html);
							}
						});

						// load discog information for this release
						$('#rightCol').load('/ajax/discog/' + theId + '.html', null, function(){
							tb_init('a.thickbox, area.thickbox, input.thickbox'); // re-bind thickbox to new discog images
						});


						return false; // return false so the link doesn't actually click anywhere

					}
				);
			}
		);
	};
	
	// bind onclick events on initial pageload
	bindClickThumbnails();

});
