// Ask Developments Image gallery
var currentImage = 1;
var show;
var first = true;
(function(jQuery) {
    jQuery.delayedTask = function(fn, scope, args) {
        var nTimeoutId = null; this.delay = function(time, newFn, newScope, newArgs) {
            if (nTimeoutId)
            { clearTimeout(nTimeoutId); }
            fn = newFn || fn; scope = newScope || scope; args = newArgs || args; nTimeoutId = setTimeout(function() { fn.call(scope, args); }, time);
        }
        this.cancel = function() {
            if (nTimeoutId)
            { clearTimeout(nTimeoutId); nTimeoutId = null; } 
        } 
    }
    if (!jQuery.fn.stop) { jQuery.fn.stop = function() { this.each(function() { jQuery.dequeue(this, "fx"); }); return this; }; } 
})(jQuery); function hImgRes(src)
{ this.src = src; this.loaded = false; this.loading = false; this.toString = function() { return this.src }; }
jQuery.dmxGallery = { first: true, aMessages: { missingList: 'The list with images is missing' }, bDebug: true, build: function(hOptions) {
    return this.each(function() {
        var hG = this; if (!this.id)
        { this.id = 'dmxZoneGallery_' + (jQuery.dmxGallery.counter++); }
        var sId = this.id;
        var hDMXGalleryOptions = {
            width: 500,
            height: 380,
            containerTag: 'div',
            containerClass: 'dmxGallery',
            imageHolderClass: 'dmxImageHolder',
            prevLinkText: 'Previous',
            showLinkText: 'Show',
            nextLinkText: 'Next',
            playLinkText: 'Play',
            pauseLinkText: 'Pause',
            prevLinkClass: 'dmxPrevious',
            prevLinkClassDisabled: "dmxPreviousDisabled",
            nextLinkClass: 'dmxNext',
            nextLinkClassDisabled: "dmxNextDisabled",
            playLinkClass: 'dmxPlay',
            showLinkClass: 'dmxShow',
            pauseLinkClass: 'dmxPause',
            swapImageClass: 'dmxSwap',
            thumbWidth: 95,
            thumbHeight: 80,
            thumbPadding: 5,
            thumbHolderHeight: 80,
            thumbHolderWidth: 'auto',
            thumbHolderPosition: 'right',
            thumbHolderHorizontal: false,
            thumbHolderVertical: true,
            thumbShowOnHover: false,
            thumbListHidden: true,
            captionPosition: 'top',
            playerDelay: 3,
            autoPlay: false,
            showInfoMessage: false,
            autosize: true,
            loaded: 0,
            messageHidden: true,
            captionOpacity: 40,
            imgIndex: 0,
            preloadTreshold: 2,
            allPreloaded: false,
            leftThumbnailListPosition: 0
        }



        if (hOptions)
        { hG.options = jQuery.extend(hDMXGalleryOptions, hOptions); }
        jQuery(this).attr('tabIndex', -1); var hList = jQuery('ul', this); if (hList.length == 0)
        { jQuery.dmxGallery.debug(jQuery.dmxGallery.aMessages.missingList); return; }
        var hHolder = jQuery('.' + hDMXGalleryOptions.imageHolderClass, this); if (hHolder.length == 0)
        { hHolder = jQuery('<div class="' + hDMXGalleryOptions.imageHolderClass + '" />').append(jQuery('ul', this)).appendTo(jQuery(this)); }
        jQuery(this).height(hDMXGalleryOptions.height + 'px'); jQuery(this).width(hDMXGalleryOptions.width + 'px'); hG.thumbList = []; hG.imageList = []; hG.linkList = []; jQuery(hHolder).find('ul').css('display', 'none'); jQuery(hHolder).find('ul li').each(function(nI) {
            var hImg = jQuery(this).find('.image'); hG.imageList.push(new hImgRes(hImg.attr('src'))); var hLink = hImg.parent().get(0); if (hLink && hLink.tagName && hLink.tagName.toUpperCase() == 'A') { hG.linkList.push(hLink); }
            else { hG.linkList.push(null); }
            jQuery('img', this).remove();
        })

        var hThumbList = jQuery('#' + sId + '_thumb'); if (hThumbList.length > 0) {
            jQuery(hThumbList).find('ul li').each(function(nI)
            { hG.thumbList.push(new hImgRes(jQuery(this).find('img').attr('src'))); })
            jQuery(hThumbList).empty();
        }
        else
        { hG.thumbList = hG.imageList; }
        hThumbList = jQuery.dmxGallery.buildThumbnailList(hG); jQuery.dmxGallery.buildMessage(hG); hG.options.messageHide = new jQuery.delayedTask(function() { jQuery.dmxGallery.doHideMessage(hG) })
        jQuery.dmxGallery.buildImageHolders(hG); jQuery.dmxGallery.buildCaption(hG); jQuery.dmxGallery.buildGalleryNavigation(hG); jQuery.dmxGallery.buildWaiting(hG); jQuery("." + hG.options.prevLinkClass).addClass(hG.options.prevLinkClassDisabled);



        window.setTimeout(function() { jQuery.dmxGallery.showImage(hG, 0); }, 10); jQuery.dmxGallery.showMessage(hG, 'loading images...'); jQuery.dmxGallery.hideMessage(hG); hG.options.player = new jQuery.delayedTask(function() { jQuery.dmxGallery.nextImage(hG); jQuery.dmxGallery.play(hG) })
        this.focus(); jQuery(hG).keydown(function(event) {
            jQuery.event.fix(event); if (event.keyCode == 37)
            { jQuery.dmxGallery.previousImage(hG); }
            if (event.keyCode == 39)
            { jQuery.dmxGallery.nextImage(hG); }
        }); hG.options.thumbsHide = new jQuery.delayedTask(function() { jQuery.dmxGallery.hideThumbnailList(hG); })
        hG.options.thumbsShow = new jQuery.delayedTask(function() { jQuery.dmxGallery.showThumbnailList(hG); })
        jQuery(hG).hover(function(event) {
            jQuery.event.fix(event); if (hG.options.thumbShowOnHover)
            { hG.options.thumbsHide.cancel(); hG.options.thumbsShow.delay(100); }
        }, function(event) {
            jQuery.event.fix(event); if (hG.options.thumbShowOnHover && !hG.options.swapping)
            { hG.options.thumbsShow.cancel(); hG.options.thumbsHide.delay(400); }
        })
        jQuery(hThumbList).keydown(function(event) {
            jQuery.event.fix(event); if (event.keyCode == 37)
            { jQuery.dmxGallery.scrollThumbnailList(hG, 'left'); event.preventDefault(); event.stopPropagation(); return false; }
            if (event.keyCode == 39)
            { jQuery.dmxGallery.scrollThumbnailList(hG, 'right'); event.preventDefault(); event.stopPropagation(); return false; }
        }); jQuery(this).bind('focus', function() { jQuery(this).addClass('dmxGalleryFocused') }); if (hG.options.autoPlay)
        { jQuery.dmxGallery.play(hG); }
    });



}, pngFix: function(elm)
{ if (jQuery.browser.msie && jQuery.browser.version < 7) { if (elm.currentStyle.backgroundImage.indexOf('.png') != -1) { elm.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + elm.currentStyle.backgroundImage.split('\"')[1] + ", sizingMethod='crop')"; elm.runtimeStyle.backgroundImage = "none"; } else if (elm.tagName == 'IMG' && elm.src.indexOf('.png') != -1) { elm.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + src + ", sizingMethod='scale')"; elm.src = "transparent.gif"; } } },
    buildGalleryNavigation: function(hGallery) {
        var hG = hGallery;
        var hImgCon = jQuery(hG).find('.imageMainContainer:first');

        var prev = jQuery('<a href="javascript:void(0);" class="' + hG.options.prevLinkClass + '" />').click(function() { jQuery(hG).focus(); jQuery.dmxGallery.previousImage(hG) }).appendTo(hImgCon).append(jQuery('<span />').html(hG.options.prevLinkText));
        var next = jQuery('<a href="javascript:void(0);" class="' + hG.options.nextLinkClass + '" />').click(function() { jQuery(hG).focus(); jQuery.dmxGallery.nextImage(hG) }).appendTo(hImgCon).append(jQuery('<span />').html(hG.options.nextLinkText));

        if (jQuery('ul', '#' + hG.id + '_thumb').width() <= jQuery(hG).width()) {jQuery("." + hG.options.nextLinkClass).addClass(hG.options.nextLinkClassDisabled); };

        var play = jQuery('<a href="javascript:void(0);" class="' + hG.options.playLinkClass + '" />').click(function() { jQuery(hG).focus(); jQuery.dmxGallery.play(hG) }).appendTo(hImgCon).append(jQuery('<span />').html(hG.options.playLinkText));
        show = jQuery('<a rel="lightbox[button_set]" class="' + hG.options.showLinkClass + '" />').appendTo(hImgCon).append(jQuery('<span />').html(hG.options.showLinkText));
        var pause = jQuery('<a href="javascript:void(0);" class="' + hG.options.pauseLinkClass + '" />').css({ display: 'none' }).click(function() { jQuery(hG).focus(); jQuery.dmxGallery.pause(hG) }).appendTo(hImgCon).append(jQuery('<span />').html(hG.options.pauseLinkText)); jQuery.dmxGallery.pngFix(prev.get(0)); jQuery.dmxGallery.pngFix(show.get(0)); jQuery.dmxGallery.pngFix(next.get(0)); jQuery.dmxGallery.pngFix(play.get(0)); jQuery.dmxGallery.pngFix(pause.get(0));
    }, buildImageHolders: function(hGallery) {
        var hG = hGallery; var sId = hGallery.id; var hThumbList = jQuery('#' + sId + '_thumb'); var nLeft = 0, nTop = 0; var nWidth = jQuery(hG).width(); var nHeight = jQuery(hG).height(); var mcCss = { left: parseInt(jQuery(hG).css('paddingLeft')) || 0, top: parseInt(jQuery(hG).css('paddingTop')) || 0, right: parseInt(jQuery(hG).css('paddingRight')) || 0, bottom: parseInt(jQuery(hG).css('paddingBottom')) || 0, overflow: 'hidden', position: 'absolute' }; if (!hG.options.thumbShowOnHover) {
            switch (hG.options.thumbHolderPosition) {
                case 'left': mcCss.left += hG.options.thumbHolderWidth
+ parseInt(hThumbList.css('paddingLeft')) || 0
+ parseInt(hThumbList.css('paddingRight')) || 0
+ parseInt(hThumbList.css('marginLeft')) || 0
+ parseInt(hThumbList.css('marginRight')) || 0; break; case 'right': mcCss.right += hG.options.thumbHolderWidth
+ parseInt(hThumbList.css('paddingLeft')) || 0
+ parseInt(hThumbList.css('paddingRight')) || 0
+ parseInt(hThumbList.css('marginLeft')) || 0
+ parseInt(hThumbList.css('marginRight')) || 0; break; case 'top': mcCss.top += hG.options.thumbHolderHeight
+ parseInt(hThumbList.css('paddingTop')) || 0
+ parseInt(hThumbList.css('paddingBottom')) || 0
+ parseInt(hThumbList.css('marginTop')) || 0
+ parseInt(hThumbList.css('marginBottom')) || 0; break; case 'bottom': mcCss.bottom += hG.options.thumbHolderHeight
+ parseInt(hThumbList.css('paddingTop')) || 0
+ parseInt(hThumbList.css('paddingBottom')) || 0
+ parseInt(hThumbList.css('marginTop')) || 0
+ parseInt(hThumbList.css('marginBottom')) || 0; break;
            }
        }
        var mainCont = jQuery('<div class="imageMainContainer" id="' + sId + '_c0" />').appendTo(hGallery).css(mcCss);
        var hIC1 = jQuery('<div class="imageContainer" id="' + sId + '_1" />').appendTo(mainCont).hide();
        var hIC2 = jQuery('<div class="imageContainer" id="' + sId + '_2" />').appendTo(mainCont).hide();
        var band = jQuery('<div class="band"></div>').appendTo(mainCont);
        var bandul = jQuery('<ul></ul>').appendTo(mainCont);

        var prev = jQuery('<li></li>').click(function() { jQuery(hG).focus(); jQuery.dmxGallery.previousImage(hG) }).appendTo(bandul).append(jQuery('<a href="javascript:void(0);" class="prevLink" />').html(hG.options.prevLinkText));

        var medium = jQuery('<li></li>').click(function() { jQuery(hG).focus();}).appendTo(bandul); medium.addClass('navInfo').html(jQuery.dmxGallery.navInfo(currentImage, hG.linkList.length));
        var next = jQuery('<li></li>').click(function() { jQuery(hG).focus(); jQuery.dmxGallery.nextImage(hG) }).appendTo(bandul).append(jQuery('<a href="javascript:void(0);" class="nextLink" />').html(hG.options.nextLinkText));

        if ((jQuery.browser.msie && jQuery.browser.version < 7) || (jQuery.browser.msie && !jQuery.boxModel)) {
            var wCorrection = 'this.parentNode.style.pixelWidth - (parseInt(this.parentNode.currentStyle.borderTopWidth) || 0) - (parseInt(this.parentNode.currentStyle.borderBottomWidth) || 0) - this.style.pixelTop - this.style.pixelBottom'; var hCorrection = 'this.parentNode.style.pixelHeight - (parseInt(this.parentNode.currentStyle.borderTopWidth) || 0) - (parseInt(this.parentNode.currentStyle.borderBottomWidth) || 0) - this.style.pixelTop - this.style.pixelBottom'; if (hG.options.thumbHolderVertical) {
                if (jQuery.boxModel)
                { wCorrection = 'this.parentNode.style.pixelWidth - (parseInt(this.currentStyle.borderLeftWidth) || 0) - (parseInt(this.currentStyle.borderRightWidth) || 0)'; if (!hG.options.thumbShowOnHover) wCorrection += ' - ' + hG.options.thumbHolderWidth; hCorrection = 'this.parentNode.style.pixelHeight - (parseInt(this.currentStyle.borderBottomWidth) || 0) - (parseInt(this.currentStyle.borderTopWidth) || 0)'; }
                hThumbList.get(0).style.setExpression('height', hCorrection);
            }
            else {
                if (jQuery.boxModel)
                { wCorrection = 'this.parentNode.style.pixelWidth - (parseInt(this.currentStyle.borderLeftWidth) || 0) - (parseInt(this.currentStyle.borderRightWidth) || 0)'; hCorrection = 'this.parentNode.style.pixelHeight - (parseInt(this.currentStyle.borderBottomWidth) || 0) - (parseInt(this.currentStyle.borderTopWidth) || 0)'; if (!hG.options.thumbShowOnHover) hCorrection += ' - ' + hG.options.thumbHolderHeight; }
                hThumbList.get(0).style.setExpression('width', wCorrection);
            }
            mainCont.get(0).style.setExpression('width', wCorrection); mainCont.get(0).style.setExpression('height', hCorrection);
        };
    }, buildWaiting: function(hGallery)
    { jQuery('<div class="dmxWaiting" />').css({ width: jQuery(hGallery).width(), height: jQuery(hGallery).height() }).appendTo(hGallery); }, showWaiting: function(hGallery)
    { jQuery('.dmxWaiting', hGallery).css({ display: 'block' }); jQuery('.dmxWaiting', hGallery).animate({ opacity: 1 }); }, hideWaiting: function(hGallery)
    { jQuery('.dmxWaiting', hGallery).animate({ opacity: 0 }, 'fast', 'linear', function() { jQuery('.dmxWaiting', hGallery).css({ display: 'none' }) }); }, buildMessage: function(hGallery)
    { var mOpac = 0.5; if (!hGallery.options.showInfoMessage) mOpac = 0; var hM = jQuery('<div class="message" />').css({ opacity: mOpac }).appendTo(hGallery); hM.css({ top: jQuery(hGallery).height() - hM.height() }); }, showMessage: function(hGallery, sMessage) {
        if (hGallery.options.showInfoMessage) {
            var hM = jQuery(hGallery).find('div.message'); var nH = jQuery(hGallery).height(); var nMH = hM.height(); if (hGallery.options.messageHidden)
            { hM.animate({ top: nH - nMH, opacity: 0.5 }, 'slow'); }
            hM.text(sMessage); hGallery.options.messageHide.cancel(); hGallery.options.messageHidden = false;
        }
    }, hideMessage: function(hGallery) {
        if (hGallery.options.messageHide)
            hGallery.options.messageHide.delay(1000);
    }, doHideMessage: function(hGallery)
    { var hM = jQuery(hGallery).find('div.message'); var nH = jQuery(hGallery).height(); jQuery(hM).animate({ top: nH, opacity: 0 }, 'slow'); hGallery.options.messageHidden = true; },

    buildCaption: function(hG) {
        var hImgCon = jQuery(hG).find('.imageMainContainer:first');
        var hCaption = jQuery('<div class="imageCaption" />').appendTo(jQuery(".image-description").eq(0)); var nCH = hCaption.height(); var nCTop; if (hG.options.captionPosition == 'bottom')
        { nCTop = jQuery(hG).height(); }
        else
        { nCTop = -jQuery(hCaption).height(); }
        var nLeft = 0; hCaption.css({ top: nCTop, left: nLeft, width: '100%', opacity: hG.options.captionOpacity / 100 });
    },


    showCaption: function(hG) {
        if (!jQuery.dmxGallery.captionHidden(hG))
        { jQuery.dmxGallery.hideCaption(hG, true); return; }
        var hCaption = jQuery('div.imageCaption', jQuery(".image-description").eq(0)); var hElements = jQuery(hG).find('div.dmxImageHolder').find('ul li'); if (hElements.eq(hG.options.imgIndex).find('h3').length > 0 || hElements.eq(hG.options.imgIndex).find('p').length > 0) {
            var nH = jQuery(hG).height(); hCaption.find('h3').remove(); hCaption.find('p').remove(); hElements.eq(hG.options.imgIndex).find('h3').clone().appendTo(hCaption); hElements.eq(hG.options.imgIndex).find('p').clone().appendTo(hCaption); jQuery(hCaption).css({ display: 'block' })
            var nCTop; if (hG.options.captionPosition == 'bottom') {
                nCTop = nH + hCaption.height(); if (!hG.options.thumbShowOnHover) {
                    if (hG.options.thumbHolderHorizontal)
                    { nCTop -= hG.options.thumbHolderHeight; }
                }
            }
            else
            { nCTop = -hCaption.height(); }
            hCaption.css({ 'top': nCTop }); if (hG.options.captionPosition == 'bottom')
            { nCTop -= 2 * hCaption.height(); }
            else
            { nCTop = 0; }
            window.setTimeout(function() { hCaption.animate({ top: nCTop, opacity: hG.options.captionOpacity / 100 }, 'fast') }, 100);
        }
    }, hideCaption: function(hG, bShow) {
        var hCaption = jQuery('div.imageCaption', jQuery(".image-description").eq(0)); var nCTop; if (hG.options.captionPosition == 'bottom')
        { nCTop = jQuery(hG).height(); }
        else
        { nCTop = -jQuery(hCaption).height(); }
        if (bShow)
        { hCaption.animate({ top: nCTop, opacity: 0 }, 'fast', 'linear', function() { jQuery(hCaption).css({ display: 'none' }); jQuery.dmxGallery.showCaption(hG) }); }
        else
        { hCaption.animate({ top: nCTop, opacity: 0 }, 'fast'); }
    },
    captionHidden: function(hG) {
    var hCaption = jQuery('div.imageCaption', jQuery(".image-description").eq(0));
        var nH = jQuery(hG).height();
        var nTop = parseInt(hCaption.css('top')) || 0;
        if (jQuery(hCaption).css('display') == 'none' || nH == nTop)
        { return true; }
        return false;
    }, buildThumbnailList: function(hGallery) {
        var hG = hGallery; var sId = hG.id; var nW = jQuery(hG).width(); var nH = jQuery(hG).height(); var hDim = jQuery(hG).offset({ border: true, padding: true }); var hTT = hDim.top + nH - hG.options.thumbHolderHeight; if (hG.options.thumbHolderPosition == 'top' || hG.options.thumbHolderPosition == 'bottom')
        { hG.options.thumbHolderHorizontal = true; hG.options.thumbHolderVertical = false; }
        var hThumbList = jQuery('#' + sId + '_thumb'); if (hThumbList.length == 0)
        { hThumbList = jQuery('<div class="dmxThumbList" id="' + sId + '_thumb" />'); }
        hThumbList.css({ left: 'auto', top: 'auto', right: 'auto', bottom: 'auto' }); if (hG.options.thumbHolderVertical)
        { hThumbList.addClass('dmxThumbListVertical'); }
        hG.options.thumbHolderHeight = hG.options.thumbHeight + 2 * hG.options.thumbPadding; hG.options.thumbHolderWidth = hG.options.thumbWidth + 2 * hG.options.thumbPadding; var tlLeft = parseInt(jQuery(hG).css('paddingLeft')) || 0; var tlTop = parseInt(jQuery(hG).css('paddingTop')) || 0; var tlRight = parseInt(jQuery(hG).css('paddingRight')) || 0; var tlBottom = parseInt(jQuery(hG).css('paddingBottom')) || 0; switch (hG.options.thumbHolderPosition)
        { case 'top': hThumbList.css({ right: tlRight, left: tlLeft, top: tlTop, width: 'auto', height: hG.options.thumbHolderHeight }); break; case 'bottom': hThumbList.css({ right: tlRight, left: tlLeft, bottom: tlBottom, width: 'auto', height: hG.options.thumbHolderHeight }); break; case 'left': hThumbList.css({ top: tlTop, left: tlLeft, bottom: tlBottom, width: hG.options.thumbHolderWidth, height: 'auto' }); break; case 'right': hThumbList.css({ top: tlTop, right: tlRight, bottom: tlBottom, width: hG.options.thumbHolderWidth, height: 'auto' }); break; }
        var hUL = jQuery('<ul />'); hThumbList.append(hUL).appendTo(hG); var nTW = 0; var nTH = 0; jQuery.each(hG.thumbList, function(nI, hImage) {
            var hItem = jQuery('<li />').css({ width: hG.options.thumbWidth, height: hG.options.thumbHeight, margin: hG.options.thumbPadding, display: 'inline' }); var hLink = jQuery('<a href="javascript:void(0);" />').css({ width: hG.options.thumbWidth, height: hG.options.thumbHeight }).click(function() { jQuery.dmxGallery.showImage(hG, nI); return false; }).appendTo(hItem); hItem.appendTo(hUL); if (jQuery.boxModel) {
                hLink.css({ width: hG.options.thumbWidth
- parseInt(hLink.css('borderLeftWidth')) || 0
- parseInt(hLink.css('borderRightWidth')) || 0, height: hG.options.thumbHeight
- parseInt(hLink.css('borderTopWidth')) || 0
- parseInt(hLink.css('borderBottomWidth')) || 0
                });
            } else { hLink.css({ width: hG.options.thumbWidth, height: hG.options.thumbHeight }); }
            hLink.hover(function() {
                var theLink = this; window.setTimeout(function() {
                    if (jQuery) {
                        if (jQuery.boxModel) {
                            jQuery(theLink).css({ width: hG.options.thumbWidth
- parseInt(hLink.css('borderLeftWidth')) || 0
- parseInt(hLink.css('borderRightWidth')) || 0, height: hG.options.thumbHeight
- parseInt(hLink.css('borderTopWidth')) || 0
- parseInt(hLink.css('borderBottomWidth')) || 0
                            });
                        } else { jQuery(theLink).css({ width: hG.options.thumbWidth, height: hG.options.thumbHeight }); }
                    }
                }, 1);
            }, function() {
                var theLink = this; window.setTimeout(function() {
                    if (jQuery) {
                        if (jQuery.boxModel) {
                            jQuery(theLink).css({ width: hG.options.thumbWidth
- parseInt(hLink.css('borderLeftWidth')) || 0
- parseInt(hLink.css('borderRightWidth')) || 0, height: hG.options.thumbHeight
- parseInt(hLink.css('borderTopWidth')) || 0
- parseInt(hLink.css('borderBottomWidth')) || 0
                            }); void(0);
                        } else { jQuery(theLink).css({ width: hG.options.thumbWidth, height: hG.options.thumbHeight }); void(0); }
                    }
                }, 1);
            }); var hGImage = jQuery('<img />'); hGImage.load(function() { hImage.loaded = true; hG.options.loaded++; jQuery.dmxGallery.showMessage(hG, 'loaded ' + hG.options.loaded + ' images'); jQuery.dmxGallery.hideMessage(hG); hItem.css("backgroundImage", 'url( "' + jQuery(this).attr('src') + '" )'); hItem.css("backgroundPosition", 'center center'); }).attr('src', hImage.toString()); nTW += hG.options.thumbWidth + 2 * hG.options.thumbPadding; nTH += hG.options.thumbHeight + 2 * hG.options.thumbPadding;
        }); if (hG.options.thumbHolderVertical)
            hUL.css({ height: nTH, left: 0, top: 0 }); else
            hUL.css({ width: nTW, left: 0, top: 0 });



        var leftElm = jQuery('<a href="javascript:void(0);" class="' + hG.options.prevLinkClass + '" />').hover(function(event)
        { jQuery.dmxGallery.scrollThumbnailList(hG, 'left'); event.preventDefault(); event.stopPropagation(); return false; }, function(event) { }).appendTo(hThumbList).append(jQuery('<span />').html(hG.options.prevLinkText));
        var rightElm = jQuery('<a href="javascript:void(0);" class="' + hG.options.nextLinkClass + '" />').hover(function(event)
        { jQuery.dmxGallery.scrollThumbnailList(hG, 'right'); event.preventDefault(); event.stopPropagation(); return false; }, function(event) { }).appendTo(hThumbList).append(jQuery('<span />').html(hG.options.nextLinkText)); jQuery.dmxGallery.pngFix(leftElm.get(0)); jQuery.dmxGallery.pngFix(rightElm.get(0)); return hThumbList;
    }, hideThumbnailList: function(hG)
    { var sId = hG.id; var hThumbList = jQuery('#' + sId + '_thumb'); hG.options.thumbListHidden = true; hThumbList.animate({ opacity: 0 }, 200); }, showThumbnailList: function(hG) {
        if (!hG.options.thumbListHidden)
        { return }
        var sId = hG.id; var hThumbList = jQuery('#' + sId + '_thumb'); hG.options.thumbListHidden = false; hThumbList.animate({ opacity: 1 }, 200);
    }, initThumbnailListEvents: function(hG) {
        var sId = hG.id; var hThumbList = jQuery('#' + sId + '_thumb'); var hList = hThumbList.find('ul'); hThumbList.mousemove(function(event)
        { jQuery.event.fix(event); }); hThumbList.mouseout(function(event)
        { jQuery.event.fix(event); });
    },


    scrollThumbnailList: function(hG, sDirection, nSpeed) {
        var sId = hG.id; var theSpeed = nSpeed ? nSpeed : 1000; if (hG.options.scrollingThumbnails)
        { return; }
        var hThumbList = jQuery('#' + sId + '_thumb'); var hList = hThumbList.find('ul'); var nW = jQuery(hG).width(); var nH = jQuery(hG).height(); var nLL = parseInt(jQuery(hList).css('left')); if (!nLL) { nLL = 0; jQuery(hList).css({ left: 0 }); }
        var nLW = jQuery(hList).outerWidth(); var nLT = parseInt(jQuery(hList).css('top')); if (!nLT) { nLT = 0; jQuery(hList).css({ top: '0px' }); }
        var nLH = jQuery(hList).outerHeight(); var nNL; var nScrollWidth = nW; var nScrollHeight = nH; if (hG.options.thumbHolderHorizontal) {
            switch (sDirection) {
                case 'left': if (nLL < 0) {
                        if (Math.min(nScrollWidth, Math.abs(nLL)) == nScrollWidth) { nNL = nLL + nScrollWidth - 2 * hG.options.leftThumbnailListPosition; }
                        else { nNL = nLL + Math.abs(nLL) + hG.options.leftThumbnailListPosition; jQuery("." + hG.options.prevLinkClass).addClass(hG.options.prevLinkClassDisabled); }
                        hG.options.scrollingThumbnails = true; jQuery(hList).animate({ left: nNL }, theSpeed, 'linear', function() { jQuery("." + hG.options.nextLinkClass).removeClass(hG.options.nextLinkClassDisabled); hG.options.scrollingThumbnails = false; });
                    }
                    break;
                case 'right':
                    if (Math.abs(nLL) < nLW - nW) {

                        if (Math.min(nScrollWidth, Math.abs(nLW - nW + nLL)) == nScrollWidth) { nNL = nLL - nScrollWidth + 2 * hG.options.leftThumbnailListPosition; }
                        else { nNL = nLL - Math.abs(nLW - nW + nLL) - hG.options.leftThumbnailListPosition; jQuery("." + hG.options.nextLinkClass).addClass(hG.options.nextLinkClassDisabled); }
                        hG.options.scrollingThumbnails = true; jQuery(hList).animate({ left: nNL }, theSpeed, 'linear', function() { jQuery("." + hG.options.prevLinkClass).removeClass(hG.options.prevLinkClassDisabled); hG.options.scrollingThumbnails = false; });
                    }
                    break;
            }
        }
        else if (hG.options.thumbHolderVertical) {
            switch (sDirection) {
                case 'left': if (nLT < 0)
                    { nNL = nLT + Math.min(nScrollHeight, Math.abs(nLT)); hG.options.scrollingThumbnails = true; jQuery(hList).animate({ top: nNL }, theSpeed, 'linear', function() { hG.options.scrollingThumbnails = false; }); }
                    break; case 'right': if (Math.abs(nLT) < nLH - nH)
                    { nNL = nLT - Math.min(nScrollHeight, Math.abs(nLH - nH + nLT)); hG.options.scrollingThumbnails = true; jQuery(hList).animate({ top: nNL }, theSpeed, 'linear', function() { hG.options.scrollingThumbnails = false; }); }
                    break;
            }
        }
    },
    fixThumbnailListPosition: function(hG) {
        var sId = hG.id; if (hG.options.scrollingThumbnails)
        { return; }

        var hThumbList = jQuery('#' + sId + '_thumb'); var nW = jQuery(hThumbList).width(); var hList = hThumbList.find('ul'); var nLL = parseInt(jQuery(hList).css('left')); if (!nLL) { nLL = 0; jQuery(hList).css({ left: 0 }); }
        var nLW = jQuery(hList).outerWidth(); var nNL = nLW + nLL; if (nNL < nW)
        { jQuery(hList).animate({ left: hG.options.leftThumbnailListPosition }, 1000, 'linear', function() { hG.options.scrollingThumbnails = false; }); }

    },

    markThumbnail: function(hGallery, nId)
    { var hG = hGallery; var sId = hG.id; var hThumbList = jQuery('#' + sId + '_thumb'); var hThumbLinks = hThumbList.find('ul a'); hThumbLinks.removeClass('selected'); hThumbLinks.eq(nId).addClass('selected'); jQuery.dmxGallery.scrollMarkedThumbIntoView(hG, nId); },


    scrollMarkedThumbIntoView: function(hGallery, nId) {
        var hG = hGallery; var sId = hG.id; var hThumbList = jQuery('#' + sId + '_thumb'); var hThumbLinks = hThumbList.find('ul a'); var nW = jQuery(hThumbList).width();
        var nH = jQuery(hThumbList).height();
        var hList = hThumbList.find('ul');
        if (first) { if (nId == 0) { jQuery(hList).animate({ left: hG.options.leftThumbnailListPosition }, 1000, 'linear', function() { jQuery("." + hG.options.prevLinkClass).addClass(hG.options.prevLinkClassDisabled); hG.options.scrollingThumbnails = false; first = false; }); return; } }
        var nLL = parseInt(jQuery(hList).css('left')) || 0; var nLT = parseInt(jQuery(hList).css('top')) || 0; var nLW = jQuery(hList).outerWidth(); var nNL = nLW + nLL; var nThumbLeft, nThumbTop; var nTW = hG.options.thumbWidth + 2 * hG.options.thumbPadding; var nTH = hG.options.thumbHeight + 2 * hG.options.thumbPadding; if (hG.options.thumbHolderHorizontal) {
            nThumbLeft = nId * nTW; if ((nThumbLeft + nLL) < 0) {
                jQuery(hList).animate({ left: -nThumbLeft + hG.options.leftThumbnailListPosition }, 300, 'linear', function() {
                    jQuery("." + hG.options.nextLinkClass).removeClass(hG.options.nextLinkClassDisabled); hG.options.scrollingThumbnails = false;
                });
            }
            if ((nThumbLeft + nLL + nTW) > nW) {
                jQuery(hList).animate({ left: -nThumbLeft + nW - nTW - hG.options.leftThumbnailListPosition }, 300, 'linear', function() {
                    jQuery("." + hG.options.prevLinkClass).removeClass(hG.options.prevLinkClassDisabled); hG.options.scrollingThumbnails = false;
                });
            }
        } else if (hG.options.thumbHolderVertical) {
            nThumbTop = nId * nTH; if ((nThumbTop + nLT) < 0)
            { jQuery(hList).animate({ top: -nThumbTop }, 300, 'linear', function() { hG.options.scrollingThumbnails = false; }); }
            if ((nThumbTop + nLT + nTH) > nH)
            { jQuery(hList).animate({ top: -nThumbTop + nH - nTH }, 300, 'linear', function() { hG.options.scrollingThumbnails = false; }); }
        }


        if (nId == hG.imageList.length - 1) { jQuery("." + hG.options.nextLinkClass).addClass(hG.options.nextLinkClassDisabled); }
        if (nId == 0) { jQuery("." + hG.options.prevLinkClass).addClass(hG.options.prevLinkClassDisabled); }




    }, nextImage: function(hGallery) {
        var hG = hGallery; hG.options.imgIndex += 1; var hElements = jQuery(hG).find('div.dmxImageHolder').find('ul li'); if (hG.options.imgIndex >= hElements.length)
        { hG.options.imgIndex = 0; }
        jQuery.dmxGallery.swapImages(hG, hG.options.imgIndex);
    }, previousImage: function(hGallery) {
        var hG = hGallery; hG.options.imgIndex -= 1; var hElements = jQuery(hG).find('div.dmxImageHolder').find('ul li'); if (hG.options.imgIndex < 0)
        { hG.options.imgIndex = hElements.length - 1; }
        jQuery.dmxGallery.swapImages(hG, hG.options.imgIndex);
    },

    play: function(hGallery) {
        var hG = hGallery;

        if (hG.imageList.length == 1) { return; }

        jQuery('a.dmxPause', hG).css({ display: '' }); jQuery('a.dmxPlay', hG).css({ display: 'none' });

        hG.options.player.delay(hG.options.playerDelay * 1000);
    },

    pause: function(hGallery)
    { var hG = hGallery; jQuery('a.dmxPause', hG).css({ display: 'none' }); jQuery('a.dmxPlay', hG).css({ display: '' }); hG.options.player.cancel(); },



    swapImages: function(hGallery, nId) {
        currentImage = nId + 1;

        var hG = hGallery; hG.options.swapping = true;

        show.get(0).href=hG.linkList[nId].href;
        show.attr("title", jQuery(hG.linkList[nId]).attr('title'));
        jQuery(".navInfo").html(jQuery.dmxGallery.navInfo(currentImage, hG.linkList.length));
        var hHolder = jQuery('.' + hG.options.imageHolderClass, hG);
        jQuery('div.imageContainer', hG).eq(1).empty();
        var hImage = jQuery('<img id="' + jQuery(hG).find('.imageContainer').eq(1).attr('id') + '_image' + '" border="0" />');
        jQuery(hG).find('.imageContainer').eq(1).append(hImage);

        if (hG.linkList[nId]) { hImage.wrap(hG.linkList[nId]); }

        if (!hG.imageList[nId].loaded) {
            hG.imageList[nId].loading = true; hImage.load(function() {
                hG.imageList[nId].loading = false; hG.imageList[nId].loaded = true; jQuery.dmxGallery.hideWaiting(hG); jQuery.dmxGallery.doSwapImages(hG); if (hG.options.autosize)
                { jQuery.dmxGallery.resizeGalleryToContent(hG); }
                else
                { window.setTimeout(function() { jQuery.dmxGallery.showCaption(hG) }, 100); }
                hG.options.swapping = false;
            }).attr('src', hG.imageList[nId]);
        }
        else {
            hImage.attr('src', hG.imageList[nId]); jQuery.dmxGallery.hideWaiting(hG); jQuery.dmxGallery.doSwapImages(hG); if (hG.options.autosize)
            { jQuery.dmxGallery.resizeGalleryToContent(hG); }
            else
            { window.setTimeout(function() { jQuery.dmxGallery.showCaption(hG) }, 100); }
            hG.options.swapping = false;
        }
        jQuery.dmxGallery.markThumbnail(hGallery, nId); jQuery.dmxGallery.preloadImages(hG, nId); if (typeof soundManager != 'undefined') {
            try
{ soundManager.play('gallery'); }
            catch (hE)
{ }
        }


    },

    doSwapImages: function(hGallery)
    { var hG = hGallery; jQuery('div.imageContainer', hG).eq(1).insertBefore(jQuery('div.imageContainer', hG).eq(0)); jQuery('div.imageContainer', hG).eq(0).fadeIn(1000); jQuery('div.imageContainer', hG).eq(1).fadeOut(1000); },

    showImage: function(hGallery, nId)
    { var hG = hGallery; jQuery.dmxGallery.showWaiting(hG); hG.options.imgIndex = nId; jQuery.dmxGallery.swapImages(hG, hG.options.imgIndex); },

    preloadImages: function(hGallery, nCurrentId) {
        if (hGallery.options.allPreloaded)
        { return; }
        for (var nI = 0; nI < hGallery.imageList.length; nI++) {
            if (!hGallery.imageList[nI].loaded)
            { break; }
        }
        if (nI == hGallery.imageList.length)
        { hGallery.options.allPreloaded = true; return; }
        function getIds(hImageList, nCurrentId, nTreshold) {
            var aIds = []; var nCId = 1; nTreshold = nTreshold > hImageList.length ? Math.floor(hImageList.length / 2) : nTreshold; while (nCId <= nTreshold)
            { aIds[aIds.length] = nCurrentId - nCId < 0 ? hImageList.length + nCurrentId - nCId : nCurrentId - nCId; aIds[aIds.length] = nCurrentId + nCId >= hImageList.length ? (nCurrentId + nCId) % hImageList.length : nCurrentId + nCId; nCId++; }
            return aIds;
        }
        var aIds = getIds(hGallery.imageList, nCurrentId, hGallery.options.preloadTreshold); var nId; while (aIds.length > 0) {
            nId = aIds.shift(); if (!hGallery.imageList[nId].loaded) {
                hGallery.imageList[nId].loading = true; var hImage = jQuery('<img />'); hImage.load(function()
                { hGallery.imageList[nId].loading = false; hGallery.imageList[nId].loaded = true; }).attr('src', hGallery.imageList[nId]);
            }
        }
    }, resizeGalleryToContent: function(hG) {
        var sId = hG.id; var hThumbList = jQuery('#' + sId + '_thumb'); var hMIC = jQuery('div.imageMainContainer:first', hG); var hIC = jQuery('div.imageContainer:first', hG); var sIId = hIC.attr('id') + '_image'; var hImage = jQuery('#' + sIId); if (jQuery(hG).width() == hImage.width() && jQuery(hG).height() == hImage.height())
        { window.setTimeout(function() { jQuery.dmxGallery.showCaption(hG) }, 10); return; }
        else {
            var gWidth = hImage.width(); var gHeight = hImage.height(); if (!hG.options.thumbShowOnHover) {
                if (hG.options.thumbHolderHorizontal) {
                    gHeight += hG.options.thumbHolderHeight
+ parseInt(hThumbList.css('paddingTop')) || 0
+ parseInt(hThumbList.css('paddingBottom')) || 0
+ parseInt(hThumbList.css('marginTop')) || 0
+ parseInt(hThumbList.css('marginBottom')) || 0;
                }
                else if (hG.options.thumbHolderVertical) {
                    gWidth += hG.options.thumbHolderWidth
+ parseInt(hThumbList.css('paddingLeft')) || 0
+ parseInt(hThumbList.css('paddingRight')) || 0
+ parseInt(hThumbList.css('marginLeft')) || 0
+ parseInt(hThumbList.css('marginRight')) || 0;
                }
                if (!jQuery.boxModel) {
                    gHeight += parseInt(jQuery(hG).css('paddingTop')) || 0
+ parseInt(jQuery(hG).css('paddingBottom')) || 0
+ parseInt(jQuery(hG).css('borderTopWidth')) || 0
+ parseInt(jQuery(hG).css('borderBottomWidth')) || 0
+ parseInt(jQuery(hG).css('marginTop')) || 0
+ parseInt(jQuery(hG).css('marginBottom')) || 0; gWidth += parseInt(jQuery(hG).css('paddingLeft')) || 0
+ parseInt(jQuery(hG).css('paddingRight')) || 0
+ parseInt(jQuery(hG).css('borderLeftWidth')) || 0
+ parseInt(jQuery(hG).css('borderRightWidth')) || 0
+ parseInt(jQuery(hG).css('marginLeft')) || 0
+ parseInt(jQuery(hG).css('marginRight')) || 0;
                }
                if (jQuery.boxModel && jQuery.browser.msie && jQuery.browser.version < 7) {
                    gHeight += parseInt(hMIC.css('borderTopWidth')) || 0
+ parseInt(hMIC.css('borderBottomWidth')) || 0
                    gWidth += parseInt(hMIC.css('borderLeftWidth')) || 0
+ parseInt(hMIC.css('borderRightWidth')) || 0
                }
            }
            jQuery(hG).stop(); jQuery(hG).animate({ width: gWidth, height: gHeight }, "slow", "linear", function()
            { window.setTimeout(function() { jQuery.dmxGallery.showCaption(hG) }, 10); });
        }
    }, debug: function(sMessage) {
        if (this.bDebug) {
            if (typeof window.console != 'undefined') {
                if (arguments.length > 1)
                { window.console.log(arguments); }
                else
                { window.console.log(sMessage); }
            }
            else
            { alert(sMessage); }
        }
    }, dir: function(sMessage) {
        if (this.bDebug) {
            if (typeof window.console != 'undefined') {
                if (arguments.length > 1)
                { window.console.dir(arguments); }
                else
                { window.console.dir(sMessage); }
            }
            else
            { alert(sMessage); }
        }
    },
    navInfo: function(current, total)
    { return String(current) + " of " + String(total) }
}
jQuery.dmxGallery.counter = 0; jQuery.fn.dmxGallery = jQuery.dmxGallery.build;



