/*
 * jQuery zoomEvent
 * http://solar-logos.appspot.com
 * 
 * Copyright (c) 2011 "Argo" Mauro Colella
 * Dual licensed under the MIT and GPL licenses.
 * See LICENSE.txt
 */

(function($) {
	// *** Register our plugin.
	
	
	
	$.fn.zoomListener = function () {
		// *** Plugin variables.
		var data = this.data("zoomEvent"); 
		if(!data){
			this.data("zoomEvent", data = {
				interval: 20,
				lastWidth: 0,
				lastHeight: 0/*,
				lastFontSize: 0*/
			});
			data = this.data("zoomEvent"); 
		}
		
		// *** Hook main program loop into the jQuery animation system.
		this.animate({opacity:"1.0"}, data.interval, function() {
			
			$(this).toggle().zoomListener();
			//console.log(($("span:last-child").height()*100/data.firstFontSize)+"%");
			// *** Get current window dimensions
			var widthNow = $(window).width() /*fontSizeNow = 100 * $("body").height()/heightNow*/,heightNow = $(window).height();
			if (data.lastWidth !== widthNow/* || data.lastFontSize !== fontSizeNow*/){	// || data.lastHeight !== heightNow){
				// *** If dimensions have changed, update data, and 
				// *** fire documentZoomed event on all available components.
				$(this).data("zoomEvent",{
					interval: data.interval,
					lastWidth: widthNow,
					lastHeight: heightNow/*,
					lastFontSize: fontSizeNow*/
				});
				$.event.trigger("documentzoom",$(this).data("zoomEvent"));	
			}
		
			// *** Make plugin chainable.
			return $(this);
		});
	}
	
	// Auto-start
	$(document).ready(function(){
		$("script:first").zoomListener();
	})
	

})(jQuery);


