(function ($) {

    $.fn.shiftGallery = function (options) {



        var defaults = {
            thumbWidth: 100,
            thumbHeight:80,
            thumbSpace: 5,
            thumbNrPage: 3,

            totalWidth: 0,
            totalHeight: 0,
            transition: "curtainShift",
            transitionTime: 1200,
            stripDelay: 70,

            stripNrX: 5,
            stripNrY: 5,
            navSpace: 5,
            isSlideshow: "off",
            slideshowTime: 5,
            menuPosition: "down",
            darkTheme: "off",
            basePath: "",
            scaleWidth: 'on',
            scaleHeight: 'on',

            //just for backward compatibility ( now use totalWidth )
            imageWidth: 400,
            imageHeight: 225
        },

           options = $.extend(defaults, options);

        this.each(function () {



            var cthis;

            var wpos = 0;

            var thumbWidth = 100;
            var thumbHeight = 80;
            var thumbSpace = 5;
            var thumbNrPage = 2;

            var totalWidth = 400;
            var totalHeight =225;
            var realtotalWidth = 400;
            var realtotalHeight = 225;

            var currPage = 0;
            var currNr = 0;

            var stripArray = new Array();

            var defaultArrowSize = 20;


            var stripWidth = 100;
            var stripHeight = 150;

            var j = 0;
            var k = 0;

            var stripX = 0;
            var stripY = 0;

            var stripNrX = 5;
            var stripNrY = 5;

            var navSpace = 5;




            var transition = "curtainSim"
            var transitionArray = [];
            var transitionTypeArray = [];
            var descriptionOpacityArray = [];

            var transitionTime = 1200;
            var stripDelay = 70;



            var busy = false;

            var lastIndex = 99;




            var aux = 0;
            var aux2 = 0;

            var aux3 = 0;

            var isSlideshow = "off";
            var paused = false;
            var slideshowTime = 5000;
            var tempCount = 0;

            var menuPosition = "down"
            var thumbInitialOpacity = 0.6;
            var darkTheme = "off";
            var basePath = "";

            var descriptionXArray = [];
            var descriptionYArray = [];

            var scaleWidth = '';
            var scaleHeight = '';


            thumbWidth = options.thumbWidth;
            thumbHeight = options.thumbHeight;
            thumbSpace = options.thumbSpace;
            thumbNrPage = options.thumbNrPage;

            if (options.totalWidth != 0)
                totalWidth = options.totalWidth;
            else
                totalWidth = options.imageWidth;

            if (options.totalHeight != 0)
                totalHeight = options.totalHeight;
            else
                totalHeight = options.imageHeight;

            imageWidth = options.imageWidth;
            transition = options.transition;
            transitionTime = options.transitionTime;
            stripDelay = options.stripDelay;

            stripNrX = options.stripNrX;
            stripNrY = options.stripNrY;
            navSpace = options.navSpace;

            isSlideshow = options.isSlideshow;
            slideshowTime = options.slideshowTime;

            menuPosition = options.menuPosition;
            darkTheme = options.darkTheme;
            scaleWidth = options.scaleWidth;
            scaleHeight = options.scaleHeight;
            basePath = options.basePath;

            cthis = jQuery(this);
            cthis.append('<div id="imgCon"></div>')



            if (cthis.css('visibility') == 'hidden') {

                cthis.css('visibility', 'visible')
                if (!(jQuery.browser.msie)) {
                    cthis.css('opacity', 0)
                    cthis.delay(1500).animate({ 'opacity': 1 }, 1000)
                }
                jQuery('.zpreloader').delay(1500).hide('slow');

            }


            if (menuPosition == 'right') {
                jQuery(this).css({
                    'overflow': 'hidden',
                    'width': totalWidth + navSpace + thumbWidth,
                    'height': totalHeight
                })
            }
            else {
                jQuery(this).css({
                    'overflow': 'hidden',
                    'width': totalWidth,
                    'height': totalHeight + navSpace + thumbHeight
                })
            }







            var nrChildren = jQuery(this).children().length;
            var imgCon = jQuery(this).find('#imgCon');

            if (transition == "random") {
                for (i = 0; i < nrChildren; i++) {
                    var randomNr = Math.floor(Math.random() * 9)


                    if (randomNr == 0) {
                        if (jQuery.browser.msie) {
                            transitionArray[i] = "curtainLeft";
                        }
                        else
                            transitionArray[i] = "slideFade";
                    }

                    if (randomNr == 1) {

                        if (jQuery.browser.msie) {
                            transitionArray[i] = "curtainLeft";
                        }
                        else
                            transitionArray[i] = "slideFade";
                    }

                    if (randomNr == 2)
                        transitionArray[i] = "curtainAlpha";
                    if (randomNr == 3)
                        transitionArray[i] = "curtainLeft";
                    if (randomNr == 4)
                        transitionArray[i] = "curtainSim";
                    if (randomNr == 5)
                        transitionArray[i] = "curtainShift";
                    if (randomNr == 6)
                        transitionArray[i] = "curtainAlternative";
                    if (randomNr == 7)
                        transitionArray[i] = "blocksDiagonal";
                    if (randomNr == 8)
                        transitionArray[i] = "blocksSlide";
                }
            }
            else {
                for (i = 0; i < nrChildren; i++)
                    transitionArray[i] = transition;
            }

            for (i = 0; i < nrChildren; i++) {
                if (transitionArray[i] == "blocksDiagonal" || transitionArray[i] == "blocksSlide") {
                    transitionTypeArray[i] = "cubes"
                }
                else {
                    transitionTypeArray[i] = "simple"
                }

            }




            imgCon.append('<div id="slider"></div>')

            var sliderCon = imgCon.find('#slider');

            for (i = 0; i < nrChildren - 1; i++) {
                jQuery(this).children().eq(0).appendTo(sliderCon)
            }

            var images = sliderCon.children();



            if (totalWidth === 0) {
                totalWidth = images.eq(0).width();
                realtotalWidth = totalWidth;
            }
            else {
                realtotalWidth = images.eq(0).width();
            }


            if (totalHeight === 0) {
                totalHeight = images.eq(0).height();
                realtotalHeight = totalHeight;
            }
            else {
                realtotalHeight = images.eq(0).height();
            }



            stripWidth = totalWidth / stripNrX;
            stripHeight = totalHeight / stripNrY;
            for (i = 0; i < images.length; i++) {
                if (scaleWidth == 'on')
                    images.eq(i).width(totalWidth)
                if (scaleHeight == 'on')
                    images.eq(i).height(totalHeight)
            }


            imgCon.css({
                'height': totalHeight,
                'width': totalWidth,

                'overflow': 'hidden'
            })



            sliderCon.css('position', 'relative')



            //NAVIGATION CONSTRUCTION *************
            jQuery(this).append('<div id="navCon"><div id="thumbSliderCon"><div id="thumbSlider"></div></div></div>');

            var navCon = jQuery(this).find('#navCon');
            var thumbSliderCon = jQuery(this).find('#thumbSliderCon');
            var thumbSlider = jQuery(this).find('#thumbSlider');





            if (menuPosition == "down") {
                navCon.css({
                    'width': totalWidth,
                    'height': thumbHeight + navSpace,
                    'overflow': 'hidden',
                    'text-align': 'center',
                    'position': 'relative',
                    'top': navSpace
                })


                thumbSliderCon.css({
                    'width': thumbNrPage * (thumbWidth + thumbSpace),
                    'height': thumbHeight,
                    'overflow': 'hidden',
                    'position': 'relative',
                    'margin': 'auto'
                })


            }
            else {
                navCon.css({
                    'width': thumbWidth + navSpace,
                    'height': totalHeight,
                    'overflow': 'hidden',
                    'text-align': 'left',
                    'position': 'absolute',
                    'left': navSpace + totalWidth,
                    'top': 0
                })


                thumbSliderCon.css({
                    'width': thumbWidth,
                    'height': thumbNrPage * (thumbHeight + thumbSpace),
                    'overflow': 'hidden',
                    'position': 'relative',
                    'top': (totalHeight - (thumbNrPage * (thumbSpace + thumbHeight))) / 2,
                    'margin': 'auto'
                })

            }


            thumbSlider.css('position', 'relative')


            var thumbPos = 0;

            if (thumbNrPage >= nrChildren - 1) {
                thumbPos += (thumbNrPage - nrChildren + 1) * thumbWidth * 0.5;
            }

            for (i = 0; i < images.length; i++) {

                if (images.eq(i).attr("data-thumb") != undefined) {
                    thumbSlider.append("<img class='thumbClass' src='" + images.eq(i).attr("data-thumb") + "'/>")
                }
                else {
                    thumbSlider.append(images.eq(i).clone());
                }
                descriptionXArray[i] = (images.eq(i).attr('data-descriptionX'));
                descriptionYArray[i] = (images.eq(i).attr('data-descriptionY'));


                if (menuPosition == "down") {
                    thumbSlider.children().eq(i).css({
                        'left': thumbPos,
                        'top': 0,
                        'position': 'absolute',
                        'cursor': 'pointer',
                        opacity: thumbInitialOpacity
                    })

                    thumbPos += thumbWidth + thumbSpace;
                }
                else {
                    thumbSlider.children().eq(i).css({
                        'left': 0,
                        'top': thumbPos,
                        'position': 'absolute',
                        'cursor': 'pointer',
                        opacity: thumbInitialOpacity
                    })

                    thumbPos += thumbHeight + thumbSpace;
                }

                thumbSlider.children().eq(i).mouseover(function (event) {


                    if (thumbSlider.children().index($(this)) == currNr)
                        return;

                    jQuery(event.target).stop();
                    jQuery(event.target).animate({
                        opacity: 1
                    }, 100)
                })

                thumbSlider.children().eq(i).mouseout(function (event) {
                    if (thumbSlider.children().index($(this)) == currNr)
                        return;

                    jQuery(event.target).stop();
                    jQuery(event.target).animate({
                        opacity: thumbInitialOpacity
                    }, 400)
                })


            }


            thumbSlider.children().width(thumbWidth);
            thumbSlider.children().height(thumbHeight);


            if (thumbNrPage < nrChildren - 1) {
                if (darkTheme == "on")
                    navCon.append('<img src="' + basePath + 'img/barrow.png" id="arrowleft"/>')
                else
                    navCon.append('<img src="' + basePath + 'img/arrow.png" id="arrowleft"/>')

                if (jQuery.browser.msie) {
                    if (darkTheme == "on")
                        navCon.append('<img src="' + basePath + 'img/barrowie.png" id="arrowright"/>')
                    else
                        navCon.append('<img src="' + basePath + 'img/arrowie.png" id="arrowright"/>')
                }
                else {
                    if (darkTheme == "on")
                        navCon.append('<img src="' + basePath + 'img/barrow.png" id="arrowright" class="flipped"/>')
                    else
                        navCon.append('<img src="' + basePath + 'img/arrow.png" id="arrowright" class="flipped"/>')
                }

            }


            var arrowSize = 0;

            if (navCon.find('#arrowleft').children().eq(0).width() === 0 || navCon.find('#arrowleft').children().eq(0).width() == null) {
                arrowSize = defaultArrowSize;
            }
            else {
                arrowSize = navCon.find('#arrowleft').children().eq(0).width();
            }




            if (menuPosition == "down") {

                aux = ((totalWidth - (thumbNrPage * (thumbWidth + thumbSpace))) / 4) - arrowSize / 2;
                navCon.find('#arrowleft').css({
                    'position': 'absolute',
                    'top': thumbHeight / 2 - arrowSize / 2,
                    'left': aux,
                    'cursor': 'default',
                    'opacity': '0.5'
                })

                navCon.find('#arrowright').css({
                    'position': 'absolute',
                    'top': thumbHeight / 2 - arrowSize / 2,
                    'right': aux,
                    'cursor': 'pointer',
                    'opacity': '0.5'
                })
            }
            else {
                aux = totalHeight - ((totalHeight - (thumbNrPage * (thumbHeight + thumbSpace))) / 4) - arrowSize / 2;


                navCon.find('#arrowleft').css({
                    'position': 'absolute',
                    'top': 0,
                    'left': thumbWidth * 0.5 - arrowSize * 0.5,
                    'cursor': 'default',
                    'opacity': '0.5'
                })

                navCon.find('#arrowright').css({
                    'position': 'absolute',
                    'top': aux,
                    'left': thumbWidth * 0.5 - arrowSize * 0.5,
                    'cursor': 'pointer',
                    'opacity': '0.5'
                })
            }




            $(this).find('#arrowleft').mouseover(function () {
                if (currPage != 0)
                    navCon.find('#arrowleft').css({
                        'opacity': '1'
                    })


            });

            $(this).find('#arrowleft').mouseout(function () {
                navCon.find('#arrowleft').css({
                    'opacity': '0.5'
                })
            });


            $(this).find('#arrowright').mouseover(function () {

                if (currPage <= Math.floor((nrChildren - 1) / thumbNrPage))
                    navCon.find('#arrowright').css({
                        'opacity': '1'
                    })
            });

            $(this).find('#arrowright').mouseout(function () {
                navCon.find('#arrowright').css({
                    'opacity': '0.5'
                })
            });



            $(this).find('#arrowleft').click(function () {
                gotoPage(currPage - 1);
            });

            $(this).find('#arrowright').click(function () {
                gotoPage(currPage + 1);
            });

            function gotoPage(arg) {



                if (arg >= 0 && arg <= Math.floor((nrChildren - 1) / thumbNrPage)) {
                    currPage = arg;
                    thumbSlider.stop();
                }
                else
                    return;

                if (arg == 0) {
                    navCon.find('#arrowleft').css('cursor', 'default')
                    navCon.find('#arrowleft').css({
                        'opacity': '0.5'
                    })
                }

                else
                    navCon.find('#arrowleft').css('cursor', 'pointer')

                if (arg == Math.floor((nrChildren - 1) / thumbNrPage)) {
                    navCon.find('#arrowright').css({
                        'opacity': '0.5'
                    })
                    navCon.find('#arrowright').css('cursor', 'default')
                }
                else
                    navCon.find('#arrowright').css('cursor', 'pointer')

                var targetX = 0;



                if (menuPosition == "down") {
                    targetX = arg * thumbNrPage * -(thumbWidth + thumbSpace);


                    if (targetX > 0)
                        targetX = 0;
                    if (targetX < ((nrChildren - 1) - thumbNrPage) * -(thumbWidth + thumbSpace))
                        targetX = ((nrChildren - 1) - thumbNrPage) * -(thumbWidth + thumbSpace);

                    thumbSlider.animate({
                        left: targetX
                    }, 500);

                }
                else {
                    targetX = arg * thumbNrPage * -(thumbHeight + thumbSpace);


                    if (targetX > 0)
                        targetX = 0;
                    if (targetX < ((nrChildren - 1) - thumbNrPage) * -(thumbHeight + thumbSpace))
                        targetX = ((nrChildren - 1) - thumbNrPage) * -(thumbHeight + thumbSpace);

                    thumbSlider.animate({
                        top: targetX
                    }, 500);
                }



            }
            thumbSlider.children().click(function (event) {
                gotoImage(thumbSlider.children().index(this))
            })

            thumbSlider.children().eq(currNr).animate({
                opacity: 0.9
            }, 100)


            //FUNCTION THAT HANDLES TRANSITIONS
            function gotoImage(arg) {

                if (currNr === arg)
                    return;

                if (busy == true) {
                    return;
                }
                busy = true;

                if ((stripArray[arg].length == 0 || stripArray[currNr].length == 0) && transitionArray[arg] != 'fade')
                    transition = "slideFade"
                else
                    transition = transitionArray[arg];


                images.eq(arg).css('z-index', lastIndex)
                lastIndex++;



                for (i = 0; i < images.length; i++) {
                    if (i == currNr || i == arg)
                        images.eq(i).css('visibility', 'visible')
                    else
                        images.eq(i).css('visibility', 'hidden')

                }
                thumbSlider.children().eq(currNr).animate({
                    opacity: thumbInitialOpacity
                }, 100)







                //*************TRANSITIONS***********

                //START FADE
                if (transition === "fade") {

                    images.eq(arg).animate({
                        left: 0,
                        opacity: 0
                    }, 0)


                    images.eq(arg).animate({
                        opacity: 1
                    }, transitionTime)







                    setTimeout(unBusy, transitionTime)
                }
                //END FADE

                //START SLIDEFADE
                if (transition === "slideFade") {
                    if (jQuery.browser.msie) {
                        images.eq(currNr).animate({
                            left: 0
                        }, 0);
                        images.eq(arg).animate({
                            left: totalWidth
                        }, 0);

                        images.eq(currNr).animate({
                            left: -totalWidth
                        }, 700);
                        images.eq(arg).animate({
                            left: 0
                        }, 700);



                        setTimeout(unBusy, transitionTime)
                    }
                    else {


                        images.eq(currNr).stop();
                        images.eq(arg).stop();

                        if (currNr < arg) {

                            images.eq(currNr).animate({
                                left: 0,
                                opacity: 1
                            }, 0);
                            images.eq(arg).animate({
                                left: totalWidth,
                                opacity: 0
                            }, 0);

                            images.eq(currNr).animate({
                                left: -totalWidth,
                                opacity: 0
                            }, 700);
                            images.eq(arg).animate({
                                left: 0,
                                opacity: 1
                            }, 700);
                        }
                        else {

                            images.eq(currNr).animate({
                                left: 0,
                                opacity: 1
                            }, 0);
                            images.eq(arg).animate({
                                left: -totalWidth,
                                opacity: 0
                            }, 0);

                            images.eq(currNr).animate({
                                left: totalWidth,
                                opacity: 0
                            }, 700);
                            images.eq(arg).animate({
                                left: 0,
                                opacity: 1
                            }, 700);
                        }
                        setTimeout(unBusy, transitionTime)
                    }
                }

                //START curtainAlpha
                if (transition === "curtainAlpha") {


                    if (images.eq(arg).css('opacity') == 1) {

                    }
                    else {
                        images.eq(arg).css({
                            'left': '0',
                            'opacity': '1'
                        })
                    }

                    images.eq(arg).css({
                        'left': '0'
                    })

                    for (i = 0; i < stripArray[arg].length; i++) {
                        stripArray[arg][i].animate({
                            opacity: 0
                        }, 0)
                        stripArray[arg][i].animate({
                            opacity: 1
                        }, transitionTime + 1.5 * i * stripDelay)
                    }
                    setTimeout(unBusy, transitionTime)

                }

                //START curtainLeft
                if (transition === "curtainLeft") {


                    if (images.eq(arg).css('opacity') == 1) {

                    }
                    else {
                        images.eq(arg).css({
                            'left': '0',
                            'opacity': '1'
                        })
                    }

                    images.eq(arg).css({
                        'left': '0'
                    })


                    for (i = 0; i < stripArray[arg].length; i++) {
                        stripArray[arg][i].animate({
                            opacity: 0,
                            top: -totalWidth
                        }, 0)
                    }
                    i = 0;
                    function animateIt1() {

                        stripArray[arg][i].animate({
                            opacity: 0,
                            top: -totalWidth
                        }, 0)

                        stripArray[arg][i].animate({
                            opacity: 1,
                            top: 0
                        }, transitionTime)



                        i++;

                        if (i == stripArray[arg].length) {
                            clearInterval(inter);
                            setTimeout(unBusy, transitionTime)
                        }

                    }



                    animateIt1();
                    i = 1;

                    var inter = setInterval(function () {

                        animateIt1();

                    }, stripDelay)


                }

                //START curtainSim	
                if (transition === "curtainSim") {


                    if (images.eq(arg).css('opacity') == 1) {

                    }
                    else {
                        images.eq(arg).css({
                            'left': '0',
                            'opacity': '1'
                        })
                    }

                    images.eq(arg).css({
                        'left': '0'
                    })


                    for (i = 0; i < stripArray[arg].length; i++) {
                        stripArray[arg][i].animate({
                            opacity: 0,
                            top: -totalWidth
                        }, 0)
                    }

                    i = 0;
                    j = stripArray[arg].length - 1;
                    function animateIt2() {
                        stripArray[arg][i].animate({
                            opacity: 0,
                            top: -totalWidth
                        }, 0)

                        stripArray[arg][i].animate({
                            opacity: 1,
                            top: 0
                        }, transitionTime)



                        i++;


                        if (j > (stripArray[arg].length / 2)) {
                            stripArray[arg][j].animate({
                                opacity: 0,
                                top: -totalWidth
                            }, 0)

                            stripArray[arg][j].animate({
                                opacity: 1,
                                top: 0
                            }, transitionTime)



                            j--;

                        }

                        if (i >= (stripArray[arg].length / 2)) {
                            clearInterval(inter);
                            setTimeout(unBusy, transitionTime)
                        }

                    }



                    animateIt2();
                    i = 1;
                    j = j = stripArray[arg].length - 2;

                    var inter = setInterval(function () {

                        animateIt2();

                    }, stripDelay)


                }
                //END CURTAINSIM


                //START CURTAINALTERNATIVE
                if (transition === "curtainAlternative") {


                    if (images.eq(arg).css('opacity') == 1) {

                    }
                    else {
                        images.eq(arg).css({
                            'left': '0',
                            'opacity': '1'
                        })
                    }

                    images.eq(arg).css({
                        'left': '0'
                    })


                    for (i = 0; i < stripArray[arg].length; i++) {
                        stripArray[arg][i].animate({
                            opacity: 0
                        }, 0)
                    }




                    i = 0;
                    j = stripArray[arg].length - 1;
                    function animateIt3() {
                        if (i % 2 == 0) {
                            stripArray[arg][i].animate({
                                opacity: 0,
                                top: -totalWidth
                            }, 0)
                        }
                        else {
                            stripArray[arg][i].animate({
                                opacity: 0,
                                top: totalWidth
                            }, 0)
                        }

                        stripArray[arg][i].animate({
                            opacity: 1,
                            top: 0
                        }, transitionTime)



                        i++;

                        if (j > (stripArray[arg].length / 2)) {
                            if (j % 2 == 0) {
                                stripArray[arg][j].animate({
                                    opacity: 0,
                                    top: -totalWidth
                                }, 0)
                            }
                            else {
                                stripArray[arg][j].animate({
                                    opacity: 0,
                                    top: totalWidth
                                }, 0)
                            }


                            stripArray[arg][j].animate({
                                opacity: 1,
                                top: 0
                            }, transitionTime)



                            j--;
                        }

                        if (i >= stripArray[arg].length / 2) {
                            clearInterval(inter);
                            setTimeout(unBusy, transitionTime)
                        }

                    }



                    animateIt3();
                    i = 1;
                    j = j = stripArray[arg].length - 2;

                    var inter = setInterval(function () {

                        animateIt3();

                    }, stripDelay)


                }
                //END CURTAINALTERNATIVE

                //START CURTAINSHIFT
                if (transition === "curtainShift") {


                    if (images.eq(arg).css('opacity') == 1) {

                    }
                    else {
                        images.eq(arg).css({
                            'left': '0',
                            'opacity': '1'
                        })
                    }

                    images.eq(arg).css({
                        'left': '0'
                    })


                    for (i = 0; i < stripArray[arg].length; i++) {
                        stripArray[arg][i].animate({
                            opacity: 0
                        }, 0)
                    }




                    i = 0;
                    j = stripArray[arg].length - 1;
                    function animateIt4() {
                        if (i % 2 == 0) {
                            stripArray[arg][i].animate({
                                opacity: 0,
                                left: stripWidth * (i + 1),
                                width: 1
                            }, 0)
                        }
                        else {
                            stripArray[arg][i].animate({
                                opacity: 0,
                                left: stripWidth * i,
                                width: 1
                            }, 0)
                        }

                        if (i % 2 == 0) {
                            stripArray[arg][i].animate({
                                opacity: 1,
                                left: stripWidth * (i),
                                width: stripWidth
                            }, transitionTime)
                        }
                        else {
                            stripArray[arg][i].animate({
                                opacity: 1,
                                width: stripWidth
                            }, transitionTime)
                        }



                        i++;

                        if (j > (stripArray[arg].length / 2)) {
                            if (j % 2 == 0) {
                                stripArray[arg][j].animate({
                                    opacity: 0,
                                    left: stripWidth * (j + 1),
                                    width: 1
                                }, 0)
                            }
                            else {
                                stripArray[arg][j].animate({
                                    opacity: 0,
                                    left: stripWidth * j,
                                    width: 1
                                }, 0)
                            }

                            if (j % 2 == 0) {
                                stripArray[arg][j].animate({
                                    opacity: 1,
                                    left: stripWidth * (j),
                                    width: stripWidth
                                }, transitionTime)
                            }
                            else {
                                stripArray[arg][j].animate({
                                    opacity: 1,
                                    width: stripWidth
                                }, transitionTime)
                            }

                            j--;
                        }

                        if (i >= stripArray[arg].length / 2) {
                            clearInterval(inter);
                            setTimeout(unBusy, transitionTime)
                        }

                    }



                    animateIt4();
                    i = 1;
                    j = j = stripArray[arg].length - 2;

                    var inter = setInterval(function () {

                        animateIt4();

                    }, stripDelay)


                }
                //END PSEUDOCURTAIN

                //SIMSTRIPS
                if (transition === "blocksDiagonal") {


                    if (images.eq(arg).css('opacity') == 1) {

                    }
                    else {
                        images.eq(arg).css({
                            'left': '0',
                            'opacity': '1'
                        })
                    }


                    stripNrY = options.stripNrY;


                    var q = 0;

                    busy = true;

                    images.eq(arg).css({
                        'left': '0'
                    })


                    for (i = 0; i < stripArray[arg].length; i++) {
                        for (j = 0; j < stripArray[arg][i].length; j++) {

                            stripArray[arg][i][j].animate({
                                opacity: 0
                            }, 0)
                        }

                    }
                    i = 0;
                    j = 0;
                    k = 0;
                    q = 0;

                    function animateIt5() {



                        function animateRight() {
                            if (k >= stripNrX) {
                                k = 0;
                                i++;
                            }


                            if (parseFloat($(stripArray[arg][i][k]).css('opacity')) == 0) {

                                jQuery(stripArray[arg][i][k]).animate({
                                    opacity: 1
                                }, transitionTime)
                            }
                            else {
                                k++;



                                if (i >= stripNrY && k >= stripNrX) {

                                }
                                else
                                    animateRight();
                            }
                        }


                        animateRight();

                        function animateDown() {

                            if (j >= stripNrY) {
                                j = 0;
                                q++;
                            }

                            if (parseFloat($(stripArray[arg][i][k]).css('opacity')) == 0) {
                                jQuery(stripArray[arg][j][q]).animate({
                                    opacity: 1
                                }, transitionTime)
                            }
                            else {
                                j++;



                                if (j >= stripNrY && q >= stripNrX) {

                                }
                                else
                                    animateDown();
                            }
                        }


                        animateDown();

                        //i++;
                        //j++;
                        if (i >= stripNrY - 1 && k >= stripNrX - 1) {
                            clearInterval(inter);
                            setTimeout(unBusy, transitionTime);
                        }
                    }

                    animateIt5();
                    animateIt5();

                    var inter = setInterval(function () {

                        animateIt5();

                    }, stripDelay)


                }
                //END blocksDiagonal

                //START blocksSlide
                if (transition === "blocksSlide") {



                    if (images.eq(arg).css('opacity') == 1) {

                    }
                    else {
                        images.eq(arg).css({
                            'left': '0',
                            'opacity': '1'
                        })
                    }

                    images.eq(arg).css({
                        'left': '0'
                    })

                    for (i = 0; i < stripArray[arg].length; i++) {
                        for (j = 0; j < stripArray[arg][i].length; j++) {

                            stripArray[arg][i][j].animate({
                                opacity: 0,
                                left: 0
                            }, 0)
                        }

                    }

                    for (i = 0; i < stripArray[arg].length; i++) {
                        for (j = 0; j < stripArray[arg][i].length; j++) {

                            stripArray[arg][i][j].animate({
                                opacity: 1,
                                left: j * stripWidth
                            }, transitionTime + i * 200)


                        }

                    }
                    setTimeout(unBusy, transitionTime);
                }
                //**********************
                //END TRANSITIONS
                //**********************

                //alert('ceva');
                //return;	
                aux2 = descriptionYArray[arg];
                aux3 = descriptionYArray[arg];
                //alert(descriptionYArray[arg])
                if (aux2 > -100) {
                    images.eq(currNr).find(".descriptionBg").animate({
                        opacity: 0,
                        top: aux2
                    }, 400)
                    images.eq(currNr).find(".descriptionText").animate({
                        opacity: 0,
                        top: aux2
                    }, 400)

                    thumbSlider.children().eq(arg).animate({
                        opacity: 0.9
                    }, 100)
                    images.eq(arg).find(".descriptionBg").animate({
                        opacity: 0,
                        top: aux2 - 10
                    }, 0)


                    images.eq(arg).find(".descriptionText").animate({
                        opacity: 0,
                        top: aux2 - 10
                    }, 0)
                }
                currNr = arg;

                tempCount = 0;

            } //END GOTOIMAGE

            function unBusy() {
                busy = false;


                if (images.eq(currNr).find(".descriptionBg").attr('style') != undefined) {


                    i++;
                    if (aux2 > -100) {
                        images.eq(currNr).find(".descriptionBg").stop();
                        images.eq(currNr).find(".descriptionText").stop();



                        images.eq(currNr).find(".descriptionBg").animate({
                            opacity: descriptionOpacityArray[currNr],
                            top: aux2
                        }, 500)

                        images.eq(currNr).find(".descriptionText").animate({
                            opacity: 1,
                            top: aux3
                        }, 500)
                    }
                }

            }



            var descriptionBgDiv = "<div class='round-corners descriptionBg' ";
            var descriptionTextDiv = "<div class='descriptionText'";


            //STRIPE CONSTRUCTION****************
            for (i = 0; i < images.length; i++) {

                descriptionBgDiv = "<div class='round-corners descriptionBg' ";
                descriptionTextDiv = "<div class='descriptionText'";

                images.eq(i).wrap('<div class="item"></div>')

                if (images.eq(i)[0].nodeName == "IMG")
                    aux = images.eq(i).attr("src");



                if (images.eq(i)[0].nodeName == "IMG")
                    descriptionOpacityArray[i] = Number(images.eq(i).attr("data-descriptionOpacity"))

                descriptionBgDiv += "style='position: absolute; left:" + images.eq(i).attr("data-descriptionX") + "px; top: " + images.eq(i).attr("data-descriptionY") + "px; z-index:98; width:" + images.eq(i).attr("data-descriptionWidth") + "px; height:" + images.eq(i).attr("data-descriptionHeight") + "px; background-color:" + images.eq(i).attr("data-descriptionBg") + "; opacity:" + images.eq(i).attr("data-descriptionOpacity") + "; filter:alpha(opacity=" + images.eq(i).attr("data-descriptionOpacity") * 100 + ");'></div>";
                descriptionTextDiv += "style='position: absolute; left:" + images.eq(i).attr("data-descriptionX") + "px; top: " + images.eq(i).attr("data-descriptionY") + "px; z-index:98; width:" + images.eq(i).attr("data-descriptionWidth") + "px; height:" + images.eq(i).attr("data-descriptionHeight") + "px;  z-index:99; color:" + images.eq(i).attr("data-descriptionTextColor") + "; text-align:" + images.eq(i).attr("data-descriptionTextAlign") + "; font-size:16;'>" + images.eq(i).attr("data-descriptionText") + "</div>";






                stripX = 0;
                stripY = 0;

                var auxArray = [];
                stripArray[i] = auxArray;

                if (images.eq(i)[0].nodeName != "IMG" || transitionArray[i] == "fade") {
                    sliderCon.children().eq(i).append(images.eq(i))
                    if (transitionArray[i] != "fade")
                        transitionArray[i] = "slideFade";


                }
                else {

                    sliderCon.children().eq(i).empty();
                    function addArrayLine() {

                        k++;
                        var auxArray2 = [];
                        auxArray[k] = auxArray2;
                    }
                    k = 0;

                    if (transitionTypeArray[i] == "cubes") {
                        var auxArray2 = [];
                        auxArray[k] = auxArray2;
                        stripNrY = options.stripNrY;
                        stripHeight = totalHeight / stripNrY;
                    }
                    else {
                        stripHeight = totalHeight;
                        stripNrY = 1;
                    }

                    for (j = 0; j < stripNrX * stripNrY; j++) {


                        var aux2 = parseInt(-stripX) + "px " + parseInt(-stripY) + "px";

                        sliderCon.children().eq(i).append('<div class="strip"></div>')


                        if (transitionTypeArray[i] == "cubes") {

                            stripArray[i][k][(j - k * stripNrX)] = sliderCon.children().eq(i).children().eq(j);
                            if (i < 2) {
                                //console.log('j:',j)
                                //console.log("el e:",j-k*stripNrX)
                                //console.log(i,k,(j-k*stripNrX))
                                //console.log(stripArray[i][k][(j-k*stripNrX)])
                            }

                        }
                        else
                            auxArray[j] = sliderCon.children().eq(i).children().eq(j)


                        sliderCon.children().eq(i).children().eq(j).css({
                            'background-position': aux2,
                            'width': parseInt(stripWidth) + 1,
                            'height': parseInt(stripHeight) + 1,
                            'position': 'absolute',
                            'left': stripX,
                            'top': stripY,
                            'background-image': 'url(' + aux + ')',
                            'background-repeat': 'no-repeat',
                            'z-index': j
                        })




                        stripX += stripWidth;


                        if (Math.ceil(stripX) >= totalWidth) {
                            stripY += stripHeight;
                            if (transitionTypeArray[i] == "cubes")
                                addArrayLine();
                            stripX = 0;
                        }

                    }


                }


                if (descriptionBgDiv.search("undefined") == -1)
                    sliderCon.children().eq(i).append(descriptionBgDiv)

                if (descriptionTextDiv.search("undefined") == -1)
                    sliderCon.children().eq(i).append(descriptionTextDiv)



                //sliderCon.children().eq(i).find('#descriptionBg').css('opacity',0.5)



            }




            images = sliderCon.children();

            var imgPos = 0;



            for (i = 0; i < images.length; i++) {
                images.eq(i).css({
                    'left': imgPos,
                    'top': 0,
                    'position': 'absolute'
                })



                //if(images.eq(i).find("#descriptionBg").attr('style')!=undefined)
                //descriptionOpacityArray[i]=Number(images.eq(i).attr('data-descriptionOpacity'))

                imgPos += totalWidth;

            }

            if (isSlideshow == "on")
                intervalID = setInterval(checkTimer, 1000)


            function checkTimer() {


                if (paused == false)
                    tempCount++;



                if (tempCount >= slideshowTime) {
                    gotoNext();

                }

            }
            function gotoNext() {

                if (currNr == nrChildren - 2)
                    gotoImage(0)
                else
                    gotoImage(currNr + 1)

                if (Math.floor(currNr / thumbNrPage) != currPage) {
                    gotoPage(Math.floor(currNr / thumbNrPage))
                }
            }


            $(this).mouseover(function () {
                paused = true;
                jQuery('.descriptionText').animate({ 'opacity': 1 }, { queue: false, duration: 1 })
                jQuery('.descriptionBg').animate({ 'opacity': 1 }, { queue: false, duration: 1 })
            })

            $(this).mouseout(function () {
                paused = false;
                jQuery('.descriptionText').animate({ 'opacity': 0 }, { queue: false, duration: 1 })
                jQuery('.descriptionBg').animate({ 'opacity': 0 }, { queue: false, duration: 1 })
            })

            return this;




        }); // end each

    }

})(jQuery);








