/*
 *
 *JavaScript Document for Art Sensus
 *
 * scaleMe - Scall the website for different browsers
 *
*/

$(function() {	
	
	
	
	// Display the current height when the browser is resized
	$(window).bind("resize", function() {
			
		// Run the scale image function		
		scaleMePic();
		
	});
		
	// Run the function when the page first loads
	// Scale the website when the page is first loaded
	$(window).load(function() {
		
		// Set the orginal height
		$( '#inner-wrapper' ).find( '.scale_me' ).each(function() {
			if ($(this)[0].complete) {
				// Make sure the image has loaded before scaling
				$(this).data('height', $(this).height());	
				$(this).data('width', $(this).width());
				// Run the scale image function		
				scaleMePic();
			}
		});
		
	});	
	
});


scaleMePic = function() {
	
	// Browser Height
	var $window = $( window );
	// Content Holder
	var $content = $( '#outer-wrapper' );
	// Content difference
	var $difference = $window.height() - $content.height() - 50;
	
	// Display window height
	$( '#browser_functions #browser_height span' ).html( $window.height()) ;	
	// Display content height
	$( '#browser_functions #content_height span' ).html( $content.height()) ;
		
	// content difference
	$( '#browser_functions #content_difference span' ).html( $difference ) ;

	// Scale the images!!!!   
   $( '#inner-wrapper' ).find( '.scale_me' ).each(function() {
		
		// Scale the image
		$(this).height( $(this).height() + $difference );
		
		// If the image is greater than its original size stop scaling
		if ( $(this).height() > $(this).data('height') ) {
			$(this).height( $(this).data('height') );
		}
		
   });
	   
	
}
