/*!
 * jQuery Popup trigger v. 0.1
 *
 * Copyright (c) 2009 Prospek Inc.
 * 
 * Dual licensed under the MIT and GPL licenses:
 * 
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Usage example:
 * 
 *	jQuery("ul#social-media-popups .popup")
 *		.popup
 *		(
 *			{
 *				"t" : "regular",
 *				"w" : "300",
 *				"h" : "300",
 *				"o" : "noicon"
 *			}
 *		);
 *
 */

var newWindow = null;

(
	
	function ($)
	{
	
		$.fn.PK_popup = function (fn, cf)
		{
			
			cf = $.extend({}, $.fn.PK_popup.cf, cf);
			
			this.each
			(
					
				function ()
				{

					var tg = $(this);
					
					tg.bind("PK_popup", fn).bind
					(
							"click",
							function (ev)
							{
								$.fn.PK_popup.popIt(ev, cf, tg);
							}
					);					
					
				}
			);
			
			
			return this;
			
		};
		
		$.fn.PK_popup.cf =
		{
            't' : 'regular',
            'w' : '780',
            'h' : '580',
            'o' : 'noicon'
		};
		
		$.fn.PK_popup.popIt = function (ev, cf, tg)
		{
			
			//set defaults - if nothing in rel attrib, these will be used
			var t = 'standard';
			var w = '780';
			var h = '580';
			var o = 'noicon';
			
			$.fn.PK_popup.openWindow(tg.attr("href"), t, w, h);
			
			// cancel the default link action if pop-up activated
			if (window.event) 
			{
				window.event.returnValue = false;
				window.event.cancelBubble = true;
			} 
			else if (ev) 
			{
				ev.stopPropagation();
				ev.preventDefault();
			}
			
		};
		
		$.fn.PK_popup.openWindow = function (url, t, w, h)
		{
			
			$.fn.PK_popup.closeWindow();
				
			t = t.toLowerCase();
			
			if (t === "fullscreen")
			{
				strWidth = screen.availWidth;
				strHeight = screen.availHeight;
			}
			
			var tools="";
			
			if (t == "standard")
			{
				tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+w+",height="+h+",top=0,left=0";
			}
			
			if (t == "console" || t == "fullscreen")
			{
				tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+w+",height="+h+",left=0,top=0";
			}
			
			newWindow = window.open(url, 'newWin', tools);
			newWindow.focus();
			
		};
		
		$.fn.PK_popup.closeWindow = function()
		{
			if (newWindow != null)
			{
				if (!newWindow.closed)
				{
					newWindow.close();
				}
			}
		};
		
	}
	
)(jQuery);

