/* Popups v2.0 - ./popup2_doc.js for docs */

var popup = {

	popMe:[],

	Add:function(id, w, h) {popup.popMe.push({'id':id,'w':w,'h':h});},

	Apply:function(id, w, h)
	{
		var links;

		if(id.charAt(0) == '#')
		{
			links = gId(id.slice(1));
		}
		else if(id.charAt(0) == '.')
		{
			links = gClass(document, id.slice(1));
		}
		else
		{
			links = gTag(document, id);
		}

		if(links)
		{
			if(links.length || links.nodeName.toLowerCase() != 'a')
			{
				if(links.length)
				{
					linkList = links;
				}
				else
				{
					linkList = gTag(links, 'a');
				}

				links = [];

				for(i=0, j=linkList.length; i < j; i++)
				{
					var tempNode = linkList[i];

					if(tempNode.nodeName.toLowerCase() == 'a')
					{
						links.push(tempNode);
					}
					else
					{
						var tempList = gTag(tempNode, 'a');

						for(k=0, l=tempList.length; k < l; k++)
						{
							links.push(tempList[k]);
						}
					}
				}
			}
			else
			{
				links = [links];
			}

			for(i = 0, j = links.length; i < j; i++)
			{
				addEvent(links[i], 'click', function(e){return (popup.Go(this.href, w, h, e));});
			}
		}
	},

	Go:function(url, w, h, e)
	{
		var options = 'scrollbars=1,resizable,width='+w+',height='+h;

		window.open(url, 'popup', options);
		stopDef(e);
	},

	Init:function()
	{
		for(i = 0, j = popup.popMe.length; i < j; i++)
		{
			var id = popup.popMe[i];

			popup.Apply(id.id, id.w, id.h);
		}
	}
}

addEvent(window, 'load', popup.Init);
