$(function(){

    /**
     *  launches the lightbox with the specified media content item
     *
     *  @param integer contentId
     *
     */

    function launchMediaLightbox( contentId ) {
        var width = 540;
        var height = 340;
        var content = $( '<iframe frameborder="0" />' )
                        .attr({
                            width: width,
                            height: height
                        })
                        .css({
                            border: 'none'
                        });

        lightbox.show( content, width, height );
        // load the url after cause it doesn't seem to work in
        // IE6 otherwise... :-/
        content.attr({
            src: 'http://www.tenantservicesauthority.org/server.php?show=ConMediaFile.' +contentId+ '&outputFormat=lightbox'
        });

    }

    /**
     *  attach lightbox links to media relation bars
     *
     */

    function attachToFlashVideo() {
        $( 'div.flashVideo' ).each(function(i,relation) {
            $.each( $(relation).attr('class').split(' '), function(i,className) {
                var parts = className.match( /^ConMediaFile_(\d+)$/ );
                if ( parts )
					
                    $( 'a', relation )
                        .attr({ href: 'javascript:;' })
                        .click(function() {
                            launchMediaLightbox( parts[1] );
                            return false;
                        });
            });

        });

    }
	
    attachToFlashVideo();

});