function openImageSet(thisIndex)
{

    if (barcode.allSets[thisIndex].isOpen == false)
    {
        barcode.allSets[thisIndex].isOpen = true;
        $thisLI = $('#barcode li').eq(thisIndex).css({
            background: barcode.activeColor
        });
        var leftPosPointer = 0;
        $('img', $thisLI).each(function()
        {
            var $thisImg = $(this);
            $thisImg.attr('src', $thisImg.attr('realsrc'));
            var additionalWidth = Number($thisImg.attr('width') + barcode.imageSpacing);
            barcode.currentLength += additionalWidth;
            leftPosPointer += additionalWidth;
            barcode.el.css({
                width: barcode.currentLength
            });
            if (barcode.canOpen == true)
            {
                $thisLI.animate({
                    width: leftPosPointer
                }, 600, function()
                {
                    $thisImg.fadeIn("slow");
                });
            }
            else
            {
                $thisLI.stop();
            }

        });

        // update _x of each image for all images at the right of the clicked one
        for (var v = 0; v < barcode.allSets.length; v++)
        {
            if (barcode.allSets[v].ID > thisIndex)
            {
                barcode.allSets[v]._x += barcode.allSets[thisIndex].fullWidth;
            }
        }
    }
    // //$.log('image set: ' + thisIndex);
    barcode.move(thisIndex);
}


function closeImageSet(thisIndex)
{
    if (barcode.allSets[thisIndex].isOpen == true)
    {

        $thisLI = $('#barcode li').eq(thisIndex);
        $thisLI.stop(true, true);
        var newWidth = barcode.allSets[thisIndex].smallWidth;
        var oldWidth = barcode.allSets[thisIndex].fullWidth;
        //$.log('barcode oldWidth = ' + oldWidth);
        var deltaWidth = oldWidth - newWidth;

        barcode.currentLength -= deltaWidth;
        //$thisLI.width(newWidth);
        $thisLI.animate({ width: newWidth }, 600);
        $('img', $thisLI).fadeOut('fast');

        for (var v = 0; v < barcode.allSets.length; v++)
        {
            if (barcode.allSets[v].ID > thisIndex)
            {
                barcode.allSets[v]._x -= barcode.allSets[thisIndex].fullWidth;
            }

        }
        barcode.el.css({ width: barcode.currentLength });
        barcode.allSets[thisIndex].isOpen = false;
        var newLeft = barcode.el.offset().left + (barcode.allSets[thisIndex]._x);

        var newLeft = (($(window).width() - barcode.currentLength) / 2) - barcode.allSets[thisIndex]._x;

        
        
        $.log('CLOSING: new left = '+newLeft);
        barcode.el.animate({left: newLeft}, 'fast', function() { barcode.showArrows(); });

    }
}


jQuery.fn.defuscate = function()
{
    return this.each(function()
    {
        var email = String($(this).html()).replace(/\s*\(.+\)\s*/, "@");
        $(this).before('<a href="mailto:' + email + '">' + email + "</a>").remove();
    });

};

jQuery.log = function(message)
{
    var mymessage = '';
    if (typeof message == 'array')
    {
        for (prop in message)
        {
            mymessage = prop + '=' + message[prop];
        }
    }
    else
    {
        mymessage = message;
    }
    if (window.console)
    {
        console.log(mymessage);
    }
    else
    {
        // / alert(message);
    }
};
