// alert('lightbox loaded');


// 	DOCUMENT READY FUNCTION *	*	*	*	*	*	*	*	*	*	*	*
$(document).ready(function(){
	

	
	/* LIGHTBOX */
         
		$('.lightbox').click(function(){
            var lightbox_content = $(this).attr('href');
			var lightbox_w = $(this).attr('width'); 
			var lightbox_h = $(this).attr('height');     
			
			show_lightbox(lightbox_content,lightbox_w,lightbox_h); 
			show_lightbox();
			
			
		});
        

		$('#overlay').click(function(){
			$('#viewer').fadeOut(function(){
				// Click-through FAILS
				// alert(event.pageX +' ' +event.pageY); 
				// $('#content').trigger('click',[event.pageX,event.pageY]);
			});

		});
		
		
 
	   


         /* IMAGE SWAP CLIPPING */
		// var currImage = $(this).css('backgroundImage');
		// $(this).css({backgroundImage: currImage == 'up-arrow.jpg' ? 'down-arrow.jpg' : 'up-arrow.jpg'});

		               
			 
 

});         


function show_lightbox(lightbox_content,lightbox_w,lightbox_h) {
	
		    alert(lightbox_content);
		
			// FIND VIEWPORT DIMENSIONS (ie 7/8 uses alterternate syntax)
			var viewport_h = find_viewport_h(); 
	   			function find_viewport_h() {
				        return window.innerHeight
				        || document.documentElement && document.documentElement.clientHeight
				        //|| document.body.clientHeight;
				 };  
		    
			var viewport_w = find_viewport_w();			
				function find_viewport_w() {
				        return window.innerWidth
				        || document.documentElement && document.documentElement.clientWidth
				        //|| document.body.clientWidth;
				 };
		
			//var lightbox_h;
			//var lightbox_w;  
			
			alert(lightbox_w);
			
			if (lightbox_h == null) {
				
				// SMALL SCREENS
				if (viewport_h < 800) {
					lightbox_h = 500;
					lightbox_w = 600;
					$('#lightbox').addClass('small');
				}
				// LARGE SCREENS
				else {
					lightbox_h = 600;
					lightbox_w = 750;
					$('#lightbox').addClass('large');
				}
			}
			
			var position_v  = (viewport_h - lightbox_h)/2;
			var position_h =  (viewport_w - lightbox_w)/2;
		  
	    
			$('body').addClass('lightbox');
			$('#lightbox')
				.height(lightbox_h).width(lightbox_w)
				.css('top',position_v + 'px').css('left',position_h + 'px');
			
			// alert(' viewport: ' + viewport_h + '\n lightbox: ' + lightbox_h + '\n position: ' + position_v + ', ' + position_h);
			
		
		    $('#viewer').fadeIn('fast');
		
}                                           