/*
 *
 *	@titre: popup.
 *	@description: javascript popup - Moniteur Archizz.
 *	@auteur: neov - http://www.neov.net.
 *	@creation: 20090602.
 *	@modification: -.
 *	@requires: jquery 1.3.2
 *
 */

// conforme avec jquery.noConflict()
(function($) {
	
	/*
	 * affichage vrai popup.
	 *
	 * @exemple: $('.popup').popup({ width:100, height:100, name:'popup', showOnLoad:true });
	 *
	 * @option: width: number, height: number
	 * @desc : taille popup
	 *
	 * @option: name: string, menubar: 'yes'/'no', resizable: 'yes'/'no', toolbar: 'yes'/'no', scrollbars: 'yes'/'no', status: 'yes'/'no'
	 * @desc : option popup
	 *	
	 * @option: showOnLoad: boolean
	 * @desc: affichage au chargement de la page
	 *		
	 */
	 
	$.fn.popup = function(o)
	{
		// options.
		o = $.extend ({
			width: 			200,
			height:			200,
			
			name:			'Popup',
			
			menubar:		'no',
			resizable:		'no',
			toolbar:		'no',
			scrollbars:		'yes',
			status:			'no',
			
			showOnLoad:		false
		}, o || {});
		
		// creation de la collection si l'element existe.
		if(this) {
		
			// retourne la collection d'element.
			return this.each(
				function()
				{
					var popPos = getPos(o.width, o.height), url = this.href;
					var features = 'width=' + o.width + ', height=' + o.height + ', top=' + popPos.top + ', left=' + popPos.left + ', menubar=' + o.menubar + ', resizable=' + o.resizable + ', tollbar=' + o.toolbar + ', scrollbars=' + o.scrollbars + ', status=' + o.status ;
					
					// evenement au click d'element.
					$(this).click(
						function()
						{
							window.open(url, o.name, features);
							
							return false;
						}
					);
					
					// affichage au chargement. simule un clic.
					if(o.showOnLoad) $(this).click();
				}
			);
	
		}
		
		// retourne la position du popup par rapport a la fenetre.
		function getPos(eW, eH) {
			var wW = $(window).width();
			var wH = $(window).height();
			
			var popPos = {}
			popPos.left = (wW - eW)/2;
			popPos.top = (wH - eH)/2;
			
			return popPos;
		}
	
	}
	
})(jQuery);
