/**
*  
*
* this script replace all images 
* that containes the configured class name
* to a Link Images for lightbox  
*
* @category   HD
* @package    HD_Javascript
* @subpackage HD_ImageLinker
* @copyright  Copyright (c) 2010 Heiko Dreßler (http://www.der-heiko.de)
* @license    http://www.dresden-it.de     
* @version    $Id: Heiko Dreßler $
* @author	  Heiko Dreßler, Heiko.@der-heiko.de	
*/

/**
* @var string rel attribute for light box class
*/
var LINK_REL ='lightbox-page';
/**
* @var string CSS classname for images to replace
*/
var IMG_CLASS_TO_REPLACE ='lbox';

/**
* Class Image Linker
*/
HdImageLinker = function()
{
    
    /**
    * link the images
    */
    this.link = function()
    {
        var _imagesToLink = document.getElementsByTagName('IMG');
        if (_imagesToLink.length > 0) {
        var _regEx = new RegExp(IMG_CLASS_TO_REPLACE,'g');
            for (var i=0; i<_imagesToLink.length;i++) {
                var _image = _imagesToLink[i];
                if (_image.className.search(_regEx) !=-1) {
                    var _linkChld = document.createElement('A');
                    var _copyImage= document.createElement('IMG');
                    _copyImage.setAttribute('src',_image.src);
                    _copyImage.setAttribute('width',_image.width);
                    _copyImage.setAttribute('height',_image.height);
                    _copyImage.setAttribute('alt',_image.alt);
                    _linkChld.setAttribute('href',_image.src);
                    _linkChld.setAttribute('title',_image.alt);
                    _linkChld.setAttribute('rel',LINK_REL);
                    _linkChld.appendChild(_copyImage);
                    var pNode = _image.parentNode;
                    pNode.replaceChild(_linkChld,_image);
                    
                }
            }
        }
    }
}