$(document).ready(function() {

/*
	book cover zooming
*/

	//hide all the text within the book covers
	$('.bookBlurb').hide();

	$('#Items div').each( function(el) {
	//$('#Items #MBIE').each( function(el) {

		//the cover has the id of the icon with IC_ prepended
		//alert('#IC_'+$(this).attr('id'));

		//get the final width/height of cover
		var zW = $('#IC_'+$(this).attr('id')).css('width');
		var zH = $('#IC_'+$(this).attr('id')).css('height');

		//get the final co-ords of this book's cover
		var zX = $('#IC_'+$(this).attr('id')).css('left');
		var zY = $('#IC_'+$(this).attr('id')).css('top');

		//debug:
		//alert('#IC_'+$(this).attr('id')+"\n"+'w='+zW+"\n"+'h='+zH+"\n"+'x='+zX+"\n"+'y='+zY+"\n");
		
		//make this cover zero sized, at the top left of its icon
		$('#IC_'+$(this).attr('id')).css('width', '0');
		$('#IC_'+$(this).attr('id')).css('height', '0');
		
		var icX = $(this).css('left');
		var icY = $(this).css('top');
		
		$('#IC_'+$(this).attr('id')).css('left', icX);
		$('#IC_'+$(this).attr('id')).css('top', icY);


		//when we enter this div, animate the cover div
		$(this).mouseenter( function() {

			//hide the previously opened covers - and stop animation
			//on any covers that are in the process of being opened. 
			$('#ItemContent .zoomBook').stop().each( function(el) {
				$('.bookBlurb', this).hide(); //hide this element's bookBlurb

				$(this).css('width', '0');
				$(this).css('height', '0');
				$(this).css('left', icX);
				$(this).css('top', icY);

			}); //end hide other opened covers


			$('#IC_'+$(this).attr('id')).animate({
				width: zW,
				height: zH,
				left: zX,
				top: zY,
				opacity: 1.0
			}, 400 );
			
			//show the caption/text content once zoom is complete
			$('#IC_'+$(this).attr('id')).queue( function() {
				//$('.bookBlurb', this).fadeIn('250');
				$('.bookBlurb', this).show();
				$(this).dequeue();
			});
			
		}); //end mouseenter

		//when the mouse leaves the cover, hide it.
		$('#IC_'+$(this).attr('id')).mouseleave( function() {
		
			$(this).animate({
				width: '0',
				height: '0',
				left: icX,
				top: icY,
				opacity: 0
			}, 400 );

			$('.bookBlurb', this).hide(); //hide this element's bookBlurb

		}); //end mouseleave

	}); //end for each item
	
	
	//show the container of covers - the contents are now hidden
	$('#ItemContent').show();

/*
	overlay modal window when links clicked
*/

	$('.colorbox').colorbox({
		iframe: 'true',
		width: '1023px',
		height: '820px'
	});


}); //end js
