/*
 * jQuery popup v1 - A jQuery popup plugin.
 * By Miguel Balboa - http://pensando.com.mx
 * Licensed under the do whatever you want to license.
 * 
*/

jQuery.fn.popup = function(options) {
	
	var options = jQuery.extend (
									{
										url:		false,
										target:		'popup',	
										width: 		400,
										height: 	300,
										statusbar: 	true,
										resizable: 	true,
										toolbar: 	true,
										scrollbars:	true,
										menubar: 	true,
										location:	true,
										top:		false,
										left:		false
									},
									options
								);
	
	
	return this.each( function() {
		
		$(this).click(function(event){
			
			if (event.ctrlKey || event.shiftKey || event.metaKey)
			return;
			
			
			if (options.left==false)
			{ 	
				options.left = screen.width / 2 - options.width / 2;
			}
			
			if(options.top==false)
			{	
				options.top = screen.height / 2 - options.height / 2;
			}
				
				
				var w = open(
						(options.url==false)?$(this).attr('href'):options.url,
						options.target,
						'width= '      + options.width +
						',height='     + options.height + 
						',top='        + options.top + 
						',left='       + options.left + 
						',scrollbars=' + ((options.scrollbars)?'yes':'no') +
						',resizable='  + ((options.resizable)?'yes':'no') +
						',menubar='    + ((options.menubar)?'yes':'no') +
						',location='   + ((options.location)?'yes':'no') +
						',statusbar='   + ((options.statusbar)?'yes':'no') +
						',toolbar='   + ((options.toolbar)?'yes':'no')
					);
				
				
				if (w && !w.closed) {
					
					w.focus();
					event.preventDefault();
				}	
				
			
			return;
			
		});
		
	});
	

};


jQuery.popupWin = function(options)
{

	var options = jQuery.extend (
			{
				url:		false,
				target:		'popup',	
				width: 		400,
				height: 	300,
				statusbar: 	true,
				resizable: 	true,
				toolbar: 	true,
				scrollbars:	true,
				menubar: 	true,
				location:	true,
				top:		false,
				left:		false
			},
			options
		);

		if (event.ctrlKey || event.shiftKey || event.metaKey)
		return;
		
		
		if (options.left==false)
		{ 	
			options.left = screen.width / 2 - options.width / 2;
		}
		
		if(options.top==false)
		{	
			options.top = screen.height / 2 - options.height / 2;
		}

		var w = open(
				options.url,
				options.target,
				'width= '      + options.width +
				',height='     + options.height + 
				',top='        + options.top + 
				',left='       + options.left + 
				',scrollbars=' + ((options.scrollbars)?'yes':'no') +
				',resizable='  + ((options.resizable)?'yes':'no') +
				',menubar='    + ((options.menubar)?'yes':'no') +
				',location='   + ((options.location)?'yes':'no') +
				',statusbar='   + ((options.statusbar)?'yes':'no') +
				',toolbar='   + ((options.toolbar)?'yes':'no')
			);
		
		
		if (w && !w.closed) {
			
			w.focus();
			return false;
			
		}else
		return;	

		

};
