/*
 *	Checks to see if any links on the page have a target="iframe_linkout" and if so
 *  it attaches the special "open in lightbox" behavior to them 
 */

// on page load events
Event.observe(window, 'load', function() {
	
    $$('a[target="lightbox_iframe"]').each( function(iframe_link) {

        var this_lightbox; // stores local reference to lightbox object
        
        // first check the LIGHTBOXES hash to see if one exists for this href already
        // (multiple links can point to the same lightbox and we don't want to create duplicates)
        // The lightbox hash is indexed by unique url strings.
        
        if (LIGHTBOXES.get(iframe_link.href)) {
            this_lightbox = LIGHTBOXES.get(iframe_link.href);
        } else {
            this_lightbox = new Lightbox(iframe_link.href, {content_type:'iframe', sizing:'full'});
            // this automatically add the new lightbox to the LIGHTBOXES hash.
        }
        
        // attach click event to open the lightbox. fallback behavior if this script fails should
        // open a new window with target="lightbox_iframe"
        iframe_link.observe('click', function(event) {
            Event.stop(event); // stop the href from resolving normally
            this_lightbox.open();
        });
    });
});
