/**
 * jQuery.AutoResize - Auto resizing elements (fonts and images separately)
 * Copyright (c) Federica Sibella - musings@musings.it - http://www.musings.it
 * Licensed under GPL
 * @author Federica Sibella @musings.it
 * @version 1.0
 * Last modified: 2010 April 07
 * for info write to: musings@musings.it
 */

// wait for document ready and more for webkit browsers

$(document).ready(function(){
	if (jQuery.browser.webkit && document.readyState != "complete"){
    //console.info('ready...');
    setTimeout( arguments.callee, 100 );
    return;
  } 
  
// my default width and height    
		var larghezzabase = 1920;
		var altezzabase = 1000;

//wait for all the stuff to be fully loaded
$(window).load(function(){

// backup of the original values from CSS	
		$(".resizeme").each(function() {
			$(this).attr("font-size_backup", $(this).css("font-size"));
			
		});
		
		$('.resizeimg').each(function(){
			$(this).attr("img-width_backup", $(this).attr("width"));
		});
			
// windows resize function
// catch new screen size and calculate a zoom value for fonts and image dimensions
	
	$(window).resize(function(){
	
		var newlarghezza = $(window).width();
		var newaltezza = $(window).height();
	
		if ((newlarghezza/newaltezza)<=(larghezzabase/altezzabase))
			var zoom = newlarghezza / larghezzabase;
		else
			var zoom = newaltezza / altezzabase;
		
		$(".resizeme").each(function() {
			var curr_size = $(this).attr("font-size_backup").slice(0,-2);
			var newsize   = zoom * curr_size;
			$(this).css("font-size", newsize + $(this).attr("font-size_backup").slice(-2));
		});
		
		$(".resizeimg").each(function() {
			var curr_width = $(this).attr("img-width_backup");
			var newwidth   = zoom * curr_width;
			$(this).attr("width", newwidth);
		});

// center the selected DIV after resize
		
		$('#schermo').scrollTo('.selected', {margin: true});
		
		$('#schermo').css({
		   'margin-top': ($(window).height() - $('#schermo').height())/2,
		   'margin-bottom': ($(window).height() - $('#schermo').height())/2
		});

	});
 
	$(window).resize(); 

});	
});
