        
        
        function Carousel(picturesList, div, img, nameDiv)
        {
            this.currentIndex = 0;
            this.source = picturesList;
            this.div = div;
            this.info = null;
            
            this.setButtonsVisible = setButtonsVisible;
            this.loadPictureToCarousel = loadPicturesToCarousel;
            this.scrollCarousel = scrollCarousel;
            this.showBigPicture = showBigPicture;
            this.showProject = showProject;
            this.setProjectIds = setProjectIds;
            this.showBigPictureWithName = showBigPictureWithName;
            
            //this.picturesCount = this.div.getElementsByTagName("img").length;
            this.picturesCount = this.div.getElementsByTagName("img").length - 2;
            
            if (img)
                this.img = img;
                
            if (nameDiv)
                this.nameDiv = nameDiv;
        }
        
        function setProjectIds(info)
        {
            this.info = info;            
        }
        
        function setButtonsVisible()
	    {
	        this.loadPictureToCarousel();
	        var buttons = this.div.getElementsByTagName("img");
	        var btnNext = buttons[0];
	        var btnPrev = buttons[buttons.length - 1];
	        
	        if (this.source.length > this.picturesCount)
		    {
			    btnNext.style.visibility = "visible";
			    btnNext.disabled = false;
			    btnPrev.style.visibility = "visible";
			    btnPrev.disabled = false;
		    }
		    else
		    {
		        btnNext.style.visibility = "hidden";
			    btnNext.disabled = false;
			    btnPrev.style.visibility = "hidden";
			    btnPrev.disabled = false;
		    }
			
			if (this.img)
			    this.img.src = this.source[0];
			    
			if (this.nameDiv)
			    this.nameDiv.innerHTML = this.info[0];
			
			return;
	    }		
		
		function loadPicturesToCarousel()
		{
		    var imgTags = this.div.getElementsByTagName("img");
		    
		    var length = this.source.length;
		    
		    var minLength = Math.min(this.picturesCount, length);
		    var maxLength = Math.max(this.picturesCount, length);
		    var allIndisies = '';
		    
		    for (var i = 0; i < minLength; i++)
			{
				//var newIndex = (this.currentIndex + i) % (this.picturesCount + 1);
				var newIndex = (this.currentIndex + i) % maxLength;
				
				if (newIndex < 0)
					newIndex += maxLength;
					
			    allIndisies += newIndex + ', ';
				
				imgTags[i + 1].src = this.source[newIndex];
			}
			
			//alert(allIndisies);
			
			if (this.picturesCount > length)
			{
				for (var j = length; j < this.picturesCount; j++)
				{
					imgTags[j + 1].style.display = "none";
				}
			}
			
			return;
		}
		
		function scrollCarousel(isIncrement)
		{
		    if (isIncrement)
		    {				
			    this.currentIndex++;
		    }
		    else
		    {
			    this.currentIndex--;
		    }
			
		    this.loadPictureToCarousel();
		}
		
		function stopScroll()
		{
		    clearTimeout(this.scroller);
		}
		
		window.onmouseup = stopScroll;
		
		function showBigPicture(senderIndex)
		{
		    this.img.src = this.div.getElementsByTagName("img")[senderIndex].src;
		}
		
		function showBigPictureWithName(senderIndex)
		{
		    var maxLength = Math.max(this.picturesCount, this.source.length);
		    
		    var newIndex = (this.currentIndex + senderIndex) % (maxLength);
			if (newIndex < 0)
			    newIndex += (maxLength);
			    
			this.img.src = this.div.getElementsByTagName("img")[senderIndex + 1].src;
		    this.nameDiv.innerHTML = this.info[newIndex];
		}
		
		function showProject(link, senderIndex)
		{
		    var newIndex = (this.currentIndex + senderIndex) % (this.picturesCount + 1);
			if (newIndex < 0)
			    newIndex += (this.picturesCount + 1);
					
		    window.location.href = link + "&id=" + this.info[newIndex];
		}
