
/*
* Title                   : Thumbnail Gallery WordPress Plugin
* Version                 : 1.2
* File                    : jquery.dop.ThumbnailGallery.js
* File Version            : 1.2
* Created / Last Modified : 07 January 2012
* Author                  : Marius-Cristian Donea
* Copyright               : © 2012 Marius-Cristian Donea
* Website                 : http://www.mariuscristiandonea.com
* Description             : Thumbnail Gallery jQuery Plugin.
*/

(function($){
    $.fn.DOPThumbnailGallery = function(options){
        var Container = this,
        ajaxURL = '',
        ID = '0',
        
        Width = 900,
        Height = 600,
        BgColor = 'f1f1f1',
        BgImage = 'none',
        BgAlpha = 100,

        ThumbnailsPosition = 'bottom',
        ThumbnailsOverImage = 'false',
        ThumbnailsBgColor = 'f1f1f1',
        ThumbnailsBgAlpha = 100,
        ThumbnailsSpacing = 5,
        ThumbnailsPaddingTop = 0,
        ThumbnailsPaddingRight = 5,
        ThumbnailsPaddingBottom = 5,
        ThumbnailsPaddingLeft = 5,
        
        ThumbnailLoader = 'assets/gui/images/ThumbnailLoader.gif',
        ThumbnailWidth = 60,
        ThumbnailHeight = 60,
        ThumbnailAlpha = 50,
        ThumbnailAlphaHover = 100,
        ThumbnailAlphaSelected = 100,
        ThumbnailBgColor = 'f1f1f1',
        ThumbnailBgColorHover = '000000',
        ThumbnailBgColorSelected = '000000',
        ThumbnailBorderSize = 2,
        ThumbnailBorderColor = 'f1f1f1',
        ThumbnailBorderColorHover = '000000',
        ThumbnailBorderColorSelected = '000000',
        ThumbnailPaddingTop = 0,
        ThumbnailPaddingRight = 0,
        ThumbnailPaddingBottom = 0,
        ThumbnailPaddingLeft = 0,

        ImageLoader = 'assets/gui/images/ImageLoader.gif',
        ImageBgColor = 'afafaf',
        ImageBgAlpha = 100,
        ImageDisplayType = 'fit',
        ImageDisplayTime = 1000,
        ImageMarginTop = 20,
        ImageMarginRight = 20,
        ImageMarginBottom = 20,
        ImageMarginLeft = 20,
        ImagePaddingTop = 5,
        ImagePaddingRight = 5,
        ImagePaddingBottom = 5,
        ImagePaddingLeft = 5,
        
        NavigationEnabled = 'true',
        NavigationPrev = 'assets/gui/images/Prev.png',
        NavigationPrevHover = 'assets/gui/images/PrevHover.png',
        NavigationNext = 'assets/gui/images/Next.png',
        NavigationNextHover = 'assets/gui/images/NextHover.png',
        NavigationLightbox = 'assets/gui/images/Lightbox.png',
        NavigationLightboxHover = 'assets/gui/images/LightboxHover.png',

        CaptionWidth = 900,
        CaptionHeight = 70,
        CaptionTitleColor = '000000',
        CaptionTextColor = '000000',
        CaptionBgColor = 'ffffff',
        CaptionBgAlpha = 50,
        CaptionPosition = 'bottom',
        CaptionScrollScrubColor = '777777',
        CaptionScrollBgColor = 'e0e0e0',
        CaptionMarginTop = 0,
        CaptionMarginRight = 0,
        CaptionMarginBottom = 0,
        CaptionMarginLeft = 0,
        CaptionPaddingTop = 10,
        CaptionPaddingRight = 10,
        CaptionPaddingBottom = 10,
        CaptionPaddingLeft = 10,
        
        LightboxEnabled = 'true',
        LightboxWindowColor = '000000',
        LightboxWindowAlpha = 80,
        LightboxLoader = 'assets/gui/images/LightboxLoader.gif',
        LightboxBgColor = '000000',
        LightboxBgAlpha = 100,
        LightboxMarginTop = 70,
        LightboxMarginRight = 70,
        LightboxMarginBottom = 70,
        LightboxMarginLeft = 70,
        LightboxPaddingTop = 10,
        LightboxPaddingRight = 10,
        LightboxPaddingBottom = 10,
        LightboxPaddingLeft = 10,
        
        LightboxNavigationPrev = 'assets/gui/images/LightboxPrev.png',
        LightboxNavigationPrevHover = 'assets/gui/images/LightboxPrevHover.png',
        LightboxNavigationNext = 'assets/gui/images/LightboxNext.png',
        LightboxNavigationNextHover = 'assets/gui/images/LightboxNextHover.png',
        LightboxNavigationClose = 'assets/gui/images/LightboxClose.png',
        LightboxNavigationCloseHover = 'assets/gui/images/LightboxCloseHover.png',
        LightboxNavigationInfoBgColor = '000000',
        LightboxNavigationInfoTextColor = 'dddddd',
        
        TooltipEnabled = 'false',
        TooltipBgColor = 'ffffff',
        TooltipStrokeColor = '000000',
        TooltipTextColor = '000000',
        
        Slideshow = 'false',
        SlideshowTime = 5000,
        SlideshowLoop = 'true',

        AutoHide = 'false',
        AutoHideTime = 2000,
        
        ThumbnailsPositionTime = 600,
        LightboxDisplayTime = 600,
        LightboxNavigationDisplayTime = 600,
        AutoHideDisplayTime = 600,
        
        Images = new Array(),
        Thumbs = new Array(),
        CaptionTitle = new Array(),
        CaptionText = new Array(),
        Media = new Array(),
        LightboxMedia = new Array(),
        noImages = 0,
        
        BgImageLoaded = false,
        BgImageWidth = 0,
        BgImageHeight = 0,

        currentImage = 0,
        imageLoaded = false,
        ImageWidth = 0,
        ImageHeight = 0,
        
        lightboxCurrentImage = 0,
        lightboxImageLoaded = false,
        lightboxImageWidth = 0,
        lightboxImageHeight = 0,

        SlideshowID,

        HideID,
        ItemsHidden,

        methods = {
                    init:function(){// Init Plugin.
                        return this.each(function(){
                            if (options){
                                $.extend(Data, options);
                            }
                            methods.parseSettings();
                            $(window).bind('resize.DOPThumbnailGallery', methods.initRP);
                        });
                    },
                    parseSettings:function(){// Parse Settings.
                        ajaxURL = $('a', Container).attr('href');
                        ID = $(Container).attr('id').split('DOPThumbnailGallery')[1];
                        
                        $.getJSON(ajaxURL, {action:'doptg_get_gallery_info', id:ID}, function(data){
                            Width = parseInt(data['Width']);
                            Height = parseInt(data['Height']);
                            BgColor = data['BgColor'];
                            BgAlpha = parseInt(data['BgAlpha']);
                            ThumbnailsPosition = data['ThumbnailsPosition'];
                            ThumbnailsOverImage = data['ThumbnailsOverImage'];
                            ThumbnailsBgColor = data['ThumbnailsBgColor'];
                            ThumbnailsBgAlpha = parseInt(data['ThumbnailsBgAlpha']);
                            ThumbnailsSpacing = parseInt(data['ThumbnailsSpacing']);
                            ThumbnailsPaddingTop = parseInt(data['ThumbnailsPaddingTop']);
                            ThumbnailsPaddingRight = parseInt(data['ThumbnailsPaddingRight']);
                            ThumbnailsPaddingBottom = parseInt(data['ThumbnailsPaddingBottom']);
                            ThumbnailsPaddingLeft = parseInt(data['ThumbnailsPaddingLeft']);
                            ThumbnailLoader = data['ThumbnailLoader'];
                            ThumbnailWidth = parseInt(data['ThumbnailWidth']);
                            ThumbnailHeight = parseInt(data['ThumbnailHeight']);
                            ThumbnailAlpha = parseInt(data['ThumbnailAlpha']);
                            ThumbnailAlphaHover = parseInt(data['ThumbnailAlphaHover']);
                            ThumbnailAlphaSelected = parseInt(data['ThumbnailAlphaSelected']);
                            ThumbnailBgColor = data['ThumbnailBgColor'];
                            ThumbnailBgColorHover = data['ThumbnailBgColorHover'];
                            ThumbnailBgColorSelected = data['ThumbnailBgColorSelected'];
                            ThumbnailBorderSize = parseInt(data['ThumbnailBorderSize']);
                            ThumbnailBorderColor = data['ThumbnailBorderColor'];
                            ThumbnailBorderColorHover = data['ThumbnailBorderColorHover'];
                            ThumbnailBorderColorSelected = data['ThumbnailBorderColorSelected'];
                            ThumbnailPaddingTop = parseInt(data['ThumbnailPaddingTop']);
                            ThumbnailPaddingRight = parseInt(data['ThumbnailPaddingRight']);
                            ThumbnailPaddingBottom = parseInt(data['ThumbnailPaddingBottom']);
                            ThumbnailPaddingLeft = parseInt(data['ThumbnailPaddingLeft']);
                            ImageLoader = data['ImageLoader'];
                            ImageBgColor = data['ImageBgColor'];
                            ImageBgAlpha = parseInt(data['ImageBgAlpha']);
                            ImageDisplayType = data['ImageDisplayType'];
                            ImageDisplayTime = parseInt(data['ImageDisplayTime']);
                            ImageMarginTop = parseInt(data['ImageMarginTop']);
                            ImageMarginRight = parseInt(data['ImageMarginRight']);
                            ImageMarginBottom = parseInt(data['ImageMarginBottom']);
                            ImageMarginLeft = parseInt(data['ImageMarginLeft']);
                            ImagePaddingTop = parseInt(data['ImagePaddingTop']);
                            ImagePaddingRight = parseInt(data['ImagePaddingRight']);
                            ImagePaddingBottom = parseInt(data['ImagePaddingBottom']);
                            ImagePaddingLeft = parseInt(data['ImagePaddingLeft']);
                            NavigationEnabled = data['NavigationEnabled'];
                            NavigationPrev = data['NavigationPrev'];
                            NavigationPrevHover = data['NavigationPrevHover'];
                            NavigationNext = data['NavigationNext'];
                            NavigationNextHover = data['NavigationNextHover'];
                            NavigationLightbox = data['NavigationLightbox'];
                            NavigationLightboxHover = data['NavigationLightboxHover'];
                            CaptionWidth = parseInt(data['CaptionWidth']);
                            CaptionHeight = parseInt(data['CaptionHeight']);
                            CaptionTitleColor = data['CaptionTitleColor'];
                            CaptionTextColor = data['CaptionTextColor'];
                            CaptionBgColor = data['CaptionBgColor'];
                            CaptionBgAlpha = parseInt(data['CaptionBgAlpha']);
                            CaptionPosition = data['CaptionPosition'];
                            CaptionScrollScrubColor = data['CaptionScrollScrubColor'];
                            CaptionScrollBgColor = data['CaptionScrollBgColor'];
                            CaptionMarginTop = parseInt(data['CaptionMarginTop']);
                            CaptionMarginRight = parseInt(data['CaptionMarginRight']);
                            CaptionMarginBottom = parseInt(data['CaptionMarginBottom']);
                            CaptionMarginLeft = parseInt(data['CaptionMarginLeft']);
                            CaptionPaddingTop = parseInt(data['CaptionPaddingTop']);
                            CaptionPaddingRight = parseInt(data['CaptionPaddingRight']);
                            CaptionPaddingBottom = parseInt(data['CaptionPaddingBottom']);
                            CaptionPaddingLeft = parseInt(data['CaptionPaddingLeft']);
                            LightboxEnabled = data['LightboxEnabled'];
                            LightboxWindowColor = data['LightboxWindowColor'];
                            LightboxWindowAlpha = parseInt(data['LightboxWindowAlpha']);
                            LightboxLoader = data['LightboxLoader'];
                            LightboxBgColor = data['LightboxBgColor'];
                            LightboxBgAlpha = parseInt(data['LightboxBgAlpha']);
                            LightboxMarginTop = parseInt(data['LightboxMarginTop']);
                            LightboxMarginRight = parseInt(data['LightboxMarginRight']);
                            LightboxMarginBottom = parseInt(data['LightboxMarginBottom']);
                            LightboxMarginLeft = parseInt(data['LightboxMarginLeft']);
                            LightboxPaddingTop = parseInt(data['LightboxPaddingTop']);
                            LightboxPaddingRight = parseInt(data['LightboxPaddingRight']);
                            LightboxPaddingBottom = parseInt(data['LightboxPaddingBottom']);
                            LightboxPaddingLeft = parseInt(data['LightboxPaddingLeft']);
                            LightboxNavigationPrev = data['LightboxNavigationPrev'];
                            LightboxNavigationPrevHover = data['LightboxNavigationPrevHover'];
                            LightboxNavigationNext = data['LightboxNavigationNext'];
                            LightboxNavigationNextHover = data['LightboxNavigationNextHover'];
                            LightboxNavigationClose = data['LightboxNavigationClose'];
                            LightboxNavigationCloseHover = data['LightboxNavigationCloseHover'];
                            LightboxNavigationInfoBgColor = data['LightboxNavigationInfoBgColor'];
                            LightboxNavigationInfoTextColor = data['LightboxNavigationInfoTextColor'];
                            TooltipEnabled = data['TooltipEnabled'];
                            TooltipBgColor = data['TooltipBgColor'];
                            TooltipStrokeColor = data['TooltipStrokeColor'];
                            TooltipTextColor = data['TooltipTextColor'];
                            Slideshow = data['Slideshow'];
                            SlideshowTime = parseInt(data['SlideshowTime']);
                            SlideshowLoop = data['SlideshowLoop'];
                            AutoHide = data['AutoHide'];
                            AutoHideTime = parseInt(data['AutoHideTime']);
                            
                            methods.parseContent();
                        });
                    },
                    parseContent:function(){// Parse Content.
                        $.getJSON(ajaxURL, {action:'doptg_get_gallery_content', id:ID}, function(data){
                            $.each(data, function(index){
                                $.each(data[index], function(key){
                                    switch (key){
                                        case 'Image':
                                            Images.push(data[index][key]);break;
                                        case 'Thumb':
                                            Thumbs.push(data[index][key]);break;
                                        case 'CaptionTitle':
                                            CaptionTitle.push(data[index][key]);break;
                                        case 'CaptionText':
                                            CaptionText.push(data[index][key]);break;
                                        case 'Media':
                                            Media.push(data[index][key]);break;
                                        case 'LightboxMedia':
                                            LightboxMedia.push(data[index][key]);break;
                                    }
                                });
                            });

                            noImages = Images.length;
                            methods.initGallery();
                        });
                    },
                    initGallery:function(){// Init the Gallery
                        var HTML = new Array(),
                        LightboxHTML = new Array();

                        HTML.push('<div class="DOP_ThumbnailGallery_Container">');

                        HTML.push('   <div class="DOP_ThumbnailGallery_Background"></div>');

                        HTML.push('   <div class="DOP_ThumbnailGallery_ThumbnailsContainer">');
                        HTML.push('       <div class="DOP_ThumbnailGallery_ThumbnailsBg"></div>');
                        HTML.push('       <div class="DOP_ThumbnailGallery_ThumbnailsWrapper">');
                        HTML.push('           <div class="DOP_ThumbnailGallery_Thumbnails"></div>');
                        HTML.push('       </div>');
                        HTML.push('   </div>');

                        HTML.push('   <div class="DOP_ThumbnailGallery_ImageWrapper">');
                        HTML.push('       <div class="DOP_ThumbnailGallery_ImageBg"></div>');
                        HTML.push('       <div class="DOP_ThumbnailGallery_Image"></div>');
                        HTML.push('       <div class="DOP_ThumbnailGallery_Caption">');
                        HTML.push('           <div class="DOP_ThumbnailGallery_CaptionBg"></div>');
                        HTML.push('           <div class="DOP_ThumbnailGallery_CaptionTextWrapper">');
                        HTML.push('               <div class="DOP_ThumbnailGallery_CaptionTitle"></div>');
                        HTML.push('               <div class="DOP_ThumbnailGallery_CaptionTextContainer">');
                        HTML.push('                   <div class="DOP_ThumbnailGallery_CaptionText"></div>');
                        HTML.push('               </div>');
                        HTML.push('           </div>');
                        HTML.push('       </div>');
                        HTML.push('   </div>');

                        if (NavigationEnabled == 'true'){
                            HTML.push('   <div class="DOP_ThumbnailGallery_NavigationLeft">');
                            HTML.push('       <img src="'+NavigationPrev+'" class="normal" alt="" />');
                            HTML.push('       <img src="'+NavigationPrevHover+'" class="hover" alt="" />');  
                            HTML.push('   </div>');
                            HTML.push('   <div class="DOP_ThumbnailGallery_NavigationRight">');
                            HTML.push('       <img src="'+NavigationNext+'" class="normal" alt="" />');
                            HTML.push('       <img src="'+NavigationNextHover+'" class="hover" alt="" />');  
                            HTML.push('   </div>');
                            if (LightboxEnabled == 'true'){
                                HTML.push('   <div class="DOP_ThumbnailGallery_NavigationLightbox">');
                                HTML.push('       <img src="'+NavigationLightbox+'" class="normal" alt="" />');
                                HTML.push('       <img src="'+NavigationLightboxHover+'" class="hover" alt="" />');  
                                HTML.push('   </div>');
                            }
                        }
                        
                        if (LightboxEnabled == 'true'){
                            LightboxHTML.push('   <div class="DOP_ThumbnailGallery_LightboxWrapper" id="DOP_ThumbnailGallery_LightboxWrapper_'+ID+'">');
                            LightboxHTML.push('       <div class="DOP_ThumbnailGallery_LightboxWindow"></div>');
                            LightboxHTML.push('       <div class="DOP_ThumbnailGallery_LightboxLoader"><img src="'+LightboxLoader+'" alt="" /></div>');
                            LightboxHTML.push('       <div class="DOP_ThumbnailGallery_LightboxContainer">');
                            LightboxHTML.push('           <div class="DOP_ThumbnailGallery_LightboxBg"></div>');
                            LightboxHTML.push('           <div class="DOP_ThumbnailGallery_Lightbox"></div>');
                            LightboxHTML.push('           <div class="DOP_ThumbnailGallery_LightboxNavigation">');
                            LightboxHTML.push('               <div class="DOP_ThumbnailGallery_LightboxNavigation_PrevBtn">');
                            LightboxHTML.push('                   <img src="'+LightboxNavigationPrev+'" class="normal" alt="" />');
                            LightboxHTML.push('                   <img src="'+LightboxNavigationPrevHover+'" class="hover" alt="" />');   
                            LightboxHTML.push('               </div>');   
                            LightboxHTML.push('               <div class="DOP_ThumbnailGallery_LightboxNavigation_NextBtn">');
                            LightboxHTML.push('                   <img src="'+LightboxNavigationNext+'" class="normal" alt="" />');
                            LightboxHTML.push('                   <img src="'+LightboxNavigationNextHover+'" class="hover" alt="" />');   
                            LightboxHTML.push('               </div>');   
                            LightboxHTML.push('               <div class="DOP_ThumbnailGallery_LightboxNavigation_CloseBtn">');
                            LightboxHTML.push('                   <img src="'+LightboxNavigationClose+'" class="normal" alt="" />');
                            LightboxHTML.push('                   <img src="'+LightboxNavigationCloseHover+'" class="hover" alt="" />');   
                            LightboxHTML.push('               </div>');  
                            LightboxHTML.push('               <div class="DOP_ThumbnailGallery_LightboxNavigation_Info">');
                            LightboxHTML.push('                   <span class="current"></span> / '+noImages);
                            LightboxHTML.push('               </div>');                                   
                            LightboxHTML.push('           </div>');
                            LightboxHTML.push('       </div>');
                            LightboxHTML.push('   </div>');
                        }
                        console.log(TooltipEnabled);
                        if (TooltipEnabled == 'true'){
                            HTML.push('   <div class="DOP_ThumbnailGallery_Tooltip"></div>');
                        }

                        HTML.push('</div>');

                        Container.html(HTML.join(''));
                        if (LightboxEnabled == 'true'){
                            $('body').append(LightboxHTML.join(''));
                        }
                        methods.initSettings();
                    },
                    initSettings:function(){// Init Settings
                        methods.initContainer();
                        methods.initBackground();
                        
                        if (Images.length > 0){
                            methods.initThumbnails();
                            methods.initImage();
                            if (NavigationEnabled == 'true'){
                                methods.initNavigation();
                            }
                            if (LightboxEnabled == 'true'){
                                methods.initLightbox();
                            }
                            if (TooltipEnabled == 'true'){
                                methods.initTooltip();
                            }
                            methods.initCaption();
                            if (AutoHide == 'true'){
                                methods.initAutoHide();
                            }
                        }
                        else{
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).css('display', 'none');
                            $('.DOP_ThumbnailGallery_ImageWrapper', Container).css('display', 'none');
                            $('.DOP_ThumbnailGallery_NavigationLeft', Container).css('display', 'none');
                            $('.DOP_ThumbnailGallery_NavigationRight', Container).css('display', 'none');
                            $('.DOP_ThumbnailGallery_NavigationLightbox', Container).css('display', 'none');
                        }
                    },
                    initRP:function(){// Init Resize & Positioning
                        methods.rpContainer();
                        methods.rpBackground();
                        methods.rpThumbnails();
                        if (Media[currentImage-1] == ''){
                            methods.rpImage();
                        }
                        else{
                            methods.rpMedia();
                        }
                        if (NavigationEnabled == 'true'){
                            methods.rpNavigation();
                        }
                        if (LightboxEnabled == 'true'){
                            if (Media[currentImage-1] == '' && LightboxMedia[currentImage-1] == ''){
                                methods.rpLightboxImage();
                            }
                            else{
                                methods.rpLightboxMedia();
                            }
                        }
                    },

                    initContainer:function(){// Init Gallery Container
                        $('.DOP_ThumbnailGallery_Container', Container).css('display', 'block');
                        methods.rpContainer();
                    },
                    rpContainer:function(){// Resize & Position the Container
                        if (Width != 'css'){
                            if (Width == '100%'){
                                $('.DOP_ThumbnailGallery_Container', Container).width($(Container).width());
                            }
                            else{
                                $('.DOP_ThumbnailGallery_Container', Container).width(Width);
                            }
                        }
                        if (Height != 'css'){
                            if (Height == '100%'){
                                $('.DOP_ThumbnailGallery_Container', Container).height($(Container).height());
                            }
                            else{
                                $('.DOP_ThumbnailGallery_Container', Container).height(Height);
                            }
                        }
                    },

                    initBackground:function(){// Init Background
                        if (BgColor != 'css'){
                            $('.DOP_ThumbnailGallery_Background', Container).css('background-color', '#'+BgColor);
                        }
                        $('.DOP_ThumbnailGallery_Background', Container).css('opacity', BgAlpha/100);

                        if (BgImage != 'none'){
                            var img = new Image();
                            $(img).load(function(){
                                BgImageLoaded = true;
                                $('.DOP_ThumbnailGallery_Background', Container).html(this);
                                BgImageWidth = $('img', '.DOP_ThumbnailGallery_Background', Container).width();
                                BgImageHeight = $('img', '.DOP_ThumbnailGallery_Background', Container).height();
                                methods.rpBackground();
                                $('img', '.DOP_ThumbnailGallery_Background', Container).css('opacity', 0);
                                $('img', '.DOP_ThumbnailGallery_Background', Container).stop(true, true).animate({'opacity':'1'}, 600);
                            }).attr('src', BgImage);
                        }

                        methods.rpBackground();
                    },
                    rpBackground:function(){// Resize & Position Background
                        if (Width != 'css'){
                            if (Width == '100%'){
                                $('.DOP_ThumbnailGallery_Background', Container).width($(Container).width());
                            }
                            else{
                                $('.DOP_ThumbnailGallery_Background', Container).width(Width);
                            }
                        }
                        if (Height != 'css'){
                            if (Height == '100%'){
                                $('.DOP_ThumbnailGallery_Background', Container).height($(Container).height());
                            }
                            else{
                                $('.DOP_ThumbnailGallery_Background', Container).height(Height);
                            }
                        }

                        if (BgImage != 'none' && BgImageLoaded){
                            prototypes.resizeItem2($('.DOP_ThumbnailGallery_Background', Container), $('.DOP_ThumbnailGallery_Background', Container).children(), $('.DOP_ThumbnailGallery_Background', Container).width(), $('.DOP_ThumbnailGallery_Background', Container).height(), BgImageWidth, BgImageHeight, 'center');
                        }
                    },
                    
                    initThumbnails:function(){// Init Thumbnails
                        $('.DOP_ThumbnailGallery_ThumbnailsBg', Container).css('background-color', '#'+ThumbnailsBgColor);
                        $('.DOP_ThumbnailGallery_ThumbnailsBg', Container).css('opacity', ThumbnailsBgAlpha/100);

                        methods.rpThumbnails();
                        
                        $('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).css('margin-top', ThumbnailsPaddingTop);
                        $('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).css('margin-left', ThumbnailsPaddingLeft);
                        
                        if (ThumbnailsPosition == 'top'){
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).css('margin-top', 0-$('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).height());
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).stop(true, true).animate({'margin-top':0}, 600);
                        }
                        if (ThumbnailsPosition == 'right'){
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).css('margin-left', $('.DOP_ThumbnailGallery_Container', Container).width());
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).stop(true, true).animate({'margin-left': $('.DOP_ThumbnailGallery_Container', Container).width()-$('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).width()}, 600);
                        }
                        if (ThumbnailsPosition == 'bottom'){
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).css('margin-top', $('.DOP_ThumbnailGallery_Container', Container).height());
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).stop(true, true).animate({'margin-top':$('.DOP_ThumbnailGallery_Container', Container).height()-$('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).height()}, 600);
                        }
                        if (ThumbnailsPosition == 'left'){
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).css('margin-left', 0-$('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).width());
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).stop(true, true).animate({'margin-left':0}, 600);
                        }
                        
                        methods.moveThumbnails();
                        methods.loadThumb(1);
                    },
                    loadThumb:function(no){// Load Thumbnail No
                        methods.initThumb(no);
                        var img = new Image();
                        
                        $(img).load(function(){
                            $('#DOP_ThumbnailGallery_Thumb_'+ID+'_'+no, Container).html(this);
                            methods.loadCompleteThumb(no);
                            if (no < noImages){
                                methods.loadThumb(no+1);
                            }
                        }).attr('src', Thumbs[no-1]);
                    },
                    initThumb:function(no){// Init Thumbnail
                        var ThumbHTML = new Array(),
                        thumbnailWidth = ThumbnailWidth+2*ThumbnailBorderSize+ThumbnailPaddingRight+ThumbnailPaddingLeft,
                        thumbnailWidthNB = ThumbnailWidth+ThumbnailPaddingRight+ThumbnailPaddingLeft,
                        thumbnailHeightNB = ThumbnailHeight+ThumbnailPaddingTop+ThumbnailPaddingBottom;
                        
                        ThumbHTML.push('<div class="DOP_ThumbnailGallery_ThumbContainer" id="DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+no+'">');
                        ThumbHTML.push('   <div class="DOP_ThumbnailGallery_Thumb" id="DOP_ThumbnailGallery_Thumb_'+ID+'_'+no+'"></div>');
                        ThumbHTML.push('</div>');
                        
                        if (ThumbnailsPosition == 'top' || ThumbnailsPosition == 'bottom'){
                            if (no == 1){
                                $('.DOP_ThumbnailGallery_Thumbnails', Container).width($('.DOP_ThumbnailGallery_Thumbnails', Container).width()+thumbnailWidth);
                            }
                            else{
                                $('.DOP_ThumbnailGallery_Thumbnails', Container).width($('.DOP_ThumbnailGallery_Thumbnails', Container).width()+thumbnailWidth+ThumbnailsSpacing);
                            }
                        }

                        $('.DOP_ThumbnailGallery_Thumbnails', Container).append(ThumbHTML.join(""));

                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+no, Container).css('opacity', ThumbnailAlpha/100);
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+no, Container).width(thumbnailWidthNB);
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+no, Container).height(thumbnailHeightNB);
                        $('#DOP_ThumbnailGallery_Thumb_'+ID+'_'+no, Container).css('margin-top', ThumbnailPaddingTop);
                        $('#DOP_ThumbnailGallery_Thumb_'+ID+'_'+no, Container).css('margin-left', ThumbnailPaddingLeft);
                        $('#DOP_ThumbnailGallery_Thumb_'+ID+'_'+no, Container).css('margin-bottom', ThumbnailPaddingBottom);
                        $('#DOP_ThumbnailGallery_Thumb_'+ID+'_'+no, Container).css('margin-right', ThumbnailPaddingRight);
                                                
                        if (ThumbnailsPosition == 'top' || ThumbnailsPosition == 'bottom'){
                            $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+no, Container).height(thumbnailHeightNB);
                        }
                        else{
                            $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+no, Container).width(thumbnailWidthNB);
                        }
                        
                        if (ThumbnailsPosition == 'top' || ThumbnailsPosition == 'bottom'){
                            $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+no, Container).css('float', 'left');
                        }

                        if (no != '1'){
                            if (ThumbnailsPosition == 'top' || ThumbnailsPosition == 'bottom'){
                                $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+no, Container).css('margin-left', ThumbnailsSpacing);
                            }
                            else{
                                $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+no, Container).css('margin-top', ThumbnailsSpacing);
                            }
                        }

                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+no, Container).css('background-color', '#'+ThumbnailBgColor);
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+no, Container).css('border-width', ThumbnailBorderSize);
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+no, Container).css('border-color', '#'+ThumbnailBorderColor);

                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+no, Container).addClass('DOP_ThumbnailGallery_ThumbLoader');
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+no+'.DOP_ThumbnailGallery_ThumbLoader', Container).css('background-image', 'url('+ThumbnailLoader+')');

                        if (ThumbnailsPosition == 'top' || ThumbnailsPosition == 'bottom'){
                            if ($('.DOP_ThumbnailGallery_Thumbnails', Container).width() <= $('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).width()){
                                prototypes.hCenterItem($('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container), $('.DOP_ThumbnailGallery_Thumbnails', Container), $('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).width());
                            }
                            else if (parseInt($('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-left')) >= 0){
                                $('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-left', 0);
                            }
                        }
                        else{
                            if ($('.DOP_ThumbnailGallery_Thumbnails', Container).height() <= $('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).height()){
                                prototypes.vCenterItem($('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container), $('.DOP_ThumbnailGallery_Thumbnails', Container), $('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).height());
                            }
                            else if (parseInt($('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-top')) >= 0){
                                $('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-top', 0);
                            }
                        }
                    },
                    loadCompleteThumb:function(no){// Thumbnail Load complete event
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+no+'.DOP_ThumbnailGallery_ThumbLoader', Container).css('background-image', 'none');
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+no, Container).removeClass('DOP_ThumbnailGallery_ThumbLoader');

                        prototypes.resizeItem2($('#DOP_ThumbnailGallery_Thumb_'+ID+'_'+no, Container), $('#DOP_ThumbnailGallery_Thumb_'+ID+'_'+no, Container).children(), ThumbnailWidth, ThumbnailHeight, $('#DOP_ThumbnailGallery_Thumb_'+ID+'_'+no, Container).children().width(), $('#DOP_ThumbnailGallery_Thumb_'+ID+'_'+no, Container).children().height(), 'center');
                        
                        $('img', '#DOP_ThumbnailGallery_Thumb_'+ID+'_'+no, Container).css('opacity', 0);
                        $('img', '#DOP_ThumbnailGallery_Thumb_'+ID+'_'+no, Container).stop(true, true).animate({'opacity':'1'}, 600);
                                                
                        if (!prototypes.isTouchDevice()){
                            $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+no, Container).hover(function(){
                                if (currentImage != no){
                                    $(this).stop(true, true).animate({'opacity':ThumbnailAlphaHover/100}, 300);
                                    $(this).css('background-color', '#'+ThumbnailBgColorHover);
                                    $(this).css('border-color', '#'+ThumbnailBorderColorHover);
                                }
                                if (TooltipEnabled == 'true'){
                                    methods.showTooltip(no-1);
                                }
                            },
                            function(){
                                if (currentImage != no){
                                    $(this).stop(true, true).animate({'opacity': ThumbnailAlpha/100}, 300);
                                    $(this).css('background-color', '#'+ThumbnailBgColor);
                                    $(this).css('border-color', '#'+ThumbnailBorderColor);
                                }
                                if (TooltipEnabled == 'true'){
                                    $('.DOP_ThumbnailGallery_Tooltip', Container).css('display', 'none');
                                }
                            });
                        }

                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+no, Container).click(function(){                            
                            if (imageLoaded){
                                if (Media[no-1] != ''){
                                    methods.loadMedia(no);
                                }
                                else{
                                    methods.loadImage(no);
                                }
                            }
                        });
                    },
                    rpThumbnails:function(){// Resize & Position the Thumbnails
                        if (ThumbnailsPosition == 'top' || ThumbnailsPosition == 'bottom'){
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).width($('.DOP_ThumbnailGallery_Container', Container).width());
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).height(ThumbnailHeight+(2*ThumbnailBorderSize)+ThumbnailPaddingTop+ThumbnailPaddingBottom+ThumbnailsPaddingTop+ThumbnailsPaddingBottom);

                            $('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).width($('.DOP_ThumbnailGallery_Container', Container).width()-ThumbnailsPaddingRight-ThumbnailsPaddingLeft);
                            $('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).height(ThumbnailHeight+(2*ThumbnailBorderSize)+ThumbnailPaddingTop+ThumbnailPaddingBottom);

                            if ($('.DOP_ThumbnailGallery_Thumbnails', Container).width() <= $('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).width()){
                                prototypes.hCenterItem($('.DOP_ThumbnailGallery_ThumbnailsContainer', Container), $('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container), $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).width());
                            }
                            else if (parseInt($('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-left')) >= 0){
                                $('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-left', 0);
                            }
                        }
                        else if (ThumbnailsPosition == 'right' || ThumbnailsPosition == 'left'){
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).width(ThumbnailWidth+(2*ThumbnailBorderSize)+ThumbnailPaddingRight+ThumbnailPaddingLeft+ThumbnailsPaddingRight+ThumbnailsPaddingLeft);
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).height($('.DOP_ThumbnailGallery_Container', Container).height());

                            $('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).width(ThumbnailWidth+(2*ThumbnailBorderSize)+ThumbnailPaddingRight+ThumbnailPaddingLeft);
                            $('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).height($('.DOP_ThumbnailGallery_Container', Container).height()-ThumbnailsPaddingTop-ThumbnailsPaddingBottom);

                            if ($('.DOP_ThumbnailGallery_Thumbnails', Container).height() <= $('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).height()){
                                prototypes.vCenterItem($('.DOP_ThumbnailGallery_ThumbnailsContainer', Container), $('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container), $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).height());
                            }
                            else if (parseInt($('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-top')) >= 0){
                                $('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-top', 0);
                            }
                        }

                        $('.DOP_ThumbnailGallery_ThumbnailsBg', Container).width($('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).width());
                        $('.DOP_ThumbnailGallery_ThumbnailsBg', Container).height($('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).height());

                        if (ThumbnailsPosition == 'top'){
                            prototypes.topItem($('.DOP_ThumbnailGallery_Container', Container), $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container), $('.DOP_ThumbnailGallery_Container', Container).height());
                        }
                        else if (ThumbnailsPosition == 'right'){
                            prototypes.rightItem($('.DOP_ThumbnailGallery_Container', Container), $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container), $('.DOP_ThumbnailGallery_Container', Container).width());
                        }
                        else if (ThumbnailsPosition == 'left'){
                            prototypes.leftItem($('.DOP_ThumbnailGallery_Container', Container), $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container), $('.DOP_ThumbnailGallery_Container', Container).width());
                        }
                        else{
                            prototypes.bottomItem($('.DOP_ThumbnailGallery_Container', Container), $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container), $('.DOP_ThumbnailGallery_Container', Container).height());
                        }
                    },
                    moveThumbnails:function(){// Move Thumbnails
                        if (prototypes.isTouchDevice()){
                            prototypes.touchNavigation($('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container), $('.DOP_ThumbnailGallery_Thumbnails', Container));
                        }
                        else{
                            $('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).mousemove(function(e){
                                var thumbnailWidth, thumbnailHeight, mousePosition, thumbnailsPosition;

                                if ((ThumbnailsPosition == 'top' || ThumbnailsPosition == 'bottom') && $('.DOP_ThumbnailGallery_Thumbnails', Container).width() > $('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).width()){
                                    thumbnailWidth = ThumbnailWidth+ThumbnailPaddingRight+ThumbnailPaddingLeft+2*ThumbnailBorderSize;
                                    mousePosition = e.clientX-$(this).offset().left+parseInt($(this).css('margin-left'))+$(document).scrollLeft();
                                    thumbnailsPosition = 0-(mousePosition-thumbnailWidth-ThumbnailsSpacing)*($('.DOP_ThumbnailGallery_Thumbnails', Container).width()-$('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).width())/($('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).width()-2*thumbnailWidth);
                                    
                                    if (thumbnailsPosition < (-1)*($('.DOP_ThumbnailGallery_Thumbnails', Container).width()-$('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).width())){
                                        thumbnailsPosition = (-1)*($('.DOP_ThumbnailGallery_Thumbnails', Container).width()-$('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).width());
                                    }
                                    if (thumbnailsPosition > 0){
                                        thumbnailsPosition = 0;
                                    }
                                    
                                    $('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-left', thumbnailsPosition);
                                }

                                if ((ThumbnailsPosition == 'right' || ThumbnailsPosition == 'left') && $('.DOP_ThumbnailGallery_Thumbnails', Container).height() > $('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).height()){
                                    thumbnailHeight = ThumbnailHeight+ThumbnailPaddingTop+ThumbnailPaddingBottom+2*ThumbnailBorderSize;
                                    mousePosition = e.clientY-$(this).offset().top+parseInt($(this).css('margin-top'))+$(document).scrollTop();
                                    thumbnailsPosition = 0-(mousePosition-thumbnailHeight-ThumbnailsSpacing)*($('.DOP_ThumbnailGallery_Thumbnails', Container).height()-$('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).height())/($('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).height()-2*thumbnailHeight);

                                    if (thumbnailsPosition < (-1)*($('.DOP_ThumbnailGallery_Thumbnails', Container).height()-$('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).height())){
                                        thumbnailsPosition = (-1)*($('.DOP_ThumbnailGallery_Thumbnails', Container).height()-$('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).height());
                                    }
                                    if (thumbnailsPosition > 0){
                                        thumbnailsPosition = 0;
                                    }
                                    
                                    $('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-top', thumbnailsPosition);
                                }
                            });
                        }
                    },
                    positionThumbnails:function(){// Position thumbnails to be displayed when hidden.
                        var thumbnailWidth = ThumbnailWidth+ThumbnailPaddingRight+ThumbnailPaddingLeft+2*ThumbnailBorderSize,
                        thumbnailHeight = ThumbnailHeight+ThumbnailPaddingTop+ThumbnailPaddingBottom+2*ThumbnailBorderSize;
                        
                        if (ThumbnailsPosition == 'top' || ThumbnailsPosition == 'bottom'){
                            if ($('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+currentImage, Container).position().left < (-1)*parseFloat($('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-left'))){
                                $('.DOP_ThumbnailGallery_Thumbnails', Container).stop(true, true).animate({'margin-left': (-1)*$('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+currentImage, Container).position().left}, ThumbnailsPositionTime, function(){
                                    if (parseFloat($('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-left')) > 0){
                                        $('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-left', 0);
                                    }
                                });
                            }
                            else if ($('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+currentImage, Container).position().left+thumbnailWidth > $('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).width()+(-1)*parseFloat($('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-left'))){
                                $('.DOP_ThumbnailGallery_Thumbnails', Container).stop(true, true).animate({'margin-left': (-1)*$('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+currentImage).position().left+$('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).width()-thumbnailWidth-ThumbnailsSpacing}, ThumbnailsPositionTime, function(){
                                    if (parseFloat($('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-left')) < (-1)*($('.DOP_ThumbnailGallery_Thumbnails', Container).width()-$('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).width())){
                                        $('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-left', (-1)*($('.DOP_ThumbnailGallery_Thumbnails', Container).width()-$('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).width()));
                                    }
                                });                                
                            }
                        }
                        else{
                            if ($('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+currentImage, Container).position().top < (-1)*parseFloat($('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-top'))){
                                $('.DOP_ThumbnailGallery_Thumbnails', Container).stop(true, true).animate({'margin-top': (-1)*$('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+currentImage, Container).position().top}, ThumbnailsPositionTime, function(){
                                    if (parseFloat($('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-top')) > 0){
                                        $('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-top', 0);
                                    }
                                });
                            }
                            else if ($('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+currentImage, Container).position().top+thumbnailWidth > $('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).height()+(-1)*parseFloat($('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-top'))){
                                $('.DOP_ThumbnailGallery_Thumbnails', Container).stop(true, true).animate({'margin-top': (-1)*$('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+currentImage).position().top+$('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).height()-thumbnailHeight-ThumbnailsSpacing}, ThumbnailsPositionTime, function(){
                                    if (parseFloat($('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-top')) < (-1)*($('.DOP_ThumbnailGallery_Thumbnails', Container).height()-$('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).height())){
                                        $('.DOP_ThumbnailGallery_Thumbnails', Container).css('margin-top', (-1)*($('.DOP_ThumbnailGallery_Thumbnails', Container).height()-$('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).height()));
                                    }
                                });                                
                            }                            
                        }
                    },

                    initImage:function(){// Init Image
                        if (ImageBgColor != 'css'){
                            $('.DOP_ThumbnailGallery_ImageBg', Container).css('background-color', '#'+ImageBgColor);
                        }
                        $('.DOP_ThumbnailGallery_ImageBg', Container).css('opacity', ImageBgAlpha/100);
                        
                        methods.rpImage();
                        if (Media[0] != ''){
                            methods.loadMedia(1);
                        }
                        else{
                            methods.loadImage(1);
                        }
                    },
                    loadImage:function(no){// Load Image
                        var img = new Image();
                            
                        clearInterval(SlideshowID);
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+currentImage, Container).stop(true, true).animate({'opacity':parseInt(ThumbnailAlpha)/100}, 300);
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+currentImage, Container).css('background-color', '#'+ThumbnailBgColor);
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+currentImage, Container).css('border-color', '#'+ThumbnailBorderColor);
                        currentImage = no;
                        imageLoaded = false;
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+currentImage, Container).stop(true, true).animate({'opacity':parseInt(ThumbnailAlphaSelected)/100}, 300);
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+currentImage, Container).css('background-color', '#'+ThumbnailBgColorSelected);
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+currentImage, Container).css('border-color', '#'+ThumbnailBorderColorSelected);
                        
                        methods.positionThumbnails();                        
                        methods.navigationDisplay('none'); 
                        methods.hideCaption();
                        
                        $('.DOP_ThumbnailGallery_Image', Container).stop(true, true).animate({'opacity':'0'}, parseInt(ImageDisplayTime)/2, function(){
                            $('.DOP_ThumbnailGallery_Image', Container).html('');
                            $('.DOP_ThumbnailGallery_ImageBg', Container).addClass('DOP_ThumbnailGallery_ImageLoader');
                            $('.DOP_ThumbnailGallery_ImageLoader', Container).css('background-image', 'url('+ImageLoader+')');

                            $(img).load(function(){
                                $('.DOP_ThumbnailGallery_CaptionTitle', Container).html(CaptionTitle[no-1]);
                                $('.DOP_ThumbnailGallery_CaptionText', Container).html(CaptionText[no-1]);
                                $('.DOP_ThumbnailGallery_Image', Container).removeClass('DOP_ThumbnailGallery_BigLoader');
                                $('.DOP_ThumbnailGallery_Image', Container).html(this);
                                $('.DOP_ThumbnailGallery_ImageLoader', Container).css('background-image', 'none');
                                $('.DOP_ThumbnailGallery_ImageBg', Container).removeClass('DOP_ThumbnailGallery_ImageLoader');
                                ImageWidth = $(this).width();
                                ImageHeight = $(this).height();
                                $('.DOP_ThumbnailGallery_Image', Container).css('opacity', 0);

                                if (ImageDisplayType == 'fit'){
                                    var currW = 0, currH = 0, ml = 0, mt = 0, dw = ImageWidth, dh = ImageHeight,
                                    cw = $('.DOP_ThumbnailGallery_ImageWrapper', Container).width()-ImageMarginLeft-ImageMarginRight-ImagePaddingLeft-ImagePaddingRight,
                                    ch = $('.DOP_ThumbnailGallery_ImageWrapper', Container).height()-ImageMarginTop-ImageMarginBottom-ImagePaddingTop-ImagePaddingBottom;

                                    if (dw <= cw && dh <= ch){
                                        currW = dw;
                                        currH = dh;
                                    }
                                    else{
                                        currH = ch;
                                        currW = (dw*ch)/dh;

                                        if (currW > cw){
                                            currW = cw;
                                            currH = (dh*cw)/dw;
                                        }
                                    }

                                    currW = currW+ImagePaddingLeft+ImagePaddingRight;
                                    currH = currH+ImagePaddingTop+ImagePaddingBottom;

                                    ml = ($('.DOP_ThumbnailGallery_ImageWrapper', Container).width()-currW)/2;
                                    mt = ($('.DOP_ThumbnailGallery_ImageWrapper', Container).height()-currH)/2;

                                    $('.DOP_ThumbnailGallery_ImageBg', Container).stop(true, true).animate({'width':currW, 'height':currH, 'margin-left':ml, 'margin-top':mt}, parseInt(ImageDisplayTime)/2, function(){
                                        methods.rpImage();
                                        $('.DOP_ThumbnailGallery_Image', Container).stop(true, true).animate({'opacity':'1'}, parseInt(ImageDisplayTime)/2, function(){
                                            imageLoaded = true;
                                            
                                            if (!ItemsHidden){
                                                methods.rpNavigation();
                                            }

                                            if (Slideshow == 'true'){
                                                if ((SlideshowLoop == 'true' && currentImage == noImages) || currentImage < noImages){
                                                    SlideshowID = setInterval(methods.nextImage, parseInt(SlideshowTime));
                                                }
                                            }
                                            
                                            methods.showCaption();
                                        });
                                    });
                                }
                                else{
                                    methods.rpImage();
                                    $('.DOP_ThumbnailGallery_Image', Container).stop(true, true).animate({'opacity':'1'}, parseInt(ImageDisplayTime), function(){
                                        imageLoaded = true;
                                        
                                        if (!ItemsHidden){
                                            methods.rpNavigation();
                                        }

                                        if (Slideshow == 'true'){
                                            if  ((SlideshowLoop == 'true' && currentImage == noImages) || currentImage < noImages){
                                                SlideshowID = setInterval(methods.nextImage, parseInt(SlideshowTime));
                                            }
                                        }
                                        
                                        methods.showCaption();
                                    });
                                }
                            }).attr('src', Images[no-1]);

                        });
                    },
                    rpImage:function(){// Resize & Position Image
                        $('.DOP_ThumbnailGallery_ImageWrapper', Container).width($('.DOP_ThumbnailGallery_Container', Container).width());
                        $('.DOP_ThumbnailGallery_ImageWrapper', Container).height($('.DOP_ThumbnailGallery_Container', Container).height());
                        if (ThumbnailsOverImage == 'false'){                        
                            if (ThumbnailsPosition == 'top' || ThumbnailsPosition == 'bottom'){
                                $('.DOP_ThumbnailGallery_ImageWrapper', Container).height($('.DOP_ThumbnailGallery_Container', Container).height()-$('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).height());
                            }
                            else{
                                $('.DOP_ThumbnailGallery_ImageWrapper', Container).width($('.DOP_ThumbnailGallery_Container', Container).width()-$('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).width());
                            }

                            if (ThumbnailsPosition == 'top'){
                                $('.DOP_ThumbnailGallery_ImageWrapper', Container).css('margin-top', $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).height());
                            }
                            if (ThumbnailsPosition == 'left'){
                                $('.DOP_ThumbnailGallery_ImageWrapper', Container).css('margin-left', $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).width());
                            }
                        }

                        if (ImageDisplayType == 'fit'){
                            var currW = 0, currH = 0, ml = 0, mt = 0, dw = ImageWidth, dh = ImageHeight,
                            cw = $('.DOP_ThumbnailGallery_ImageWrapper', Container).width()-ImageMarginLeft-ImageMarginRight-ImagePaddingLeft-ImagePaddingRight,
                            ch = $('.DOP_ThumbnailGallery_ImageWrapper', Container).height()-ImageMarginTop-ImageMarginBottom-ImagePaddingTop-ImagePaddingBottom;

                            if (ImageWidth == 0 || ImageHeight == 0){
                                dw = 200;
                                dh = 200;
                            }
                            
                            if (dw <= cw && dh <= ch){
                                currW = dw;
                                currH = dh;
                            }
                            else{
                                currH = ch;
                                currW = (dw*ch)/dh;

                                if (currW > cw){
                                    currW = cw;
                                    currH = (dh*cw)/dw;
                                }
                            }

                            $('.DOP_ThumbnailGallery_ImageBg', Container).width(currW+ImagePaddingLeft+ImagePaddingRight);
                            $('.DOP_ThumbnailGallery_ImageBg', Container).height(currH+ImagePaddingTop+ImagePaddingBottom);
                            $('.DOP_ThumbnailGallery_Image', Container).width(currW);
                            $('.DOP_ThumbnailGallery_Image', Container).height(currH);
                            $('.DOP_ThumbnailGallery_Image', Container).children().width(currW);
                            $('.DOP_ThumbnailGallery_Image', Container).children().height(currH);

                            prototypes.centerItem($('.DOP_ThumbnailGallery_ImageWrapper', Container), $('.DOP_ThumbnailGallery_ImageBg', Container), $('.DOP_ThumbnailGallery_ImageWrapper', Container).width(), $('.DOP_ThumbnailGallery_ImageWrapper', Container).height());
                            prototypes.centerItem($('.DOP_ThumbnailGallery_ImageWrapper', Container), $('.DOP_ThumbnailGallery_Image', Container), $('.DOP_ThumbnailGallery_ImageWrapper', Container).width(), $('.DOP_ThumbnailGallery_ImageWrapper', Container).height());
                        }
                        else{                            
                            $('.DOP_ThumbnailGallery_ImageBg', Container).width($('.DOP_ThumbnailGallery_ImageWrapper', Container).width()-ImageMarginLeft-ImageMarginRight);
                            $('.DOP_ThumbnailGallery_ImageBg', Container).height($('.DOP_ThumbnailGallery_ImageWrapper', Container).height()-ImageMarginTop-ImageMarginBottom);
                            prototypes.centerItem($('.DOP_ThumbnailGallery_ImageWrapper', Container), $('.DOP_ThumbnailGallery_ImageBg', Container), $('.DOP_ThumbnailGallery_ImageWrapper', Container).width(), $('.DOP_ThumbnailGallery_ImageWrapper', Container).height());                            
                            prototypes.resizeItem2($('.DOP_ThumbnailGallery_Image', Container), $('.DOP_ThumbnailGallery_Image', Container).children(), $('.DOP_ThumbnailGallery_ImageWrapper', Container).width()-ImageMarginLeft-ImageMarginRight, $('.DOP_ThumbnailGallery_ImageWrapper', Container).height()-ImageMarginTop-ImageMarginBottom, ImageWidth, ImageHeight, 'center');
                            prototypes.centerItem($('.DOP_ThumbnailGallery_ImageWrapper', Container), $('.DOP_ThumbnailGallery_Image', Container), $('.DOP_ThumbnailGallery_ImageWrapper', Container).width(), $('.DOP_ThumbnailGallery_ImageWrapper', Container).height());
                        }

                        methods.rpCaption();
                        
                        if (NavigationEnabled == 'true'){
                            methods.rpNavigation();
                        }
                    },

                    loadMedia:function(no){// Load Media                       
                        var iframeSRC = '';
                        
                        clearInterval(SlideshowID);
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+currentImage, Container).stop(true, true).animate({'opacity': ThumbnailAlpha/100}, 300);
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+currentImage, Container).css('background-color', '#'+ThumbnailBgColor);
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+currentImage, Container).css('border-color', '#'+ThumbnailBorderColor);
                        currentImage = no;
                        imageLoaded = false;
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+currentImage, Container).stop(true, true).animate({'opacity':ThumbnailAlphaSelected/100}, 300);
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+currentImage, Container).css('background-color', '#'+ThumbnailBgColorSelected);
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+ID+'_'+currentImage, Container).css('border-color', '#'+ThumbnailBorderColorSelected);
                        
                        methods.positionThumbnails();
                        methods.navigationDisplay('none'); 
                        methods.hideCaption();

                        $('.DOP_ThumbnailGallery_Image', Container).stop(true, true).animate({'opacity':'0'}, ImageDisplayTime/2, function(){
                            $('.DOP_ThumbnailGallery_Image', Container).html('');
                            $('.DOP_ThumbnailGallery_ImageBg', Container).addClass('DOP_ThumbnailGallery_ImageLoader');
                            $('.DOP_ThumbnailGallery_ImageLoader', Container).css('background-image', 'url('+ImageLoader+')');

                            $('.DOP_ThumbnailGallery_CaptionTitle', Container).html(CaptionTitle[no-1]);
                            $('.DOP_ThumbnailGallery_CaptionText', Container).html(CaptionText[no-1]);
                            $('.DOP_ThumbnailGallery_Image', Container).removeClass('DOP_ThumbnailGallery_BigLoader');
                            
                            $('.DOP_ThumbnailGallery_Image', Container).html(Media[no-1]);
                            iframeSRC = $('.DOP_ThumbnailGallery_Image', Container).children().attr('src');
                            $('.DOP_ThumbnailGallery_Image', Container).children().attr('src', iframeSRC+'?wmode=transparent');

                            $('.DOP_ThumbnailGallery_ImageLoader', Container).css('background-image', 'none');
                            $('.DOP_ThumbnailGallery_ImageBg', Container).removeClass('DOP_ThumbnailGallery_ImageLoader');
                            ImageWidth = $('.DOP_ThumbnailGallery_Image', Container).children().width();
                            ImageHeight = $('.DOP_ThumbnailGallery_Image', Container).children().height();
                            $('.DOP_ThumbnailGallery_Image', Container).css('opacity', 0);
                            
                            var ml = ($('.DOP_ThumbnailGallery_ImageWrapper', Container).width()-ImageWidth-ImagePaddingLeft-ImagePaddingRight)/2,
                            mt = ($('.DOP_ThumbnailGallery_ImageWrapper', Container).height()-ImageHeight-ImagePaddingTop-ImagePaddingBottom)/2;
                            
                            $('.DOP_ThumbnailGallery_ImageBg', Container).stop(true, true).animate({'width':ImageWidth+ImagePaddingLeft+ImagePaddingRight, 'height':ImageHeight+ImagePaddingTop+ImagePaddingBottom, 'margin-left':ml, 'margin-top':mt}, ImageDisplayTime/2, function(){
                                methods.rpMedia();
                                $('.DOP_ThumbnailGallery_Image', Container).stop(true, true).animate({'opacity':'1'}, ImageDisplayTime/2, function(){
                                    imageLoaded = true;
                                    
                                    if (!ItemsHidden){
                                        methods.rpNavigation();
                                    }

                                    if (Slideshow == 'true'){
                                        if ((SlideshowLoop == 'true' && currentImage == noImages) || currentImage < noImages){
                                            SlideshowID = setInterval(methods.nextImage, SlideshowTime);
                                        }
                                    }
                                    
                                    methods.showCaption();
                                });
                            });
                        });
                    },
                    rpMedia:function(){// Resize & Position Media
                        $('.DOP_ThumbnailGallery_ImageWrapper', Container).width($('.DOP_ThumbnailGallery_Container', Container).width());
                        $('.DOP_ThumbnailGallery_ImageWrapper', Container).height($('.DOP_ThumbnailGallery_Container', Container).height());
                        if (ThumbnailsOverImage == 'false'){
                            if (ThumbnailsPosition == 'top' || ThumbnailsPosition == 'bottom'){
                                $('.DOP_ThumbnailGallery_ImageWrapper', Container).height($('.DOP_ThumbnailGallery_Container', Container).height()-$('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).height());
                            }
                            else{
                                $('.DOP_ThumbnailGallery_ImageWrapper', Container).width($('.DOP_ThumbnailGallery_Container', Container).width()-$('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).width());
                            }

                            if (ThumbnailsPosition == 'top'){
                                $('.DOP_ThumbnailGallery_ImageWrapper', Container).css('margin-top', $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).height());
                            }
                            if (ThumbnailsPosition == 'left'){
                                $('.DOP_ThumbnailGallery_ImageWrapper', Container).css('margin-left', $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).width());
                            }
                        }

                        $('.DOP_ThumbnailGallery_ImageBg', Container).width(ImageWidth+ImagePaddingLeft+ImagePaddingRight);
                        $('.DOP_ThumbnailGallery_ImageBg', Container).height(ImageHeight+ImagePaddingTop+ImagePaddingBottom);
                        $('.DOP_ThumbnailGallery_Image', Container).width(ImageWidth);
                        $('.DOP_ThumbnailGallery_Image', Container).height(ImageHeight);
                        $('.DOP_ThumbnailGallery_Image', Container).children().width(ImageWidth);
                        $('.DOP_ThumbnailGallery_Image', Container).children().height(ImageHeight);
                        
                        prototypes.centerItem($('.DOP_ThumbnailGallery_ImageWrapper', Container), $('.DOP_ThumbnailGallery_ImageBg', Container), $('.DOP_ThumbnailGallery_ImageWrapper', Container).width(), $('.DOP_ThumbnailGallery_ImageWrapper', Container).height());
                        prototypes.centerItem($('.DOP_ThumbnailGallery_ImageWrapper', Container), $('.DOP_ThumbnailGallery_Image', Container), $('.DOP_ThumbnailGallery_ImageWrapper', Container).width(), $('.DOP_ThumbnailGallery_ImageWrapper', Container).height());
                        
                        methods.rpCaption();
                        methods.rpNavigation();
                    },

                    initNavigation:function(){// Init Navigation                        
                        if (!prototypes.isTouchDevice()){
                            $('.DOP_ThumbnailGallery_NavigationLeft', Container).hover(function(){
                                $('.normal', this).css('display', 'none');
                                $('.hover', this).css('display', 'block');
                            }, function(){
                                $('.normal', this).css('display', 'block');
                                $('.hover', this).css('display', 'none');
                            });
                        
                            $('.DOP_ThumbnailGallery_NavigationRight', Container).hover(function(){
                                $('.normal', this).css('display', 'none');
                                $('.hover', this).css('display', 'block');
                            }, function(){
                                $('.normal', this).css('display', 'block');
                                $('.hover', this).css('display', 'none');
                            });
                        }

                        $('.DOP_ThumbnailGallery_NavigationLeft', Container).click(function(){
                            if (imageLoaded){
                                methods.previousImage();
                            }
                        });

                        $('.DOP_ThumbnailGallery_NavigationRight', Container).click(function(){
                            if (imageLoaded){
                                methods.nextImage();
                            }
                        });
                        
                        if (LightboxEnabled == 'true'){
                            if (!prototypes.isTouchDevice()){
                                $('.DOP_ThumbnailGallery_NavigationLightbox', Container).hover(function(){
                                    $('.normal', this).css('display', 'none');
                                    $('.hover', this).css('display', 'block');
                                }, function(){
                                    $('.normal', this).css('display', 'block');
                                    $('.hover', this).css('display', 'none');
                                });
                            }
                            
                            $('.DOP_ThumbnailGallery_NavigationLightbox', Container).click(function(){
                                methods.showLightbox();
                            });
                        }
                    },
                    previousImage:function(){// Go to previous image
                        if (currentImage == 1){
                            if (Media[noImages-1] != ''){
                                methods.loadMedia(noImages);
                            }
                            else{
                                methods.loadImage(noImages);
                            }
                        }
                        else{
                            if (Media[currentImage-2] != ''){
                                methods.loadMedia(currentImage-1);
                            }
                            else{
                                methods.loadImage(currentImage-1);
                            }
                        }
                    },
                    nextImage:function(){// Go to next image
                        if (currentImage == noImages){
                            if (Media[0] != ''){
                                methods.loadMedia(1);
                            }
                            else{
                                methods.loadImage(1);
                            }
                        }
                        else{
                            if (Media[currentImage] != ''){
                                methods.loadMedia(currentImage+1);
                            }
                            else{
                                methods.loadImage(currentImage+1);
                            }
                        }
                    },
                    rpNavigation:function(){// Resize & Position Navigation Buttons    
                        methods.navigationDisplay('block');                        
                        $('.DOP_ThumbnailGallery_NavigationLeft', Container).css({'height': $('.DOP_ThumbnailGallery_NavigationLeft img:first-child', Container).height(),
                                                                                  'margin-left': parseFloat($('.DOP_ThumbnailGallery_Image', Container).css('margin-left'))+10,
                                                                                  'margin-top': parseFloat($('.DOP_ThumbnailGallery_Image', Container).css('margin-top'))+($('.DOP_ThumbnailGallery_Image', Container).height()-$('.DOP_ThumbnailGallery_NavigationLeft', Container).height())/2});
                        $('.DOP_ThumbnailGallery_NavigationRight', Container).css({'height': $('.DOP_ThumbnailGallery_NavigationRight img:first-child', Container).height(),
                                                                                   'margin-left': parseFloat($('.DOP_ThumbnailGallery_Image', Container).css('margin-left'))+$('.DOP_ThumbnailGallery_Image', Container).width()-$('.DOP_ThumbnailGallery_NavigationRight', Container).width()-10,
                                                                                   'margin-top': parseFloat($('.DOP_ThumbnailGallery_Image', Container).css('margin-top'))+($('.DOP_ThumbnailGallery_Image', Container).height()-$('.DOP_ThumbnailGallery_NavigationRight', Container).height())/2});
                        $('.DOP_ThumbnailGallery_NavigationLightbox', Container).css({'height': $('.DOP_ThumbnailGallery_NavigationLightbox img:first-child', Container).height(),
                                                                                      'margin-left': parseFloat($('.DOP_ThumbnailGallery_ImageWrapper', Container).css('margin-left'))+parseInt($('.DOP_ThumbnailGallery_Image', Container).css('margin-left'))+($('.DOP_ThumbnailGallery_Image', Container).width()-$('.DOP_ThumbnailGallery_NavigationRight', Container).width())-10,
                                                                                      'margin-top': parseFloat($('.DOP_ThumbnailGallery_Image', Container).css('margin-top'))+10});
                        if (!imageLoaded){    
                            methods.navigationDisplay('none');
                        }                                                       
                    },
                    navigationDisplay:function(value){
                        $('.DOP_ThumbnailGallery_NavigationLeft', Container).css('display', value);
                        $('.DOP_ThumbnailGallery_NavigationRight', Container).css('display', value);    
                        $('.DOP_ThumbnailGallery_NavigationLightbox', Container).css('display', value);                        
                    },

                    initCaption:function(){// Init Caption
                        $('.DOP_ThumbnailGallery_Caption', Container).css('opacity', 0);
                        $('.DOP_ThumbnailGallery_CaptionBg', Container).css('background-color', '#'+CaptionBgColor);
                        $('.DOP_ThumbnailGallery_CaptionBg', Container).css('opacity', CaptionBgAlpha/100);
                        $('.DOP_ThumbnailGallery_CaptionTitle', Container).css('color', '#'+CaptionTitleColor);
                        $('.DOP_ThumbnailGallery_CaptionText', Container).css('color', '#'+CaptionTextColor);
                    },
                    showCaption:function(){// Show Caption
                        if (imageLoaded && ($('.DOP_ThumbnailGallery_CaptionTitle', Container).html() != '' || $('.DOP_ThumbnailGallery_CaptionText', Container).html() != '')){
                            $('.DOP_ThumbnailGallery_Caption', Container).css('display', 'block');
                            $('.DOP_ThumbnailGallery_Caption', Container).stop(true, true).animate({'opacity': 1}, 600, function(){
                                $('.DOP_ThumbnailGallery_CaptionTextContainer', Container).height($('.DOP_ThumbnailGallery_CaptionTextWrapper', Container).height()-$('.DOP_ThumbnailGallery_CaptionTitle', Container).height()-5);
                                $('.DOP_ThumbnailGallery_CaptionTextContainer', Container).jScrollPane();
                                if (CaptionScrollScrubColor != 'css'){
                                    $('.jspDrag', Container).css('background-color', '#'+CaptionScrollScrubColor);
                                }
                                if (CaptionScrollBgColor != 'css'){
                                    $('.jspTrack', Container).css('background-color', '#'+CaptionScrollBgColor);
                                }
                            });
                        }
                    },
                    hideCaption:function(){// Hide Caption
                        $('.DOP_ThumbnailGallery_Caption', Container).stop(true, true).animate({'opacity': 0}, 600, function(){
                            $(this).css('display', 'none');
                        });
                    },
                    rpCaption:function(){// Resize & Position Caption
                        if (CaptionWidth+CaptionMarginLeft+CaptionMarginRight > $('.DOP_ThumbnailGallery_Image', Container).width()){
                            $('.DOP_ThumbnailGallery_Caption', Container).width($('.DOP_ThumbnailGallery_Image', Container).width());
                        }
                        else{
                            $('.DOP_ThumbnailGallery_Caption', Container).width(CaptionWidth+CaptionMarginLeft+CaptionMarginRight);
                        }
                        if (CaptionHeight+CaptionMarginTop+CaptionMarginBottom > $('.DOP_ThumbnailGallery_Image', Container).height()){
                            $('.DOP_ThumbnailGallery_Caption', Container).height($('.DOP_ThumbnailGallery_Image', Container).height());
                        }
                        else{
                            $('.DOP_ThumbnailGallery_Caption', Container).height(CaptionHeight+CaptionMarginTop+CaptionMarginBottom);
                        }
                        
                        if (CaptionPosition == 'top'){
                            prototypes.hCenterItem($('.DOP_ThumbnailGallery_ImageWrapper', Container), $('.DOP_ThumbnailGallery_Caption', Container), $('.DOP_ThumbnailGallery_ImageWrapper', Container).width());
                            $('.DOP_ThumbnailGallery_Caption', Container).css('margin-top', parseInt($('.DOP_ThumbnailGallery_Image', Container).css('margin-top')));
                        }
                        else if (CaptionPosition == 'top-left'){
                            $('.DOP_ThumbnailGallery_Caption', Container).css('margin-top', parseInt($('.DOP_ThumbnailGallery_Image', Container).css('margin-top')));
                            $('.DOP_ThumbnailGallery_Caption', Container).css('margin-left', parseInt($('.DOP_ThumbnailGallery_Image', Container).css('margin-left')));
                        }
                        else if (CaptionPosition == 'top-right'){
                            $('.DOP_ThumbnailGallery_Caption', Container).css('margin-top', parseInt($('.DOP_ThumbnailGallery_Image', Container).css('margin-top')));
                            $('.DOP_ThumbnailGallery_Caption', Container).css('margin-left', parseInt($('.DOP_ThumbnailGallery_Image', Container).css('margin-left'))+$('.DOP_ThumbnailGallery_Image', Container).width()-$('.DOP_ThumbnailGallery_Caption', Container).width());
                        }
                        else if (CaptionPosition == 'right'){
                            prototypes.vCenterItem($('.DOP_ThumbnailGallery_ImageWrapper', Container), $('.DOP_ThumbnailGallery_Caption', Container), $('.DOP_ThumbnailGallery_ImageWrapper', Container).height());
                            $('.DOP_ThumbnailGallery_Caption', Container).css('margin-left', parseInt($('.DOP_ThumbnailGallery_Image', Container).css('margin-left'))+$('.DOP_ThumbnailGallery_Image', Container).width()-$('.DOP_ThumbnailGallery_Caption', Container).width());
                        }
                        else if (CaptionPosition == 'left'){
                            prototypes.vCenterItem($('.DOP_ThumbnailGallery_ImageWrapper', Container), $('.DOP_ThumbnailGallery_Caption', Container), $('.DOP_ThumbnailGallery_ImageWrapper', Container).height());
                            $('.DOP_ThumbnailGallery_Caption', Container).css('margin-left', parseInt($('.DOP_ThumbnailGallery_Image', Container).css('margin-left')));
                        }
                        else if (CaptionPosition == 'bottom-left'){
                            $('.DOP_ThumbnailGallery_Caption', Container).css('margin-top', parseInt($('.DOP_ThumbnailGallery_Image', Container).css('margin-top'))+$('.DOP_ThumbnailGallery_Image', Container).height()-$('.DOP_ThumbnailGallery_Caption', Container).height());
                            $('.DOP_ThumbnailGallery_Caption', Container).css('margin-left', parseInt($('.DOP_ThumbnailGallery_Image', Container).css('margin-left')));
                        }
                        else if (CaptionPosition == 'bottom-right'){
                            $('.DOP_ThumbnailGallery_Caption', Container).css('margin-top', parseInt($('.DOP_ThumbnailGallery_Image', Container).css('margin-top'))+$('.DOP_ThumbnailGallery_Image', Container).height()-$('.DOP_ThumbnailGallery_Caption', Container).height());
                            $('.DOP_ThumbnailGallery_Caption', Container).css('margin-left', parseInt($('.DOP_ThumbnailGallery_Image', Container).css('margin-left'))+$('.DOP_ThumbnailGallery_Image', Container).width()-$('.DOP_ThumbnailGallery_Caption', Container).width());
                        }
                        else{
                            prototypes.hCenterItem($('.DOP_ThumbnailGallery_ImageWrapper', Container), $('.DOP_ThumbnailGallery_Caption', Container), $('.DOP_ThumbnailGallery_ImageWrapper', Container).width());
                            $('.DOP_ThumbnailGallery_Caption', Container).css('margin-top', parseInt($('.DOP_ThumbnailGallery_Image', Container).css('margin-top'))+$('.DOP_ThumbnailGallery_Image', Container).height()-$('.DOP_ThumbnailGallery_Caption', Container).height());
                        }

                        $('.DOP_ThumbnailGallery_CaptionBg', Container).width($('.DOP_ThumbnailGallery_Caption', Container).width()-CaptionMarginLeft-CaptionMarginRight);
                        $('.DOP_ThumbnailGallery_CaptionBg', Container).height($('.DOP_ThumbnailGallery_Caption', Container).height()-CaptionMarginTop-CaptionMarginBottom);
                        $('.DOP_ThumbnailGallery_CaptionBg', Container).css('margin-top', CaptionMarginTop);
                        $('.DOP_ThumbnailGallery_CaptionBg', Container).css('margin-left', CaptionMarginLeft);

                        $('.DOP_ThumbnailGallery_CaptionTextWrapper', Container).css('margin-top', CaptionMarginTop+CaptionPaddingTop);
                        $('.DOP_ThumbnailGallery_CaptionTextWrapper', Container).css('margin-left', CaptionMarginLeft+CaptionPaddingLeft);
                        $('.DOP_ThumbnailGallery_CaptionTextWrapper', Container).width($('.DOP_ThumbnailGallery_CaptionBg', Container).width()-CaptionPaddingLeft-CaptionPaddingRight);
                        $('.DOP_ThumbnailGallery_CaptionTextWrapper', Container).height($('.DOP_ThumbnailGallery_CaptionBg', Container).height()-CaptionPaddingTop-CaptionPaddingBottom);
                        $('.DOP_ThumbnailGallery_CaptionTextContainer', Container).height($('.DOP_ThumbnailGallery_CaptionTextWrapper', Container).height()-$('.DOP_ThumbnailGallery_CaptionTitle', Container).height()-5);
                        if (prototypes.isTouchDevice()){
                            $('.DOP_ThumbnailGallery_CaptionTextContainer', Container).css('overflow', 'scroll');
                        }
                        else{
                            $('.DOP_ThumbnailGallery_CaptionTextContainer', Container).jScrollPane();
                            if (CaptionScrollScrubColor != 'css'){
                                $('.jspDrag', Container).css('background-color', '#'+CaptionScrollScrubColor);
                            }
                            if (CaptionScrollBgColor != 'css'){
                                $('.jspTrack', Container).css('background-color', '#'+CaptionScrollBgColor);
                            }
                        }
                    },

                    initLightbox:function(){// Init Lightbox
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxWindow').css({'background-color': '#'+LightboxWindowColor,
                                                                                                                    'opacity': LightboxWindowAlpha/100});
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxBg').css({'background-color': '#'+LightboxBgColor,
                                                                                                                'opacity': LightboxBgAlpha/100});
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_Info').css({'background-color': '#'+LightboxNavigationInfoBgColor,
                                                                                                                             'color': LightboxNavigationInfoTextColor/100});
                                                                                             
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').hover(function(){
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation').animate({'opacity': 1}, LightboxNavigationDisplayTime);
                        }, function(){
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation').animate({'opacity': 0}, LightboxNavigationDisplayTime);
                        });

                        if (!prototypes.isTouchDevice()){                        
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_PrevBtn').hover(function(){
                                $('.normal', this).css('display', 'none');
                                $('.hover', this).css('display', 'block');
                            }, function(){
                                $('.normal', this).css('display', 'block');
                                $('.hover', this).css('display', 'none');                            
                            });
                        
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_NextBtn').hover(function(){
                                $('.normal', this).css('display', 'none');
                                $('.hover', this).css('display', 'block');
                            }, function(){
                                $('.normal', this).css('display', 'block');
                                $('.hover', this).css('display', 'none');                            
                            });
                        
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_CloseBtn').hover(function(){
                                $('.normal', this).css('display', 'none');
                                $('.hover', this).css('display', 'block');
                            }, function(){
                                $('.normal', this).css('display', 'block');
                                $('.hover', this).css('display', 'none');                            
                            });
                        }
                        
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_PrevBtn').click(function(){
                            methods.previousLightbox();
                        });
                        
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_NextBtn').click(function(){
                            methods.nextLightbox();
                        });
                        
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_CloseBtn').click(function(){
                           methods.hideLightbox();                           
                        });
                    },
                    showLightbox:function(){// Show Lightbox
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID).fadeIn(LightboxDisplayTime, function(){                        
                            if (Media[currentImage-1] != '' || LightboxMedia[currentImage-1] != ''){
                                methods.loadLightboxMedia(currentImage);      
                            }
                            else{
                                methods.loadLightboxImage(currentImage);
                            }
                        }); 
                    },
                    hideLightbox:function(){// Hide Lightbox
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID).fadeOut(LightboxDisplayTime, function(){
                            lightboxCurrentImage = 0;
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').css('opacity', 0);
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_Lightbox').html('');
                        });                        
                    },
                    loadLightboxImage:function(no){// Load Lightbox Image
                        var img = new Image(),                      
                        startLightbox = false;
                        
                        if (lightboxCurrentImage == 0){
                            startLightbox = true;
                        }                        
                            
                        clearInterval(SlideshowID);
                        lightboxCurrentImage = no;
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxLoader').css('display', 'block');
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_Info .current').html(no);
                        
                        if (no == 1){
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_PrevBtn').css('display', 'none');
                        }
                        else{
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_PrevBtn').css('display', 'block');
                        }
                        
                        if (no == noImages){
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_NextBtn').css('display', 'none');
                        }
                        else{
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_NextBtn').css('display', 'block');
                        }
                        
                        $(img).load(function(){
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxLoader').css('display', 'none');
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_Lightbox').html(this);
                            lightboxImageWidth = $(this).width();
                            lightboxImageHeight = $(this).height();
                            lightboxImageLoaded = true;
                            methods.rpLightboxImage();
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').stop(true, true).animate({'opacity': 1}, LightboxDisplayTime, function(){
                                if (!startLightbox){
                                    methods.loadImage(no);
                                }
                            });
                        }).attr('src', Images[no-1]);
                    },
                    loadLightboxMedia:function(no){// Load Lightbox Media                          
                        var startLightbox = false;
                        
                        if (lightboxCurrentImage == 0){
                            startLightbox = true;
                        }
                        
                        clearInterval(SlideshowID);
                        lightboxCurrentImage = no;
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxLoader').css('display', 'block');
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_Info .current').html(no);
                        
                        if (no == 1){
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_PrevBtn').css('display', 'none');
                        }
                        else{
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_PrevBtn').css('display', 'block');
                        }
                        
                        if (no == noImages){
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_NextBtn').css('display', 'none');
                        }
                        else{
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_NextBtn').css('display', 'block');
                        }
                        
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxLoader').css('display', 'none');
                        
                        if (LightboxMedia[no-1] != ''){
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_Lightbox').html(LightboxMedia[no-1]);
                        }
                        else{
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_Lightbox').html(Media[no-1]);                            
                        }
                        
                        var iframeSRC =  $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_Lightbox').children().attr('src');
                        
                        if (iframeSRC != null){
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_Lightbox').children().attr('src', iframeSRC+'?wmode=transparent');
                        }

                        lightboxImageLoaded = true;
                        methods.rpLightboxMedia();

                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').stop(true, true).animate({'opacity': 1}, LightboxDisplayTime, function(){
                            if (!startLightbox){
                                if (Media[no-1] != ''){
                                    methods.loadMedia(no);
                                }
                                else{
                                    methods.loadImage(no);
                                }
                            }
                        });
                    },
                    previousLightbox:function(){
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').stop(true, true).animate({'opacity': 0}, LightboxDisplayTime, function(){
                            if (Media[lightboxCurrentImage-2] != '' || LightboxMedia[lightboxCurrentImage-2] != ''){
                                methods.loadLightboxMedia(lightboxCurrentImage-1);
                            }
                            else{
                                methods.loadLightboxImage(lightboxCurrentImage-1);
                            }
                        });                        
                    },
                    nextLightbox:function(){
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').stop(true, true).animate({'opacity': 0}, LightboxDisplayTime, function(){
                            if (Media[lightboxCurrentImage] != '' || LightboxMedia[lightboxCurrentImage] != ''){
                                methods.loadLightboxMedia(lightboxCurrentImage+1);
                            }
                            else{
                                methods.loadLightboxImage(lightboxCurrentImage+1);
                            }
                        });                                                
                    },
                    rpLightboxImage:function(){// Resize & Position Lightbox Image
                        var maxWidth = $(window).width()-LightboxMarginRight-LightboxMarginLeft-LightboxPaddingRight-LightboxPaddingLeft, 
                        maxHeight = $(window).height()-LightboxMarginTop-LightboxMarginBottom-LightboxPaddingTop-LightboxPaddingBottom,
                        currW, currH;
                        
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID).width($(document).width());
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID).height($(document).height());
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxWindow').width($(document).width());
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxWindow').height($(document).height());
                        
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID).css('display', 'block');
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxLoader').css('display', 'block');
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxLoader').css({'top': ($(window).height()-$('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxLoader').height())/2,
                                                                                                                    'left': ($(window).width()-$('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxLoader').width())/2});
                        if (lightboxCurrentImage == 0){
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID).css('display', 'none');                         
                        }
                        
                        if (lightboxCurrentImage == 0 || lightboxImageLoaded){
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxLoader').css('display', 'none');
                        }
                        
                        if (lightboxImageLoaded){  
                            if (lightboxImageWidth <= maxWidth && lightboxImageHeight <= maxHeight){
                                currW = lightboxImageWidth;
                                currH = lightboxImageHeight;
                            }
                            else{
                                currH = maxHeight;
                                currW = (lightboxImageWidth*maxHeight)/lightboxImageHeight;

                                if (currW > maxWidth){
                                    currW = maxWidth;
                                    currH = (lightboxImageHeight*maxWidth)/lightboxImageWidth;
                                }
                            }

                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_Lightbox img').width(currW);
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_Lightbox img').height(currH);
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_Lightbox img').css({'margin-top': LightboxPaddingTop,
                                                                                                                      'margin-left': LightboxPaddingLeft});
                            
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').width(currW+LightboxPaddingRight+LightboxPaddingLeft);
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').height(currH+LightboxPaddingTop+LightboxPaddingBottom);
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxBg').width(currW+LightboxPaddingRight+LightboxPaddingLeft);
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxBg').height(currH+LightboxPaddingTop+LightboxPaddingBottom);
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').css({'margin-top': ($(window).height()-$('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').height())/2,
                                                                                                                           'margin-left': ($(window).width()-$('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').width())/2});
                            methods.rpLightboxNavigation();
                        }
                    },
                    rpLightboxMedia:function(){// Resize & Position Lightbox Media
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_Lightbox').css({'height': $(document).height(),
                                                                                                              'width': $(document).width()});
                                                                                                          
                        var currW = $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_Lightbox').children().width(),
                        currH = $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_Lightbox').children().height();
                                                
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID).width($(document).width());
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID).height($(document).height());
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxWindow').width($(document).width());
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxWindow').height($(document).height());
                        
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID).css('display', 'block');
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxLoader').css('display', 'block');
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxLoader').css({'top': ($(window).height()-$('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxLoader').height())/2,
                                                                                                                    'left': ($(window).width()-$('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxLoader').width())/2});
                        if (lightboxCurrentImage == 0){
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID).css('display', 'none');                         
                        }
                        
                        if (lightboxCurrentImage == 0 || lightboxImageLoaded){
                            $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxLoader').css('display', 'none');
                        }
                        
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_Lightbox').css({'height': $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_Lightbox').children().height(),
                                                                                                              'width': $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_Lightbox').children().width()});

                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_Lightbox').children().css({'margin-top': LightboxPaddingTop,
                                                                                                                         'margin-left': LightboxPaddingLeft});
                                                                                                                  
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').width(currW+LightboxPaddingRight+LightboxPaddingLeft);
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').height(currH+LightboxPaddingTop+LightboxPaddingBottom);
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxBg').width(currW+LightboxPaddingRight+LightboxPaddingLeft);
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxBg').height(currH+LightboxPaddingTop+LightboxPaddingBottom);
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').css({'margin-top': ($(window).height()-$('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').height())/2,
                                                                                                                       'margin-left': ($(window).width()-$('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').width())/2});                                                                                                                                                                                                                                              
                        methods.rpLightboxNavigation();
                    },
                    rpLightboxNavigation:function(){// Resize & Position Lightbox Navigation
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_PrevBtn').css({'height': $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_PrevBtn img:first-child').height(),
                                                                                                                                'margin-top': ($('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').height()-$('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_PrevBtn').height())/2,
                                                                                                                                'margin-left': LightboxPaddingLeft+10});
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_NextBtn').css({'height': $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_NextBtn img:first-child').height(),
                                                                                                                                'margin-top': ($('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').height()-$('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_PrevBtn').height())/2,
                                                                                                                                'margin-left': $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').width()-LightboxPaddingRight-10-$('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_NextBtn').width()});
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_CloseBtn').css({'height': $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_CloseBtn img:first-child').height(),
                                                                                                                                 'margin-top': LightboxPaddingTop+10,
                                                                                                                                 'margin-left': $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').width()-LightboxPaddingRight-10-$('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_CloseBtn').width()});                            
                        $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_Info').css({'margin-top': $('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').height()-LightboxPaddingBottom-$('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_Info').height(),
                                                                                                                             'margin-left': ($('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxContainer').width()-$('#DOP_ThumbnailGallery_LightboxWrapper_'+ID+' .DOP_ThumbnailGallery_LightboxNavigation_Info').width())/2});                        
                    },                    
                    
                    initTooltip:function(){// Init Tooltip                        
                        $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).mousemove(function(e){
                            var mousePositionX = e.clientX-$(this).offset().left+parseInt($(this).css('margin-left'))+$(document).scrollLeft();
                            var mousePositionY = e.clientY-$(this).offset().top+parseInt($(this).css('margin-top'))+$(document).scrollTop();

                            $('.DOP_ThumbnailGallery_Tooltip', Container).css('margin-left', mousePositionX-10);
                            $('.DOP_ThumbnailGallery_Tooltip', Container).css('margin-top', mousePositionY-$('.DOP_ThumbnailGallery_Tooltip', Container).height()-15);
                        });
                    },
                    showTooltip:function(no){// Resize, Position & Display the Tooltip
                        var HTML = new Array();
                        HTML.push(CaptionTitle[no]);
                        HTML.push('<div class="DOP_ThumbnailGallery_Tooltip_ArrowBorder"></div>');
                        HTML.push('<div class="DOP_ThumbnailGallery_Tooltip_Arrow"></div>');
                        $('.DOP_ThumbnailGallery_Tooltip', Container).html(HTML.join(""));

                        if (TooltipBgColor != 'css'){
                            $('.DOP_ThumbnailGallery_Tooltip', Container).css('background-color', '#'+TooltipBgColor);
                            $('.DOP_ThumbnailGallery_Tooltip_Arrow', Container).css('border-top-color', '#'+TooltipBgColor);
                        }
                        if (TooltipStrokeColor != 'css'){
                            $('.DOP_ThumbnailGallery_Tooltip', Container).css('border-color', '#'+TooltipStrokeColor);
                            $('.DOP_ThumbnailGallery_Tooltip_ArrowBorder', Container).css('border-top-color', '#'+TooltipStrokeColor);
                        }
                        if (TooltipTextColor != 'css'){
                            $('.DOP_ThumbnailGallery_Tooltip', Container).css('color', '#'+TooltipTextColor);
                        }
                        if (CaptionTitle[no] != '' || prototypes.isTouchDevice()){
                            $('.DOP_ThumbnailGallery_Tooltip', Container).css('display', 'block');
                        }
                    },

                    initAutoHide:function(){// Init Auto Hide
                        HideID = setInterval(methods.hideItems, parseInt(AutoHideTime));

                        $('.DOP_ThumbnailGallery_Container', Container).hover(function(){
                            methods.showItems();
                        }, function(){
                            HideID = setInterval(methods.hideItems, parseInt(AutoHideTime));
                        });
                    },
                    showItems:function(){// Show Items
                        clearInterval(HideID);
                        ItemsHidden = false;

                        if (imageLoaded){
                            if (NavigationEnabled == 'true'){                                
                                $('.DOP_ThumbnailGallery_NavigationLeft', Container).css('display', 'block');
                                $('.DOP_ThumbnailGallery_NavigationRight', Container).css('display', 'block');
                                
                                if (LightboxEnabled == 'true'){
                                    $('.DOP_ThumbnailGallery_NavigationLightbox', Container).css('display', 'block');
                                }
                            }
                        }

                        if (ThumbnailsPosition == 'top'){
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).stop(true, true).animate({'margin-top': 0}, AutoHideDisplayTime);
                        }
                        if (ThumbnailsPosition == 'right'){
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).stop(true, true).animate({'margin-left': $('.DOP_ThumbnailGallery_Container', Container).width()-$('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).width()}, AutoHideDisplayTime);
                        }
                        if (ThumbnailsPosition == 'bottom'){
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).stop(true, true).animate({'margin-top': $('.DOP_ThumbnailGallery_Container', Container).height()-$('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).height()}, AutoHideDisplayTime);
                        }
                        if (ThumbnailsPosition == 'left'){
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).stop(true, true).animate({'margin-left': 0}, AutoHideDisplayTime);
                        }
                        methods.showCaption();
                    },
                    hideItems:function(){// Hide Items
                        clearInterval(HideID);
                        ItemsHidden = true;

                        if (NavigationEnabled == 'true'){                                
                            $('.DOP_ThumbnailGallery_NavigationLeft', Container).css('display', 'none');
                            $('.DOP_ThumbnailGallery_NavigationRight', Container).css('display', 'none');

                            if (LightboxEnabled == 'true'){
                                $('.DOP_ThumbnailGallery_NavigationLightbox', Container).css('display', 'none');
                            }
                        }

                        if (ThumbnailsPosition == 'top'){
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).stop(true, true).animate({'margin-top': 0-$('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).height()}, AutoHideDisplayTime);
                        }
                        if (ThumbnailsPosition == 'right'){
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).stop(true, true).animate({'margin-left': $('.DOP_ThumbnailGallery_Container', Container).width()}, AutoHideDisplayTime);
                        }
                        if (ThumbnailsPosition == 'bottom'){
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).stop(true, true).animate({'margin-top': $('.DOP_ThumbnailGallery_Container', Container).height()}, AutoHideDisplayTime);
                        }
                        if (ThumbnailsPosition == 'left'){
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).stop(true, true).animate({'margin-left': 0-$('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).width()}, AutoHideDisplayTime);
                        }
                        methods.hideCaption();
                    }
                  },

        prototypes = {
                        resizeItem:function(parent, child, cw, ch, dw, dh, pos){// Resize & Position an Item (the item is 100% visible)
                            var currW = 0, currH = 0;

                            if (dw <= cw && dh <= ch){
                                currW = dw;
                                currH = dh;
                            }
                            else{
                                currH = ch;
                                currW = (dw*ch)/dh;

                                if (currW > cw){
                                    currW = cw;
                                    currH = (dh*cw)/dw;
                                }
                            }

                            child.width(currW);
                            child.height(currH);
                            switch(pos.toLowerCase()){
                                case 'top':
                                    prototypes.topItem(parent, child, ch);
                                    break;
                                case 'bottom':
                                    prototypes.bottomItem(parent, child, ch);
                                    break;
                                case 'left':
                                    prototypes.leftItem(parent, child, cw);
                                    break;
                                case 'right':
                                    prototypes.rightItem(parent, child, cw);
                                    break;
                                case 'horizontal-center':
                                    prototypes.hCenterItem(parent, child, cw);
                                    break;
                                case 'vertical-center':
                                    prototypes.vCenterItem(parent, child, ch);
                                    break;
                                case 'center':
                                    prototypes.centerItem(parent, child, cw, ch);
                                    break;
                                case 'top-left':
                                    prototypes.tlItem(parent, child, cw, ch);
                                    break;
                                case 'top-center':
                                    prototypes.tcItem(parent, child, cw, ch);
                                    break;
                                case 'top-right':
                                    prototypes.trItem(parent, child, cw, ch);
                                    break;
                                case 'middle-left':
                                    prototypes.mlItem(parent, child, cw, ch);
                                    break;
                                case 'middle-right':
                                    prototypes.mrItem(parent, child, cw, ch);
                                    break;
                                case 'bottom-left':
                                    prototypes.blItem(parent, child, cw, ch);
                                    break;
                                case 'bottom-center':
                                    prototypes.bcItem(parent, child, cw, ch);
                                    break;
                                case 'bottom-right':
                                    prototypes.brItem(parent, child, cw, ch);
                                    break;
                            }
                        },
                        resizeItem2:function(parent, child, cw, ch, dw, dh, pos){// Resize & Position an Item (the item covers all the container)
                            var currW = 0, currH = 0;

                            currH = ch;
                            currW = (dw*ch)/dh;

                            if (currW < cw){
                                currW = cw;
                                currH = (dh*cw)/dw;
                            }

                            child.width(currW);
                            child.height(currH);

                            switch(pos.toLowerCase()){
                                case 'top':
                                    prototypes.topItem(parent, child, ch);
                                    break;
                                case 'bottom':
                                    prototypes.bottomItem(parent, child, ch);
                                    break;
                                case 'left':
                                    prototypes.leftItem(parent, child, cw);
                                    break;
                                case 'right':
                                    prototypes.rightItem(parent, child, cw);
                                    break;
                                case 'horizontal-center':
                                    prototypes.hCenterItem(parent, child, cw);
                                    break;
                                case 'vertical-center':
                                    prototypes.vCenterItem(parent, child, ch);
                                    break;
                                case 'center':
                                    prototypes.centerItem(parent, child, cw, ch);
                                    break;
                                case 'top-left':
                                    prototypes.tlItem(parent, child, cw, ch);
                                    break;
                                case 'top-center':
                                    prototypes.tcItem(parent, child, cw, ch);
                                    break;
                                case 'top-right':
                                    prototypes.trItem(parent, child, cw, ch);
                                    break;
                                case 'middle-left':
                                    prototypes.mlItem(parent, child, cw, ch);
                                    break;
                                case 'middle-right':
                                    prototypes.mrItem(parent, child, cw, ch);
                                    break;
                                case 'bottom-left':
                                    prototypes.blItem(parent, child, cw, ch);
                                    break;
                                case 'bottom-center':
                                    prototypes.bcItem(parent, child, cw, ch);
                                    break;
                                case 'bottom-right':
                                    prototypes.brItem(parent, child, cw, ch);
                                    break;
                            }
                        },

                        topItem:function(parent, child, ch){// Position Item on Top
                            parent.height(ch);
                            child.css('margin-top', 0);
                        },
                        bottomItem:function(parent, child, ch){// Position Item on Bottom
                            parent.height(ch);
                            child.css('margin-top', ch-child.height());
                        },
                        leftItem:function(parent, child, cw){// Position Item on Left
                            parent.width(cw);
                            child.css('margin-left', 0);
                        },
                        rightItem:function(parent, child, cw){// Position Item on Right
                            parent.width(cw);
                            child.css('margin-left', parent.width()-child.width());
                        },
                        hCenterItem:function(parent, child, cw){// Position Item on Horizontal Center
                            parent.width(cw);
                            child.css('margin-left', (cw-child.width())/2);
                        },
                        vCenterItem:function(parent, child, ch){// Position Item on Vertical Center
                            parent.height(ch);
                            child.css('margin-top', (ch-child.height())/2);
                        },
                        centerItem:function(parent, child, cw, ch){// Position Item on Center
                            prototypes.hCenterItem(parent, child, cw);
                            prototypes.vCenterItem(parent, child, ch);
                        },
                        tlItem:function(parent, child, cw, ch){// Position Item on Top-Left
                            prototypes.topItem(parent, child, ch);
                            prototypes.leftItem(parent, child, cw);
                        },
                        tcItem:function(parent, child, cw, ch){// Position Item on Top-Center
                            prototypes.topItem(parent, child, ch);
                            prototypes.hCenterItem(parent, child, cw);
                        },
                        trItem:function(parent, child, cw, ch){// Position Item on Top-Right
                            prototypes.topItem(parent, child, ch);
                            prototypes.rightItem(parent, child, cw);
                        },
                        mlItem:function(parent, child, cw, ch){// Position Item on Middle-Left
                            prototypes.vCenterItem(parent, child, ch);
                            prototypes.leftItem(parent, child, cw);
                        },
                        mrItem:function(parent, child, cw, ch){// Position Item on Middle-Right
                            prototypes.vCenterItem(parent, child, ch);
                            prototypes.rightItem(parent, child, cw);
                        },
                        blItem:function(parent, child, cw, ch){// Position Item on Bottom-Left
                            prototypes.bottomItem(parent, child, ch);
                            prototypes.leftItem(parent, child, cw);
                        },
                        bcItem:function(parent, child, cw, ch){// Position Item on Bottom-Center
                            prototypes.bottomItem(parent, child, ch);
                            prototypes.hCenterItem(parent, child, cw);
                        },
                        brItem:function(parent, child, cw, ch){// Position Item on Bottom-Right
                            prototypes.bottomItem(parent, child, ch);
                            prototypes.rightItem(parent, child, cw);
                        },

                        longMonth:function(month){// Return month with 0 in front if smaller then 10.
                            if (month < 10){
                                return '0'+month;
                            }
                            else{
                                return month;
                            }

                        },
                        longDay:function(day){// Return day with 0 in front if smaller then 10.
                            if (day < 10){
                                return '0'+day;
                            }
                            else{
                                return day;
                            }
                        },

                        randomize:function(theArray){// Randomize the items of an array
                            theArray.sort(function(){
                                return 0.5-Math.random();
                            });
                            return theArray;
                        },
                        randomString:function(string_length){// Create a string with random elements
                            var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz",
                            random_string = '';

                            for (var i=0; i<string_length; i++){
                                var rnum = Math.floor(Math.random()*chars.length);
                                random_string += chars.substring(rnum,rnum+1);
                            }
                            return random_string;
                        },

                        isIE8Browser:function(){// Detect the browser IE8
                            var isIE8 = false,
                            agent = navigator.userAgent.toLowerCase();

                            if (agent.indexOf('msie 8') != -1){
                                isIE8 = true;
                            }
                            return isIE8;
                        },
                        isTouchDevice:function(){// Detect Touchscreen devices
                            var isTouch = false,
                            agent = navigator.userAgent.toLowerCase();

                            if (agent.indexOf('android') != -1){
                                isTouch = true;
                            }
                            if (agent.indexOf('blackberry') != -1){
                                isTouch = true;
                            }
                            if (agent.indexOf('ipad') != -1){
                                isTouch = true;
                            }
                            if (agent.indexOf('iphone') != -1){
                                isTouch = true;
                            }
                            if (agent.indexOf('ipod') != -1){
                                isTouch = true;
                            }
                            if (agent.indexOf('palm') != -1){
                                isTouch = true;
                            }
                            if (agent.indexOf('series60') != -1){
                                isTouch = true;
                            }
                            if (agent.indexOf('symbian') != -1){
                                isTouch = true;
                            }
                            if (agent.indexOf('windows ce') != -1){
                                isTouch = true;
                            }

                            return isTouch;
                        },
                        touchNavigation:function(parent, child){// One finger Navigation for touchscreen devices
                            var prevX, prevY, currX, currY, touch;

                            parent.bind('touchstart', function(e){
                                touch = e.originalEvent.touches[0];
                                prevX = touch.clientX;
                                prevY = touch.clientY;
                            });

                            parent.bind('touchmove', function(e){
                                e.preventDefault();

                                var touch = e.originalEvent.touches[0],
                                currX = touch.clientX,
                                currY = touch.clientY,
                                thumbnailsPositionX = currX>prevX ? parseInt(child.css('margin-left'))+(currX-prevX):parseInt(child.css('margin-left'))-(prevX-currX),
                                thumbnailsPositionY = currY>prevY ? parseInt(child.css('margin-top'))+(currY-prevY):parseInt(child.css('margin-top'))-(prevY-currY);

                                if (thumbnailsPositionX < (-1)*(child.width()-parent.width())){
                                    thumbnailsPositionX = (-1)*(child.width()-parent.width());
                                }
                                else if (thumbnailsPositionX > 0){
                                    thumbnailsPositionX = 0;
                                }
                                if (thumbnailsPositionY < (-1)*(child.height()-parent.height())){
                                    thumbnailsPositionY = (-1)*(child.height()-parent.height());
                                }
                                else if (thumbnailsPositionY > 0){
                                    thumbnailsPositionY = 0;
                                }

                                prevX = currX;
                                prevY = currY;

                                child.css('margin-left', thumbnailsPositionX);
                                child.css('margin-top', thumbnailsPositionY);
                            });

                            parent.bind('touchend', function(e){
                                e.preventDefault();
                            });
                        },

                        openLink:function(url, target){// Open a link.
                            if (target.toLowerCase() == '_blank'){
                                window.open(url);
                            }
                            else{
                                window.location = url;
                            }
                        }
                     };

        return methods.init.apply(this);
    }
})(jQuery);
