
/*
* Title                   : Thumbnail Gallery
* Version                 : 1.1
* File                    : jquery.dop.ThumbnailGallery.js
* File Version            : 1.1
* Created / Last Modified : 20 May 2011
* Author                  : Marius-Cristian Donea
* Copyright               : © 2011 Marius-Cristian Donea
* Website                 : http://www.mariuscristiandonea.com
* Description             : Thumbnail Gallery jQuery Plugin.
*/

(function($){
    $.fn.DOPThumbnailGallery = function(options){
        var Data = {'Content':''},

        Container = this,
        
        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,
        
        Navigation = 'true',
        NavigationColor = 'ffffff',
        NavigationColorHover = 'ffffff',
        NavigationIconColor = '000000',
        NavigationIconColorHover = '000000',
        NavigationAlpha = '20',
        NavigationAlphaHover = '60',

        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,
        
        TooltipEnabled = 'false',
        TooltipBgColor = 'ffffff',
        TooltipStrokeColor = '000000',
        TooltipTextColor = '000000',
        
        Slideshow = 'false',
        SlideshowTime = '5000',
        SlideshowLoop = 'true',

        AutoHide = 'false',
        AutoHideTime = '2000',
        
        Images = new Array(),
        Thumbs = new Array(),
        CaptionTitle = new Array(),
        CaptionText = new Array(),
        noImages = 0,
        
        BgImageLoaded = false,
        BgImageWidth = 0,
        BgImageHeight = 0,

        currentImage = 0,
        imageLoaded = false,
        ImageWidth = 0,
        ImageHeight = 0,

        SlideshowID,

        HideID,
        ItemsHidden,

        methods = {
                    init:function(){// Init Plugin.
                        return this.each(function(){
                            if (options){
                                $.extend(Data, options);
                            }
                            methods.parseData(Data['Content']);
                            $(window).bind('resize.DOPThumbnailGallery', methods.initRP);
                            $(window).bind('scroll.DOPThumbnailGallery', methods.initRP);
                        });
                    },
                    parseData:function(data){// Parse the Settings XML.
                        var settings = data.split('|||||')[0],
                        content = data.split('|||||')[1],
                        settingsItem = new Array(),
                        images = new Array(), i;

                        settingsItem = settings.split(';');
                        images = content.split(';;;');

                        if (settingsItem[0] != 'default0123456789'){
                            Width = parseInt(settingsItem[0]);
                        }
                        if (settingsItem[1] != 'default0123456789'){
                            Height = parseInt(settingsItem[1]);
                        }
                        if (settingsItem[2] != 'default0123456789'){
                            BgColor = settingsItem[2];
                        }
                        if (settingsItem[3] != 'default0123456789'){
                            BgAlpha = settingsItem[3];
                        }

                        if (settingsItem[4] != 'default0123456789'){
                            ThumbnailsPosition = settingsItem[4];
                        }
                        if (settingsItem[5] != 'default0123456789'){
                            ThumbnailsOverImage = settingsItem[5];
                        }
                        if (settingsItem[6] != 'default0123456789'){
                            ThumbnailsBgColor = settingsItem[6];
                        }
                        if (settingsItem[7] != 'default0123456789'){
                            ThumbnailsBgAlpha = settingsItem[7];
                        }
                        if (settingsItem[8] != 'default0123456789'){
                            ThumbnailsSpacing =  parseInt(settingsItem[8]);
                        }
                        if (settingsItem[9] != 'default0123456789'){
                            ThumbnailsPaddingTop = parseInt(settingsItem[9]);
                        }
                        if (settingsItem[10] != 'default0123456789'){
                            ThumbnailsPaddingRight = parseInt(settingsItem[10]);
                        }
                        if (settingsItem[11] != 'default0123456789'){
                            ThumbnailsPaddingBottom = parseInt(settingsItem[11]);
                        }
                        if (settingsItem[12] != 'default0123456789'){
                            ThumbnailsPaddingLeft = parseInt(settingsItem[12]);
                        }

                        if (settingsItem[13] != 'default0123456789'){
                            ThumbnailLoader = settingsItem[13];
                        }
                        if (settingsItem[14] != 'default0123456789'){
                            ThumbnailWidth = parseInt(settingsItem[14]);
                        }
                        if (settingsItem[15] != 'default0123456789'){
                            ThumbnailHeight = parseInt(settingsItem[15]);
                        }
                        if (settingsItem[16] != 'default0123456789'){
                            ThumbnailAlpha = settingsItem[16];
                        }
                        if (settingsItem[17] != 'default0123456789'){
                            ThumbnailAlphaHover = settingsItem[17];
                        }
                        if (settingsItem[18] != 'default0123456789'){
                            ThumbnailAlphaSelected = settingsItem[18];
                        }
                        if (settingsItem[19] != 'default0123456789'){
                            ThumbnailBgColor = settingsItem[19];
                        }
                        if (settingsItem[20] != 'default0123456789'){
                            ThumbnailBgColorHover = settingsItem[20];
                        }
                        if (settingsItem[21] != 'default0123456789'){
                            ThumbnailBgColorSelected = settingsItem[21];
                        }
                        if (settingsItem[22] != 'default0123456789'){
                            ThumbnailBorderSize = parseInt(settingsItem[22]);
                        }
                        if (settingsItem[23] != 'default0123456789'){
                            ThumbnailBorderColor = settingsItem[23];
                        }
                        if (settingsItem[24] != 'default0123456789'){
                            ThumbnailBorderColorHover = settingsItem[24];
                        }
                        if (settingsItem[25] != 'default0123456789'){
                            ThumbnailBorderColorSelected = settingsItem[25];
                        }
                        if (settingsItem[26] != 'default0123456789'){
                            ThumbnailPaddingTop = parseInt(settingsItem[26]);
                        }
                        if (settingsItem[27] != 'default0123456789'){
                            ThumbnailPaddingRight = parseInt(settingsItem[27]);
                        }
                        if (settingsItem[28] != 'default0123456789'){
                            ThumbnailPaddingBottom = parseInt(settingsItem[28]);
                        }
                        if (settingsItem[29] != 'default0123456789'){
                            ThumbnailPaddingLeft = parseInt(settingsItem[29]);
                        }

                        if (settingsItem[30] != 'default0123456789'){
                            ImageLoader = settingsItem[30];
                        }
                        if (settingsItem[31] != 'default0123456789'){
                            ImageBgColor = settingsItem[31];
                        }
                        if (settingsItem[32] != 'default0123456789'){
                            ImageBgAlpha = settingsItem[32];
                        }
                        if (settingsItem[33] != 'default0123456789'){
                            ImageDisplayType = settingsItem[33];
                        }
                        if (settingsItem[34] != 'default0123456789'){
                            ImageDisplayTime = settingsItem[34];
                        }
                        if (settingsItem[35] != 'default0123456789'){
                            ImageMarginTop = parseInt(settingsItem[35]);
                        }
                        if (settingsItem[36] != 'default0123456789'){
                            ImageMarginRight = parseInt(settingsItem[36]);
                        }
                        if (settingsItem[37] != 'default0123456789'){
                            ImageMarginBottom = parseInt(settingsItem[37]);
                        }
                        if (settingsItem[38] != 'default0123456789'){
                            ImageMarginLeft = parseInt(settingsItem[38]);
                        }
                        if (settingsItem[39] != 'default0123456789'){
                            ImagePaddingTop = parseInt(settingsItem[39]);
                        }
                        if (settingsItem[40] != 'default0123456789'){
                            ImagePaddingRight = parseInt(settingsItem[40]);
                        }
                        if (settingsItem[41] != 'default0123456789'){
                            ImagePaddingBottom = parseInt(settingsItem[41]);
                        }
                        if (settingsItem[42] != 'default0123456789'){
                            ImagePaddingLeft = parseInt(settingsItem[42]);
                        }

                        if (settingsItem[43] != 'default0123456789'){
                            Navigation = settingsItem[43];
                        }
                        if (settingsItem[44] != 'default0123456789'){
                            NavigationColor = settingsItem[44];
                        }
                        if (settingsItem[45] != 'default0123456789'){
                            NavigationColorHover = settingsItem[45];
                        }
                        if (settingsItem[46] != 'default0123456789'){
                            NavigationIconColor = settingsItem[46];
                        }
                        if (settingsItem[47] != 'default0123456789'){
                            NavigationIconColorHover = settingsItem[47];
                        }
                        if (settingsItem[48] != 'default0123456789'){
                            NavigationAlpha = settingsItem[48];
                        }
                        if (settingsItem[49] != 'default0123456789'){
                            NavigationAlphaHover = settingsItem[49];
                        }

                        if (settingsItem[50] != 'default0123456789'){
                            CaptionWidth = parseInt(settingsItem[50]);
                        }
                        if (settingsItem[51] != 'default0123456789'){
                            CaptionHeight = parseInt(settingsItem[51]);
                        }
                        if (settingsItem[52] != 'default0123456789'){
                            CaptionTitleColor = settingsItem[52];
                        }
                        if (settingsItem[53] != 'default0123456789'){
                            CaptionTextColor = settingsItem[53];
                        }
                        if (settingsItem[54] != 'default0123456789'){
                            CaptionBgColor = settingsItem[54];
                        }
                        if (settingsItem[55] != 'default0123456789'){
                            CaptionBgAlpha = settingsItem[55];
                        }
                        if (settingsItem[56] != 'default0123456789'){
                            CaptionPosition = settingsItem[56];
                        }
                        if (settingsItem[57] != 'default0123456789'){
                            CaptionScrollScrubColor = settingsItem[57];
                        }
                        if (settingsItem[58] != 'default0123456789'){
                            CaptionScrollBgColor = settingsItem[58];
                        }
                        if (settingsItem[59] != 'default0123456789'){
                            CaptionMarginTop = parseInt(settingsItem[59]);
                        }
                        if (settingsItem[60] != 'default0123456789'){
                            CaptionMarginRight = parseInt(settingsItem[60]);
                        }
                        if (settingsItem[61] != 'default0123456789'){
                            CaptionMarginBottom = parseInt(settingsItem[61]);
                        }
                        if (settingsItem[62] != 'default0123456789'){
                            CaptionMarginLeft = parseInt(settingsItem[62]);
                        }
                        if (settingsItem[63] != 'default0123456789'){
                            CaptionPaddingTop = parseInt(settingsItem[63]);
                        }
                        if (settingsItem[64] != 'default0123456789'){
                            CaptionPaddingRight = parseInt(settingsItem[64]);
                        }
                        if (settingsItem[65] != 'default0123456789'){
                            CaptionPaddingBottom = parseInt(settingsItem[65]);
                        }
                        if (settingsItem[66] != 'default0123456789'){
                            CaptionPaddingLeft = parseInt(settingsItem[66]);
                        }

                        if (settingsItem[67] != 'default0123456789'){
                            TooltipEnabled = settingsItem[67];
                        }
                        if (settingsItem[68] != 'default0123456789'){
                            TooltipBgColor = settingsItem[68];
                        }
                        if (settingsItem[69] != 'default0123456789'){
                            TooltipStrokeColor = settingsItem[69];
                        }
                        if (settingsItem[70] != 'default0123456789'){
                            TooltipTextColor = settingsItem[70];
                        }

                        if (settingsItem[71] != 'default0123456789'){
                            Slideshow = settingsItem[71];
                        }
                        if (settingsItem[72] != 'default0123456789'){
                            SlideshowTime = settingsItem[72];
                        }
                        if (settingsItem[73] != 'default0123456789'){
                            SlideshowLoop = settingsItem[73];
                        }

                        if (settingsItem[74] != 'default0123456789'){
                            AutoHide = settingsItem[74];
                        }
                        if (settingsItem[75] != 'default0123456789'){
                            AutoHideTime = settingsItem[75];
                        }

                        for (i=0; i<images.length; i++){
                            Images.push(images[i].split(':::')[0]);
                            Thumbs.push(images[i].split(':::')[1]);
                            if (images[i].split(':::')[2] == 'default0123456789'){
                                CaptionTitle.push('');
                            }
                            else{
                                CaptionTitle.push(images[i].split(':::')[2]);
                            }
                            if (images[i].split(':::')[3] == 'default0123456789'){
                                CaptionText.push('');
                            }
                            else{
                                CaptionText.push(images[i].split(':::')[3]);
                            }
                        }

                        noImages = images.length;

                        methods.initGallery();
                    },
                    initGallery:function(){// Init the Gallery
                        var HTML = 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 (Navigation == 'true'){
                            HTML.push('   <div class="DOP_ThumbnailGallery_NavigationLeft">');
                            HTML.push('       <div class="Icon"></div>');
                            HTML.push('   </div>');
                            HTML.push('   <div class="DOP_ThumbnailGallery_NavigationRight">');
                            HTML.push('       <div class="Icon"></div>');
                            HTML.push('   </div>');
                        }
                        
                        if (TooltipEnabled == 'true'){
                            HTML.push('   <div class="DOP_ThumbnailGallery_Tooltip"></div>');
                        }

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

                        Container.html(HTML.join(""));
                        methods.initSettings();
                    },
                    initSettings:function(){// Init Settings
                        methods.initContainer();
                        methods.initBackground();
                        methods.initThumbnails();
                        methods.initImage();
                        if (Navigation == 'true'){
                            methods.initNavigation();
                        }
                        if (TooltipEnabled == 'true'){
                            methods.initTooltip();
                        }
                        methods.initCaption();
                        if (AutoHide == 'true'){
                            methods.initAutoHide();
                        }
                    },
                    initRP:function(){// Init Resize & Positioning
                        methods.rpContainer();
                        methods.rpBackground();
                        methods.rpThumbnails();
                        methods.rpImage();
                        if (Navigation == 'true'){
                            methods.rpNavigation();
                        }
                    },

                    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', parseInt(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', parseInt(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);
                        }
                        $('.DOP_ThumbnailGallery_ThumbnailsWrapper', Container).hover(function(){
                            thumbnailsMove = true;
                        });
                        
                        methods.moveThumbnails();
                        methods.loadThumb(1);
                    },
                    loadThumb:function(no){// Load Thumbnail No
                        methods.initThumb(no);
                        var img = new Image();
                        
                        $(img).load(function(){
                            $('#DOP_ThumbnailGallery_Thumb_'+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();
                        ThumbHTML.push('<div class="DOP_ThumbnailGallery_ThumbContainer" id="DOP_ThumbnailGallery_ThumbContainer_'+no+'">');
                        ThumbHTML.push('   <div class="DOP_ThumbnailGallery_Thumb" id="DOP_ThumbnailGallery_Thumb_'+no+'"></div>');
                        ThumbHTML.push('</div>');
                        
                        if (ThumbnailsPosition == 'top' || ThumbnailsPosition == 'bottom'){
                            if (no == 1){
                                $('.DOP_ThumbnailGallery_Thumbnails', Container).width($('.DOP_ThumbnailGallery_Thumbnails', Container).width()+ThumbnailWidth+(2*ThumbnailBorderSize)+ThumbnailPaddingRight+ThumbnailPaddingLeft);
                            }
                            else{
                                $('.DOP_ThumbnailGallery_Thumbnails', Container).width($('.DOP_ThumbnailGallery_Thumbnails', Container).width()+ThumbnailWidth+(2*ThumbnailBorderSize)+ThumbnailPaddingRight+ThumbnailPaddingLeft+ThumbnailsSpacing);
                            }
                        }

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

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

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

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

                        $('#DOP_ThumbnailGallery_ThumbContainer_'+no, Container).addClass('DOP_ThumbnailGallery_ThumbLoader');
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+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_'+no+'.DOP_ThumbnailGallery_ThumbLoader', Container).css('background-image', 'none');
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+no, Container).removeClass('DOP_ThumbnailGallery_ThumbLoader');

                        prototypes.resizeItem2($('#DOP_ThumbnailGallery_Thumb_'+no, Container), $('#DOP_ThumbnailGallery_Thumb_'+no, Container).children(), ThumbnailWidth, ThumbnailHeight, $('#DOP_ThumbnailGallery_Thumb_'+no, Container).children().width(), $('#DOP_ThumbnailGallery_Thumb_'+no, Container).children().height(), 'center');
                        
                        $('img', '#DOP_ThumbnailGallery_Thumb_'+no, Container).css('opacity', 0);
                        $('img', '#DOP_ThumbnailGallery_Thumb_'+no, Container).stop(true, true).animate({'opacity':'1'}, 600);

                        $('#DOP_ThumbnailGallery_ThumbContainer_'+no, Container).hover(function(){
                            if (currentImage != no){
                                $(this).stop(true, true).animate({'opacity':parseInt(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':parseInt(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_'+no, Container).click(function(){
                            if (imageLoaded){
                                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);
                                }
                            });
                        }
                    },

                    initImage:function(){// Init Image
                        if (ImageBgColor != 'css'){
                            $('.DOP_ThumbnailGallery_ImageBg', Container).css('background-color', '#'+ImageBgColor);
                        }
                        $('.DOP_ThumbnailGallery_ImageBg', Container).css('opacity', parseInt(ImageBgAlpha)/100);
                        
                        methods.rpImage();
                        methods.loadImage(1);
                    },
                    loadImage:function(no){// Load Image
                        clearInterval(SlideshowID);
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+currentImage, Container).stop(true, true).animate({'opacity':parseInt(ThumbnailAlpha)/100}, 300);
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+currentImage, Container).css('background-color', '#'+ThumbnailBgColor);
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+currentImage, Container).css('border-color', '#'+ThumbnailBorderColor);
                        currentImage = no;
                        imageLoaded = false;
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+currentImage, Container).stop(true, true).animate({'opacity':parseInt(ThumbnailAlphaSelected)/100}, 300);
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+currentImage, Container).css('background-color', '#'+ThumbnailBgColorSelected);
                        $('#DOP_ThumbnailGallery_ThumbContainer_'+currentImage, Container).css('border-color', '#'+ThumbnailBorderColorSelected);
                        
                        $('.DOP_ThumbnailGallery_NavigationLeft', Container).css('display', 'none');
                        $('.DOP_ThumbnailGallery_NavigationRight', Container).css('display', '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+')');

                            var img = new Image();
                            $(img).load(function(){
                                imageLoaded = true;
                                $('.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+ImagePaddingLeft+ImagePaddingRight;

                                    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();
                                        methods.showCaption();
                                        $('.DOP_ThumbnailGallery_Image', Container).stop(true, true).animate({'opacity':'1'}, parseInt(ImageDisplayTime)/2, function(){
                                            if (!ItemsHidden){
                                                $('.DOP_ThumbnailGallery_NavigationLeft', Container).css('display', 'block');
                                                $('.DOP_ThumbnailGallery_NavigationRight', Container).css('display', 'block');
                                            }

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

                                        if (Slideshow == 'true'){
                                            if  ((SlideshowLoop == 'true' && currentImage == noImages) || currentImage < noImages){
                                                SlideshowID = setInterval(methods.nextImage, parseInt(SlideshowTime));
                                            }
                                        }
                                    });
                                }
                            }).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();
                        methods.rpNavigation();
                    },

                    initNavigation:function(){// Init Navigation
                        $('.DOP_ThumbnailGallery_NavigationLeft', Container).css('background-color', '#'+NavigationColor);
                        $('.DOP_ThumbnailGallery_NavigationRight', Container).css('background-color', '#'+NavigationColor);
                        $('.DOP_ThumbnailGallery_NavigationLeft .Icon', Container).css('border-top-color', '#'+NavigationColor);
                        $('.DOP_ThumbnailGallery_NavigationLeft .Icon', Container).css('border-bottom-color', '#'+NavigationColor);
                        $('.DOP_ThumbnailGallery_NavigationLeft .Icon', Container).css('border-left-color', '#'+NavigationColor);
                        $('.DOP_ThumbnailGallery_NavigationRight .Icon', Container).css('border-top-color', '#'+NavigationColor);
                        $('.DOP_ThumbnailGallery_NavigationRight .Icon', Container).css('border-bottom-color', '#'+NavigationColor);
                        $('.DOP_ThumbnailGallery_NavigationRight .Icon', Container).css('border-right-color', '#'+NavigationColor);

                        $('.DOP_ThumbnailGallery_NavigationLeft .Icon', Container).css('border-right-color', '#'+NavigationIconColor);
                        $('.DOP_ThumbnailGallery_NavigationRight .Icon', Container).css('border-left-color', '#'+NavigationIconColor);

                        $('.DOP_ThumbnailGallery_NavigationLeft').css('opacity', parseInt(NavigationAlpha)/100);
                        $('.DOP_ThumbnailGallery_NavigationRight').css('opacity', parseInt(NavigationAlpha)/100);

                        $('.DOP_ThumbnailGallery_NavigationLeft', Container).hover(function(){
                            $('.DOP_ThumbnailGallery_NavigationLeft', Container).css('background-color', '#'+NavigationColorHover);
                            $('.DOP_ThumbnailGallery_NavigationLeft .Icon', Container).css('border-top-color', '#'+NavigationColorHover);
                            $('.DOP_ThumbnailGallery_NavigationLeft .Icon', Container).css('border-bottom-color', '#'+NavigationColorHover);
                            $('.DOP_ThumbnailGallery_NavigationLeft .Icon', Container).css('border-left-color', '#'+NavigationColorHover);
                            $('.DOP_ThumbnailGallery_NavigationLeft', Container).css('opacity', parseInt(NavigationAlphaHover)/100);
                            $('.DOP_ThumbnailGallery_NavigationLeft .Icon', Container).css('border-right-color', '#'+NavigationIconColorHover);
                        }, function(){
                            $('.DOP_ThumbnailGallery_NavigationLeft', Container).css('background-color', '#'+NavigationColor);
                            $('.DOP_ThumbnailGallery_NavigationLeft .Icon', Container).css('border-top-color', '#'+NavigationColor);
                            $('.DOP_ThumbnailGallery_NavigationLeft .Icon', Container).css('border-bottom-color', '#'+NavigationColor);
                            $('.DOP_ThumbnailGallery_NavigationLeft .Icon', Container).css('border-left-color', '#'+NavigationColor);
                            $('.DOP_ThumbnailGallery_NavigationLeft', Container).css('opacity', parseInt(NavigationAlpha)/100);
                            $('.DOP_ThumbnailGallery_NavigationLeft .Icon', Container).css('border-right-color', '#'+NavigationIconColor);
                        });

                        $('.DOP_ThumbnailGallery_NavigationRight', Container).hover(function(){
                            $('.DOP_ThumbnailGallery_NavigationRight', Container).css('background-color', '#'+NavigationColorHover);
                            $('.DOP_ThumbnailGallery_NavigationRight .Icon', Container).css('border-top-color', '#'+NavigationColorHover);
                            $('.DOP_ThumbnailGallery_NavigationRight .Icon', Container).css('border-bottom-color', '#'+NavigationColorHover);
                            $('.DOP_ThumbnailGallery_NavigationRight .Icon', Container).css('border-right-color', '#'+NavigationColorHover);
                            $('.DOP_ThumbnailGallery_NavigationRight', Container).css('opacity', parseInt(NavigationAlphaHover)/100);
                            $('.DOP_ThumbnailGallery_NavigationRight .Icon', Container).css('border-left-color', '#'+NavigationIconColorHover);
                        }, function(){
                            $('.DOP_ThumbnailGallery_NavigationRight', Container).css('background-color', '#'+NavigationColor);
                            $('.DOP_ThumbnailGallery_NavigationRight .Icon', Container).css('border-top-color', '#'+NavigationColor);
                            $('.DOP_ThumbnailGallery_NavigationRight .Icon', Container).css('border-bottom-color', '#'+NavigationColor);
                            $('.DOP_ThumbnailGallery_NavigationRight .Icon', Container).css('border-right-color', '#'+NavigationColor);
                            $('.DOP_ThumbnailGallery_NavigationRight', Container).css('opacity', parseInt(NavigationAlpha)/100);
                            $('.DOP_ThumbnailGallery_NavigationRight .Icon', Container).css('border-left-color', '#'+NavigationIconColor);
                        });

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

                        $('.DOP_ThumbnailGallery_NavigationRight', Container).click(function(){
                            if (imageLoaded){
                                methods.nextImage();
                            }
                        });
                    },
                    rpNavigation:function(){// Resize & Position Navigation Buttons
                        $('.DOP_ThumbnailGallery_NavigationLeft', Container).css('margin-left', parseFloat($('.DOP_ThumbnailGallery_ImageWrapper', Container).css('margin-left'))+parseInt($('.DOP_ThumbnailGallery_Image', Container).css('margin-left'))+10);
                        $('.DOP_ThumbnailGallery_NavigationRight', Container).css('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);
                        $('.DOP_ThumbnailGallery_NavigationLeft', Container).css('margin-top', parseFloat($('.DOP_ThumbnailGallery_ImageWrapper', Container).css('margin-top'))+parseInt($('.DOP_ThumbnailGallery_Image', Container).css('margin-top'))+($('.DOP_ThumbnailGallery_Image', Container).height()-$('.DOP_ThumbnailGallery_NavigationLeft', Container).height())/2);
                        $('.DOP_ThumbnailGallery_NavigationRight', Container).css('margin-top', parseFloat($('.DOP_ThumbnailGallery_ImageWrapper', Container).css('margin-top'))+parseInt($('.DOP_ThumbnailGallery_Image', Container).css('margin-top'))+($('.DOP_ThumbnailGallery_Image', Container).height()-$('.DOP_ThumbnailGallery_NavigationRight', Container).height())/2);
                    },
                    nextImage:function(){// Go to next image
                        if (currentImage == noImages){
                            methods.loadImage(1);
                        }
                        else{
                            methods.loadImage(currentImage+1);
                        }
                    },
                    previousImage:function(){// Go to previous image
                        if (currentImage == 1){
                            methods.loadImage(noImages);
                        }
                        else{
                            methods.loadImage(currentImage-1);
                        }
                    },

                    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');
                        }
                    },

                    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', parseInt(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 (parseInt(CaptionWidth)+CaptionMarginLeft+CaptionMarginRight > $('.DOP_ThumbnailGallery_Image', Container).width()){
                            $('.DOP_ThumbnailGallery_Caption', Container).width($('.DOP_ThumbnailGallery_Image', Container).width());
                        }
                        else{
                            $('.DOP_ThumbnailGallery_Caption', Container).width(parseInt(CaptionWidth)+CaptionMarginLeft+CaptionMarginRight);
                        }
                        if (parseInt(CaptionHeight)+CaptionMarginTop+CaptionMarginBottom > $('.DOP_ThumbnailGallery_Image', Container).height()){
                            $('.DOP_ThumbnailGallery_Caption', Container).height($('.DOP_ThumbnailGallery_Image', Container).height());
                        }
                        else{
                            $('.DOP_ThumbnailGallery_Caption', Container).height(parseInt(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);
                            }
                        }
                    },

                    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){
                            $('.DOP_ThumbnailGallery_NavigationLeft', Container).css('display', 'block');
                            $('.DOP_ThumbnailGallery_NavigationRight', Container).css('display', 'block');
                        }

                        if (ThumbnailsPosition == 'top'){
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).stop(true, true).animate({'margin-top': 0}, 600);
                        }
                        if (ThumbnailsPosition == 'right'){
                            $('.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).stop(true, true).animate({'margin-top': $('.DOP_ThumbnailGallery_Container', Container).height()-$('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).height()}, 600);
                        }
                        if (ThumbnailsPosition == 'left'){
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).stop(true, true).animate({'margin-left': 0}, 600);
                        }
                        methods.showCaption();
                    },
                    hideItems:function()
                    {
                        clearInterval(HideID);
                        ItemsHidden = true;

                        $('.DOP_ThumbnailGallery_NavigationLeft', Container).css('display', 'none');
                        $('.DOP_ThumbnailGallery_NavigationRight', Container).css('display', 'none');

                        if (ThumbnailsPosition == 'top'){
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).stop(true, true).animate({'margin-top': 0-$('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).height()}, 600);
                        }
                        if (ThumbnailsPosition == 'right'){
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).stop(true, true).animate({'margin-left': $('.DOP_ThumbnailGallery_Container', Container).width()}, 600);
                        }
                        if (ThumbnailsPosition == 'bottom'){
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).stop(true, true).animate({'margin-top': $('.DOP_ThumbnailGallery_Container', Container).height()}, 600);
                        }
                        if (ThumbnailsPosition == 'left'){
                            $('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).stop(true, true).animate({'margin-left': 0-$('.DOP_ThumbnailGallery_ThumbnailsContainer', Container).width()}, 600);
                        }
                        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);
