/*
 * A script to provide image viewer using Lightbox
 *
 */
    $(document).ready(function(){

	$("td").filter(".text").find("img").each(function(){
    

    var img = $(this).get(0);

    var w = img.width;
    var h = img.height;

	var title = img.title;
	var alt = img.alt;

	if (alt.length > 0 && title.length == 0)
		title = alt;

        var maxsize = 600;
        var thumbsize = 300;

        if (w > maxsize || h > maxsize) {
        
            $(this).wrap("<div />");

            var ratio = (w > maxsize)? w / thumbsize : h / thumbsize;

            var wt = w / ratio;
            var ht = h / ratio;
            
            $(this).replaceWith("<a rel='lightbox' title='"+title+"' href='"
                + $(this).attr("src")
                + "'><img border='0' src='"
                + $(this).attr("src")
                + "' width='"+wt+"' height='"+ht+"'></a>");
        }
            });

    $('a[rel=lightbox]').lightBox();

    });

