(function($) {
  
    $.fn.shiftGallery = function(options) {
      
      
          var wpos = 0;
          
          var thumbWidth = 140;
          var thumbHeight = 100;
      var thumbSpace = 5;
      var thumbNrPage = 3;
      
      var imageWidth = 0;
      var imageHeight = 0;
      var realImageWidth=0;
      var realImageHeight=0;
      
      var currPage = 0;
      var currNr = 0;
      
      var stripArray = new Array();
      
      var defaultArrowSize = 20;
      
      
      var stripWidth=150;
      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 = "slidefade"
      var transitionArray = [];
      var transitionTypeArray = [];
      var descriptionOpacityArray = [];
      
      var transitionTime=1200;
      var stripDelay=70;
      
      
      
      var busy=false;
      
      var lastIndex=99;
      
      
      
      
      var aux=0;
      
      var aux3=0;
      
      var isSlideshow="on";
      var paused=false;
      var slideshowTime=3000;
      var tempCount = 0;
      
      var menuPosition="down"
      
      
          var defaults = {
             thumbWidth : 140,
          thumbHeight : 100,
       thumbSpace : 5,
      thumbNrPage : 3,
      
      imageWidth : 0,
      imageHeight : 0,
      transition : "slidefade",
      transitionTime:1200,
      stripDelay:70,
      
      stripNrX:5,
      stripNrY:5,
      navSpace:5,
      isSlideshow : "on",
      slideshowTime : 3,
      menuPosition : "down"
            },
            
           options = $.extend(defaults, options);
                
          this.each(function() {
            
    thumbWidth=options.thumbWidth;
    thumbHeight=options.thumbHeight;
    thumbSpace=options.thumbSpace;
    thumbNrPage=options.thumbNrPage;
    imageWidth=options.imageWidth;
    imageHeight=options.imageHeight;
    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;
      
    
          jQuery(this).append('<div id="imgCon"></div>')
      jQuery(this).css('overflow', 'hidden')
      
      jQuery('.slider').css('max-width','710px')
      jQuery('.slider').css('max-height','240px')
     
          
     
          
      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(imageWidth===0)
      {
        imageWidth=images.eq(0).width();
      realImageWidth=imageWidth;
      }
      else
      {
        realImageWidth=images.eq(0).width();
      }
      
           
       if(imageHeight===0)
       {
         imageHeight=images.eq(0).height();
      realImageHeight=imageHeight;
       }
       else
       {
         realImageHeight=images.eq(0).height();
       }
       
       $(this).css({
         'max-width' : imageWidth + navSpace + thumbWidth,
      'max-height' : imageHeight + navSpace + thumbHeight
       })
      
      stripWidth=imageWidth/stripNrX;
      stripHeight=imageHeight/stripNrY;
     
      images.width(imageWidth)
      images.height(imageHeight)
      
      
      imgCon.css({
        'min-height' : imageHeight,
      'min-width' : imageWidth,
        'max-width' : imageWidth,
      'max-height' : imageHeight,
      '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({
      'min-width' : imageWidth,
        'max-width' : imageWidth,
      'min-height' : thumbHeight + navSpace,
      'max-height' : thumbHeight + navSpace,
      'overflow' : 'hidden',
      'text-align' : 'center',
      'position' : 'relative',
      'top' : navSpace
        })
      
      
        thumbSliderCon.css({
      'min-width' : thumbNrPage * (thumbWidth + thumbSpace),
        'max-width' : thumbNrPage * (thumbWidth + thumbSpace),
      'min-height' : thumbHeight,
      'max-height' : thumbHeight,
      'overflow' : 'hidden',
      'position' : 'relative',
      'margin' : 'auto'
        })
      
      
      }
      else
      {
        navCon.css({
      'min-width' : thumbWidth + navSpace,
        'max-width' : thumbWidth + navSpace,
      'min-height' : imageHeight,
      'max-height' : imageHeight,
      'overflow' : 'hidden',
      'text-align' : 'left',
      'position' : 'absolute',
      'left' : navSpace + imageWidth,
      'top' : 0
        })
      
      
        thumbSliderCon.css({
      'min-width' : thumbWidth,
        'max-width' : thumbWidth,
      'min-height' : thumbNrPage * (thumbHeight + thumbSpace),
      'max-height' : thumbNrPage * (thumbHeight + thumbSpace),
      'overflow' : 'hidden',
      'position' : 'relative',
      'top' : (imageHeight-(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("thumb")!=undefined )
      {
        thumbSlider.append("<img src='" + images.eq(i).attr("thumb") + "'/>")
      }
      else
      {
        thumbSlider.append(images.eq(i).clone());
      }
      
       
      if (menuPosition == "down") {
        thumbSlider.children().eq(i).css({
          'left': thumbPos,
          'top': 0,
          'position': 'absolute',
          'cursor': 'pointer',
          opacity: 0.6
        })
        
        thumbPos += thumbWidth + thumbSpace;
      }
      else
      {
        thumbSlider.children().eq(i).css({
          'left': 0,
          'top': thumbPos,
          'position': 'absolute',
          'cursor': 'pointer',
          opacity: 0.6
        })
        
        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:0.9
        },100)
      })
      
      thumbSlider.children().eq(i).mouseout(function(event){
        if(thumbSlider.children().index($(this))==currNr)
        return;
        
        jQuery(event.target).stop();
        jQuery(event.target).animate({
          opacity:0.6
        },400)
      })
      
      
      }
      
      
      thumbSlider.children().width(thumbWidth);
      thumbSlider.children().height(thumbHeight);
      
      
      if(thumbNrPage<nrChildren-1)
      {
        navCon.append('<img src="img/arrow.png" id="arrowleft"/>')
      if (jQuery.browser.msie) {
      navCon.append('<img src="img/arrowie.png" id="arrowright"/>')
      }
      else
       navCon.append('<img src="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 = ((imageWidth - (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 = imageHeight - ((imageHeight - (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('#arrowright').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)
      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:0.6
      },100)
      
        
        
      
      
      
      
      
      //*************TRANSITIONS***********
      
      //START FADE
      if (transition === "fade") {
        
        images.eq(arg).animate({
          left:0,
          opacity:0
        },0)
        
        
        images.eq(arg).animate({
          opacity:1
        },transitionTime)
        
        
        
        
        
        
        //alert("mda")
        
        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: imageWidth
            }, 0);
            
            images.eq(currNr).animate({
              left: -imageWidth
            }, 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: imageWidth,
              opacity: 0
            }, 0);
            
            images.eq(currNr).animate({
              left: -imageWidth,
              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: -imageWidth,
              opacity: 0
            }, 0);
            
            images.eq(currNr).animate({
              left: imageWidth,
              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:-imageWidth
          }, 0)
        }
        i=0;
        function animateIt1()
          {
            
            stripArray[arg][i].animate({
            opacity:0,
            top:-imageWidth
            },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:-imageWidth
          }, 0)
        }
        
        i=0;
        j=stripArray[arg].length-1;
        function animateIt2()
          {
            stripArray[arg][i].animate({
            opacity:0,
            top:-imageWidth
            },0)
            
            stripArray[arg][i].animate({
              opacity:1,
              top:0
            },transitionTime)
            
            
            
            i++;
            
            
            if(j>(stripArray[arg].length/2))
            {
            stripArray[arg][j].animate({
            opacity:0,
            top:-imageWidth
            },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:-imageWidth
            },0)
            }
            else
            {
            stripArray[arg][i].animate({
            opacity:0,
            top:imageWidth
            },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: -imageWidth
                }, 0)
              }
              else {
                stripArray[arg][j].animate({
                  opacity: 0,
                  top: imageWidth
                }, 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);
        } 
          
        
        //hide previous transitions
      images.eq(currNr).find("#descriptionBg").animate({
        opacity:0,
        top:aux2
      },400)
      
      
      aux3=parseFloat(images.eq(currNr).find("#descriptionText").css('top'))
      images.eq(currNr).find("#descriptionText").animate({
        opacity:0,
        top:aux2
      },400)
      
      
      currNr=arg;
      thumbSlider.children().eq(currNr).animate({
        opacity:0.9
      },100)
      
          
      
      aux2=parseFloat(images.eq(currNr).find("#descriptionBg").css('top'))
      
      
      
      images.eq(currNr).find("#descriptionBg").animate({
        opacity:0,
        top:aux2-10
      },0)
      
      
      aux3=parseFloat(images.eq(currNr).find("#descriptionText").css('top'))
      images.eq(currNr).find("#descriptionText").animate({
        opacity:0,
        top:aux2-10
      },0)
      
      tempCount=0;
      
      }//END GOTOIMAGE
      
      function unBusy()
      {
        busy=false;
      
      
      if(images.eq(currNr).find("#descriptionBg").attr('style')!=undefined)
      {
        
        
        i++;
        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 id='descriptionBg' ";
      var descriptionTextDiv="<div id='descriptionText'";
      
      
      //STRIPE CONSTRUCTION****************
      for(i=0;i<images.length;i++)
      {
        
        descriptionBgDiv="<div id='descriptionBg' ";
      descriptionTextDiv="<div id='descriptionText'";
      
      images.eq(i).wrap('<div class="item"></div>')
      aux = images.eq(i).attr("src");
      
      descriptionBgDiv+="style='position: absolute; left:" + images.eq(i).attr("descriptionX") + "px; top: " + images.eq(i).attr("descriptionY") + "px; z-index:98; width:" + images.eq(i).attr("descriptionWidth") + "px; height:" + images.eq(i).attr("descriptionHeight") + "px; background-color:" + images.eq(i).attr("descriptionBg") + "; opacity:" + images.eq(i).attr("descriptionOpacity") + "; filter:alpha(opacity=" + images.eq(i).attr("descriptionOpacity")*100 + ");'></div>";
      descriptionTextDiv+="style='position: absolute; left:" + images.eq(i).attr("descriptionX") + "px; top: " + images.eq(i).attr("descriptionY") + "px; z-index:98; width:" + images.eq(i).attr("descriptionWidth") + "px; height:" + images.eq(i).attr("descriptionHeight") + "px;  z-index:99; color:" + images.eq(i).attr("descriptionTextColor") + "; text-align:" + images.eq(i).attr("descriptionTextAlign") + "; font-size:16;'>" + images.eq(i).attr("descriptionText") + "</div>";
      
      
      
      
      
      
      stripX=0;
      stripY=0;
      
      var auxArray = [];
      stripArray[i]=auxArray;
      //console.log(images.eq(i)[0].nodeName)
      //alert(images.eq(i)[0].nodeName)
      if (images.eq(i)[0].nodeName != "IMG") {
        sliderCon.children().eq(i).append(images.eq(i))
        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=imageHeight/stripNrY;
        }
        else
        {
          stripHeight=imageHeight;
          stripNrY=1;
        }
        
        for (j = 0; j < stripNrX * stripNrY; j++) {
        
          
          var aux2 = -stripX + "px " + -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': stripWidth,
            'height': stripHeight,
            'position': 'absolute',
            'left': stripX,
            'top': stripY,
            'background-image': 'url(' + aux + ')',
            'background-repeat' : 'no-repeat',
            'z-index': j
          })
          
          
          
          
          stripX += stripWidth;
          
          
          if (Math.ceil(stripX) >=  imageWidth) {
            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]=images.eq(i).find("#descriptionBg").css('opacity')
      
      imgPos+=imageWidth;
      
      }
     
     if(isSlideshow=="on")
     intervalID = setInterval(checkTimer,1000)
     
     
     function checkTimer()
    {
      
      
      if(paused==false)
      tempCount++;
      
      
      
      if(tempCount>=slideshowTime)
      {
        gotoNext();
        
      }
      if(Math.floor(currNr/thumbNrPage)!=currPage)
      {
        gotoPage(Math.floor(currNr/thumbNrPage))
      }
    }
    function gotoNext()
    {
      
      if(currNr==nrChildren-2)
      gotoImage(0)
      else
      gotoImage(currNr+1)
    }
    
    
    $(this).mouseover(function(){
       paused=true;
      

      
     })
     
     $(this).mouseout(function(){
       paused=false;
     })
    
          return this;
          
          
          
                            
           }); // end each
                                            
       }
                                              
})(jQuery);








