/*******************************************************************************
	TITLE: 			Popup (jQuery Plugin)
	
	AUTHOR:			Nathan Koch
	
	VERSION:		1.0
	
	REQUIRES:		jQuery v1.2.6 (obtained at jquery.com)
	
	EXPECTS:		One or more a elements
	
	OPTIONS:		options.scrollbars:		Visible scrollbars? Boolean.
					options.resizable:		Resizable window? Boolean.
					options.status:			Visible status bar? Boolean.
					options.width:			Width of window. Integer.
					options.height:			Height of window. Integer.
					options.windowname:		Name of window object. String.
					
	DESCRIPTION:	Spawns a new window.  Use as a jQuery method on any
					collection of links, and it will use the link href and 
					text to create the popups. Defaults to 800x600
*******************************************************************************/

(function($) {
    $.fn.extend({
        popup: function(options) {
            // accept an options object with sensible defaults
            var defaults = {
                scrollbars:			true,
                resizable:			false,
                status:				false,
                width:				500,
                height:				500,
                windowname:         'default'
            };
            var options = $.extend(defaults, options);
			options.resizable = (options.resizable) ? 'yes' : 'no';
			options.status = (options.status) ? 'yes' : 'no';
			options.scrollbars = (options.scrollbars) ? 'yes' : 'no';						
				
            return this.each(function() {
                $(this).click( function(e) {
                	e.preventDefault();
                	pop($(this).attr('href'), options.windowname, options.width, options.height, options.scrollbars);         	
                });              
            });
            
            function pop(url, winName, wWidth, wHeight, scrll)
			{
				var scrollB;
			   if(!scrll)
			   {
			      scrollB = 'no';
			      var pWidth = wWidth;
			      var rSize = 'no';
			   }
			   else 
			   {
			      scrollB = scrll;
			      wWidth = parseInt(wWidth) + 20;
			      var rSize = 'yes';
			   }
			   var iMyWidth;
			   var iMyHeight;
			   iMyWidth =(window.screen.width / 2) - (wWidth / 2 + 10);
			   //half the screen width minus half the new window width (plus 5 pixel borders).
			   iMyHeight =(window.screen.height /2) - (wHeight / 2 + 15);
			   //half the screen height minus half the new window height (plus title and status bars).
			   var zWin = window.open(url, winName, "status=no,width=" + wWidth + ",height=" + wHeight + ",resizable=" + rSize + ",left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",scrollbars=" + scrollB);
			   zWin.focus();
			}
        }
    });
}) (jQuery);