var OSP_SHADOWBOX_CLASS = 'osp_thumb';


function OSP_SetupShadowbox(options)
{
	if ( !options )
	{
		options = new Object();
	}

	var thumbs = getElementsByClass(OSP_SHADOWBOX_CLASS + '(_.+)*');
	var id = thumbs.length;

	for ( var i = 0; i < thumbs.length; i++ )
	{
		// Gallery property
		var matches;
		if ( matches = thumbs[i].className.match(new RegExp('^' + OSP_SHADOWBOX_CLASS + '(_.+)*$', '')) )
		{
			options = jQuery.extend(options, new Object({
				'gallery' : matches[1]
			}));
		}

		var a_node = null;

		// This is a link node
		if ( thumbs[i].tagName == 'A' )
		{
			a_node = $(thumbs[i]);
		}
		// This is NOT a link node
		else
		{
			// Try to get link node by parsing parents
			a_node = $(thumbs[i]).parent('a');

			// NO link node exists
			if ( !a_node.length )
			{
				$(thumbs[i]).wrap('<a id="osp_thumb_' + id + '" href="' + $(thumbs[i]).attr('src') + '" title="' + $(thumbs[i]).attr('alt') + '"></a>');
				a_node = $('#osp_thumb_' + id);
				id++;
			}
		}

		if ( a_node )
		{
			Shadowbox.setup(a_node, options);
		}
	}
}

