$j = jQuery.noConflict();

re = new RegExp('<img.+src=[\'"].*flickr.com\/.*\/([^\'"]+)_.*([^(_t|)])\.jpg[\'"].*>', 'i');

toolbar_div = "";

$j(document).ready(function () {
	
    toolbar_div = $j("<div class='flickr-toolbar'></div>");
    $j('body').append(toolbar_div);

    flickr_images = $j("img[src *='flickr']");

    $j(flickr_images).each(function () {

        $j(this).hover(function () {

            img_html = $j('<div>').append($j(this).clone()).remove().html()

            matches = re.exec(img_html);

            if (matches) {
                show_toolbar(matches[1], $j(this).offset());
            }

        }, function () {
            $j('.flickr-toolbar').hide();
        })
    })

})


function show_toolbar(flickr_id, image_offset) {

    toolbar_top = parseInt(image_offset.top) + 10;
    toolbar_left = parseInt(image_offset.left) + 10;

    toolbar_html = "<a href='" + pluginurl + "/flickr-foto-info/map.php?api_key=" + api_key + "&flickr_id=" + flickr_id + "&TB_iframe=true&height=400&width=600' class='thickbox' ><img title='Location' alt='Location' src='" + pluginurl + "/flickr-foto-info/images/red_marker.16.png' ></a>"
    toolbar_html += "<a href='" + pluginurl + "/flickr-foto-info/exif.php?api_key=" + api_key + "&flickr_id=" + flickr_id + "&TB_iframe=true&height=400&width=600' class='thickbox' ><img title='Exif' alt='Exif' src='" + pluginurl + "/flickr-foto-info/images/camera1.png' ></a>"
    toolbar_html += "<a href='" + pluginurl + "/flickr-foto-info/info.php?api_key=" + api_key + "&flickr_id=" + flickr_id + "&TB_iframe=true&height=400&width=600' class='thickbox' ><img title='Information' alt='Info' src='" + pluginurl + "/flickr-foto-info/images/information.png' ></a>"
    toolbar_html += "<a href='" + pluginurl + "/flickr-foto-info/help.php?api_key=" + api_key + "&flickr_id=" + flickr_id + "&TB_iframe=true&height=250&width=600' class='thickbox' ><img width='16' title='What is this' alt='What is this' src='" + pluginurl + "/flickr-foto-info/images/help.gif' ></a>"

    $j(toolbar_div).html(toolbar_html).css({
        left: toolbar_left + 'px',
        top: toolbar_top + 'px'
    });

    $j(toolbar_div).show();

    //Prevent the toolbar flickr when hovered upon
    $j(toolbar_div).hover(function () {
        $j(this).show()
    }, function () {
        $j(this).hide()
    });

    tb_init('a.thickbox');

}