jQuery.fn.blackbox = function(settings){    
    var tmpClass = "thickbox";
    
    var blackBoxCondition =
	'a.' + tmpClass + '[href$=".jpg"], ' +
  'a.' + tmpClass + '[href$=".bmp"], ' +
	'a.' + tmpClass + '[href$=".gif"], ' +
	'a.' + tmpClass + '[href$=".png"], ' +
	'a.' + tmpClass+ '[href$="/image"]';

    function addEnlargeLink(element){
        var theclone = $(element).find(blackBoxCondition).clone();
        theclone.attr('class', 'enlarge thickbox').html('<span>Enlarge image</span>');
        
        //prevent duplicated links
        $(element).find(blackBoxCondition).parent().parent().find('.image_entities a').remove();
        
        //add enlarge link to footer
        $(element).find(blackBoxCondition).parent().parent().find('.image_entities').append(theclone);
    }
    
   
    
    var doBlackbox = function(){
    
        addEnlargeLink($(this));
        
       
    };
    
    return this.each(doBlackbox);
    
};

$(document).ready(function(){
    jQuery('.blackbox').blackbox();

    jQuery('.blackbox > div:first-child a img:first-child').addClass('blackbox-thumbnail');
    
    var imgUrl = "./files/gfx/blackbox/zoom.png";
    
    if (jQuery.browser.msie && jQuery.browser.version.substring(0, 1) == '6') { //IE 6
        imgUrl = "./files/gfx/blackbox/zoom_ie6.png";
    }
    
    jQuery('<img class="zoom" src="' + imgUrl + '" alt="enlarge image" title="" />').appendTo('.blackbox a');
    
    jQuery('.zoom').css('opacity', '0');
    jQuery('a.enlarge img.zoom').remove();
		jQuery('div.quotation a img.zoom').remove();
    
    jQuery('.enlarge').hover(function(){
        jQuery(this).parent('div').prev('div').children('a').children('img.zoom').fadeTo(250, 0.75);
    }, function(){
        jQuery(this).parent('div').prev('div').children('a').children('img.zoom').fadeTo(250, 0);
    });
    
    jQuery('.blackbox a').hover(function(){
        jQuery(this).children('img.zoom').fadeTo(250, 0.75);
    }, function(){
        jQuery(this).children('img.zoom').fadeTo(250, 0);
    });
});
