/*
 * Gestione PopUp Youppido 0.1,  plugin jQuery creato per il portale http://www.youppido.com
 *
 * Autore: Luca Morabito (Mastro jQuery)
 * 
 * Dipendenze: jQuery Fancybox v. 1.3.1 o superiore
 */
(function( $ ){
	
	 var defaults = {
			 width : 300,
			 height : 100,
			 content : ""
	 };
	
	$.youpopup = function(data) {
		
		if(!$.fancybox){	
			alert('Questo plugin necessita di jQuery Fancybox per poter essere utilizzato');
		}else{
			
			if (data) $.extend(defaults, data);
			
			$('#youpopup').html(defaults.content);

			var w = parseInt($("#youpopup>:first-child").css('width').replace('px',''));
			var h = parseInt($("#youpopup>:first-child").css('height').replace('px',''));
						
			if(w <= 0 || w == null || isNaN(w)) w = defaults.width;
			if(h <= 0 || h == null || isNaN(h)) h = defaults.height;

			$('#youpopup').css('width',w);
			$('#youpopup').css('height',h);
					
			$.fancybox({
				'padding'		: 0,
				'autoScale': false,
				'autoDimensions': false,
				'scrolling': 'no', 
				'width' : (w+16),
				'height': (h+16),
				'transitionIn'	: 'fade',
				'transitionOut'	: 'none',
				'href'			: '#youpopup'
			});
			
		}	
	};
  
  
  
  $.youpopup.init = function() {
		
		$('body').append(
			youpopup = $('<div style="display: none;"><div id="youpopup" class="youpopup" style="position: absolute; top: 0px; left: 0px;"></div></div>')
		);

	};
  
  
  $(document).ready(function() {
		$.youpopup.init();
	});

})( jQuery );
