var igalleryClass = new Class
({
	options: {},

    initialize: function(options)
    {
        this.setOptions(options);
        this.imageIndex = 0;

        if(this.options.main == 1)
        {
        	this.urlImageId = this.getUrlParamater('image');

        	if(this.urlImageId != 'unset')
        	{
        		this.imageIndex = this.urlImageId - 1;
        		
        		
        		this.thumbId = 'main-' + this.options.catid + '-' + this.urlImageId;
        		
        		if( $chk( $(this.thumbId) ) )
        		{
        		    this.igThumbScroller = new Fx.Scroll(this.options.thumbContainer,{duration: 50});
        		    this.igThumbScroller.toElement( $(this.thumbId) );
        		}
        	}
            
        	if(this.options.showLargeImage == 1)
        	{
	           this.swapImage(this.options.jsonImagesImageType[this.imageIndex], false, this.imageIndex);
        	}
	        
        }
        
        if(this.options.showThumbs == 1)
		{
    		this.thumbScroller = new Scroller(this.options.thumbContainer, {area: this.options.scrollBoundary, velocity: this.options.scrollSpeed});
    		$(this.options.thumbContainer).addEvent('mouseenter', this.thumbScroller.start.bind(this.thumbScroller));
    		$(this.options.thumbContainer).addEvent('mouseleave', this.thumbScroller.stop.bind(this.thumbScroller));
    		
    		this.addThumbBehaviors();
		}

		if(this.options.showUpDown == 1 && this.options.showThumbs)
		{
			this.addArrowBehaviors(this.options.upArrow, -200, 'vertical');
			this.addArrowBehaviors(this.options.downArrow, 200, 'vertical');
		}
		if(this.options.showLeftRight == 1 && this.options.showThumbs)
		{
			this.addArrowBehaviors(this.options.rightArrow, 200, 'horizontal');
			this.addArrowBehaviors(this.options.leftArrow, -200, 'horizontal');
		}

		if(this.options.preload == 1 && this.options.main == 1)
		{
			this.preloadCounter = 0;
			this.preloaderVar = this.preloadImages.periodical(750, this);
		}

        if( (this.options.showSlideshowControls == 1 || this.options.slideshowAutostart == 1)  && this.options.main == 1 && this.options.showLargeImage == 1)
        {
        	this.clearSlideShow();

        	if(this.options.showSlideshowControls == 1)
			{
                $(this.options.slideshowForward).addEvent('click', function(e)
				{
					this.clearSlideShow();
					this.slideShowSwap(true);
				}.bind(this));

				$(this.options.slideshowRewind).addEvent('click', function(e)
				{
					this.clearSlideShow();
					this.slideShowSwap(false);
				}.bind(this));
			}

        	if(this.options.slideshowAutostart == 1 && this.options.showLargeImage == 1)
        	{
        		this.slideShowStart(false);
        	}
        }
    },

    addThumbBehaviors: function(options)
    {
        this.linksArray = $(this.options.thumbTable).getElements('a');

		this.linksArray.each(function(el,index)
		{
			el.addEvent('click', function(e)
			{
				e = new Event(e).stop();

				if(this.options.showLargeImage == 0 && this.options.main == 1)
				{
					this.thumbLinksArray = $(this.options.thumbContainer).getElements('a');
					this.thumbLinkClass = el.getProperty('class');
					this.thumbLinkTarget = el.getProperty('target');

					if(this.thumbLinkClass == 'picture_link')
					{
						el.setStyle('cursor', 'pointer');

						if (this.thumbLinkTarget == '_blank')
						{
							window.open(this.thumbLinksArray[index]);
						}
						else
						{
							window.location = this.thumbLinksArray[index];
						}
					}
					else
					{
						this.showLightBox(index);
					}
				}
				else
				{
					this.swapImage(this.options.jsonImagesImageType[index], this.options.fadeDuration, index);
				}
			}.bind(this));

		}.bind(this));
	},

    swapImage : function(imageObject, fadeDuration, index)
	{
	    this.imageIndex = index;
	    
		this.removeImage(fadeDuration);
		this.insertImage(imageObject, fadeDuration, this.imageIndex);
		
	    if(this.options.showThumbs == 1)
		{
            this.thumbCells = $(this.options.thumbTable).getElements('td');
            this.thumbCells.each(function(el,index)
            {
                  el.setProperty('class','inactive_thumb');
            }.bind(this));
            this.thumbCells[index].setProperty('class','active_thumb');
		}

		if(this.options.main == 1 && this.options.showLargeImage == 1 && this.options.showThumbs == 1)
		{
			this.addMainImageClick(this.imageIndex);
		}
		
		if(this.options.showThumbs == 0)
		{
		    $(this.options.largeImage).removeEvents('click');

			$(this.options.largeImage).setStyle('cursor', 'pointer');

			$(this.options.largeImage).addEvent('click', function(e)
			{
				this.showLightBox(index);
			}.bind(this));
		}
		
		if(this.options.downloadType != 'none')
		{
		    if(this.options.main == 0 || this.options.showLargeImage == 1)
		    {
			    if(this.options.main == 1)
			    {
			        this.linkType = 'main';
			    }
			    else
			    {
			        this.linkType = 'lbox';
			    }
			    
                var url = this.options.host + 'index.php?option=com_igallery&task=download&type=' + this.linkType + '&id=' + this.options.idArray[index];
                
			    this.downloadLink = $(this.options.downloadId);
                this.downloadLink.setProperty('href',url);
    
    			}
		}

		if(this.options.allowRating == 1)
		{
			this.swapRating();
		}

		if(this.options.allowComments == 1)
		{
			this.swapComments();
		}

		if(this.options.showDescriptions == 1)
		{
			this.swapDescription(index);
		}

	},

	removeImage : function(fadeDuration)
	{
	    if(typeof(this.lastImageDisplayed) != 'undefined')
	    {
			this.imageToRemove = $(this.lastImageDisplayed);
    
    		if(this.imageToRemove != null)
    		{
    			this.imageFadeAway = new Fx.Style(this.imageToRemove, 'opacity',{duration:fadeDuration});
    			this.imageFadeAway.start(1,0);
    	   }
		}

		if(this.options.main == 1 && this.options.lightboxOn == 1)
		{
			if (this.options.magnify == 1 && $('magnifygif') != null)
			{
				$('magnifygif').remove();
			}
		}
	},

	insertImage : function(imageObject, fadeDuration, index)
	{
	    this.insertedImages = $(this.options.largeImage).getElements('img[class=large_img]');
	    this.insertedMatch = false;
		
		for(var i=0; i<this.insertedImages.length; i++)
	    {
			this.insertedImageId = this.insertedImages[i].getProperty('id');
			this.idSplitted = this.insertedImageId.split('-');
			this.insertedImageCounter = this.idSplitted[2];
			if(this.insertedImageCounter == index)
			{
			    this.insertedMatch = true;
			    break;
			}
		}
		
		if(this.insertedMatch == true)
		{
		    this.imageFadeIn = new Fx.Style($(this.insertedImageId), 'opacity',{duration:fadeDuration}).start(0,1);
		    
		    this.largeImgDivSizeArray = $(this.options.largeImage).getSize();
			this.imageToInjectLeftMargin = Math.round( (this.largeImgDivSizeArray.size.x - imageObject.width) /2 );
			this.imageToInjectTopMargin  = Math.round( (this.largeImgDivSizeArray.size.y - imageObject.height) /2 );
			
			if(this.options.style == 'grey-border-shadow')
			{
			    this.imageToInjectLeftMargin = this.imageToInjectLeftMargin - 7;
			    this.imageToInjectTopMargin = this.imageToInjectTopMargin - 7;
			}
		    
			if(this.options.main == true && this.options.magnify == 1 && this.options.lightboxOn == 1)
			{
				this.insertMagnify(this.insertedImageCounter, this.imageToInjectLeftMargin, this.imageToInjectTopMargin);
			}
			
			this.lastImageDisplayed = $(this.insertedImageId);
		}
	    else
	    {
    		this.ImageAsset = new Asset.images([this.options.resizePath + imageObject.filename ],
    		{
    			onComplete: function()
    			{
    				this.largeImgDivSizeArray = $(this.options.largeImage).getSize();
    				this.imageToInjectLeftMargin = Math.round( (this.largeImgDivSizeArray.size.x - imageObject.width) /2 );
    				this.imageToInjectTopMargin  = Math.round( (this.largeImgDivSizeArray.size.y - imageObject.height) /2 );
    
    				if(this.options.style == 'grey-border-shadow')
    				{
    				    this.imageToInjectLeftMargin = this.imageToInjectLeftMargin - 7;
    				    this.imageToInjectTopMargin = this.imageToInjectTopMargin - 7;
    				}
    				
    				this.ImageAsset.setStyles
    				({
    					position: 'absolute',
    					left: this.imageToInjectLeftMargin,
    					top: this.imageToInjectTopMargin,
    					width: imageObject.width,
    					height: imageObject.height,
    					opacity: 0
    				});
    
    				this.ImageAsset.setProperty('class', 'large_img');
    				this.ImageAsset.setProperty('alt', imageObject.alt);
    				this.imageAssetId = 'ig' + this.options.main + '-' + this.options.catid + '-' + index;
                    this.ImageAsset.setProperty('id', this.imageAssetId);
    				
    				this.ImageAsset.injectTop( $(this.options.largeImage) );
    				this.ImageAssetInjected = $(this.options.largeImage).getElement('img');
    				this.imageFadeIn = new Fx.Style(this.ImageAssetInjected, 'opacity',{duration:fadeDuration}).start(0,1);
    				
                    if(this.options.main == true && this.options.magnify == 1 && this.options.lightboxOn == 1)
    				{
    					this.insertMagnify(index, this.imageToInjectLeftMargin, this.imageToInjectTopMargin);
    				}
    				
    				this.lastImageDisplayed = $(this.imageAssetId);
    
    			}.bind(this)
    		});
	    }
	},

	addMainImageClick : function(index)
	{
			this.linksArray = $(this.options.thumbContainer).getElements('a');
			this.linkClass = this.linksArray[index].getProperty('class');
			this.linkTarget = this.linksArray[index].getProperty('target');

			if(this.linkClass == 'picture_link')
			{
				$(this.options.largeImage).setStyle('cursor', 'pointer');
				$(this.options.largeImage).removeEvents('click');

				$(this.options.largeImage).addEvent('click', function(e)
				{
					if (this.linkTarget == '_blank')
					{
						window.open(this.linksArray[index]);
					}
					else
					{
						window.location = this.linksArray[index];
					}

				}.bind(this));
			}

			if(this.options.lightboxOn == 1 && this.linkClass == 'no_link' )
			{
				$(this.options.largeImage).removeEvents('click');

				$(this.options.largeImage).setStyle('cursor', 'pointer');

				$(this.options.largeImage).addEvent('click', function(e)
				{
					this.showLightBox(index);
				}.bind(this));
			}
	},

	addArrowBehaviors: function(arrow, pixels, mode)
	{
   		this.arrowScroller = new Fx.Scroll(this.options.thumbContainer);

		$(arrow).addEvent('click', function(e)
		{
			this.containerSizeArray = $(this.options.thumbContainer).getSize();
			this.currentScrollX = this.containerSizeArray.scroll.x;
			this.currentScrollY = this.containerSizeArray.scroll.y;

			if (mode == 'horizontal')
			{
				this.arrowScroller.scrollTo(this.currentScrollX + pixels, this.currentScrollY);
			}

			if (mode == 'vertical')
			{
				this.arrowScroller.scrollTo(this.currentScrollX, this.currentScrollY + pixels);
			}

	    }.bind(this));
    },

    lboxPreloadStarter : function()
	{
		this.preloadCounter = 0;
		this.preloaderVar = this.preloadImages.periodical(750, this);
	},

    preloadImages : function()
	{
    	new Asset.images([this.options.resizePath + this.options.jsonImagesImageType[this.preloadCounter].filename ],
		{
		    onComplete: function(){}
		});

		this.preloadCounter++;

		if(this.preloadCounter == this.options.numPics)
		{
			$clear(this.preloaderVar);
		}
	},

	swapDescription : function(index)
	{
		this.descriptionDivs = $(this.options.desContainer).getElements('div[class=des_div]');
		this.descriptionDivs.each(function(el,index)
		{
			el.setStyle('display', 'none');
		});

		$(this.options.desContainer).scrollTo(0,0);
		this.descriptionDivs[index].setStyle('display', 'block');
	},

	slideShowStart : function(instant)
	{
		if(instant == true)
		{
			this.slideShowSwap(true);
		}

  		this.slideShowObject = this.slideShowSwap.periodical(this.options.slideshowPause, this, true);

  		if(this.options.showSlideshowControls == 1)
		{
			$(this.options.slideshowPlay).setProperty('src', this.options.imageAssetPath + 'pause.jpg');
			$(this.options.slideshowPlay).removeEvents();
			$(this.options.slideshowPlay).addEvent('click', function(e)
			{
				this.clearSlideShow();
			}.bind(this));
		}
	},

    slideShowSwap : function(forward)
	{
		if(forward == true)
		{
			if(this.imageIndex == this.options.numPics - 1)
			{
				this.imageIndex = 0;
			}
			else
			{
				this.imageIndex++
			}
		}
    	else
    	{
    		if(this.imageIndex == 0)
			{
				this.imageIndex = this.options.numPics - 1;
			}
			else
			{
				this.imageIndex--
			}
    	}

		this.swapImage(this.options.jsonImagesImageType[this.imageIndex], this.options.fadeDuration, this.imageIndex );
	},

	clearSlideShow : function()
	{
		$clear(this.slideShowObject);

		if(this.options.showSlideshowControls == 1)
		{
			$(this.options.slideshowPlay).setProperty('src', this.options.imageAssetPath + 'play.jpg');
			$(this.options.slideshowPlay).removeEvents();
			$(this.options.slideshowPlay).addEvent('click', function(e)
			{
				this.slideShowStart(true);
			}.bind(this));
		}
	},

	swapRating: function()
	{
		this.caculateDisplayRating();

		this.showRatingMessage();

		if(this.options.guest == 0)
		{
			this.ratingStars.each(function(el,index)
			{
				el.removeEvents();

				if(this.options.ratedArray[this.imageIndex] == 0)
				{
					this.addStarsMouseover(el,index);
					this.addStarsClick(el,index);
				}
			}.bind(this));
		}
	},

	caculateDisplayRating: function()
	{
		this.imgRating = this.options.ratingsArray[this.imageIndex];

		$(this.options.numRatings).setHTML(this.options.ratingsCounterArray[this.imageIndex]);

		this.ratingStars = $(this.options.ratingsForm).getElements('img');

		for(this.k = 0; this.k<5; this.k++)
		{
			this.ratingStars[this.k].setProperty('src', this.options.imageAssetPath + 'star-white.gif');
		}

		for(this.m = 0; this.m<Math.floor(this.imgRating); this.m++)
		{
			this.ratingStars[this.m].setProperty('src', this.options.imageAssetPath + 'star-blue.gif');
		}

		if(this.imgRating - Math.floor(this.imgRating) > 0)
		{
			this.ratingStars[Math.floor(this.imgRating)].setProperty('src', this.options.imageAssetPath + 'star-half.gif');
		}
	},

	showRatingMessage: function()
	{
    	this.ratingMessages = $(this.options.ratingsMessageContainer).getElements('span');
    	this.ratingMessages.each(function(el,index){el.setStyle('display','none')});

    	if(this.options.guest == 1)
		{
    		this.ratingMessages[0].setStyle('display','inline');
		}

		if(this.options.guest == 0 && this.options.ratedArray[this.imageIndex] == 0)
		{
    		this.ratingMessages[1].setStyle('display','inline');
		}

		if(this.options.guest == 0 && this.options.ratedArray[this.imageIndex] == 1)
		{
    		this.ratingMessages[2].setStyle('display','inline');
		}
	},

	addStarsMouseover: function(el,index)
	{
		el.addEvent('mouseenter', function()
	    {
	    	for(this.i = 0; this.i<5; this.i++)
			{
				if(this.i <= index)
				{
					this.ratingStars[this.i].setProperty('src', this.options.imageAssetPath + 'star-blue.gif');
				}
				else
				{
					this.ratingStars[this.i].setProperty('src', this.options.imageAssetPath + 'star-white.gif');
				}
			}
	    }.bind(this));

	    el.addEvent('mouseleave', function()
	    {
	    	for(this.i = 0; this.i<5; this.i++)
			{
				if(this.i < Math.floor(this.imgRating))
				{
					this.ratingStars[this.i].setProperty('src', this.options.imageAssetPath + 'star-blue.gif');
				}
				else
				{
					this.ratingStars[this.i].setProperty('src', this.options.imageAssetPath + 'star-white.gif');
				}

				if(this.imgRating - Math.floor(this.imgRating) > 0)
				{
					this.ratingStars[Math.floor(this.imgRating)].setProperty('src', this.options.imageAssetPath + 'star-half.gif');
				}
			}
	    }.bind(this));
	},

	addStarsClick: function(el,index)
	{
	    el.addEvent('click', function()
	    {
	    	this.ratingMessages.each(function(el,index){el.setStyle('display','none')});
	    	this.ratingMessages[3].setStyle('display','inline');
	    	$(this.options.ratingsImgId).setProperty('value', this.options.idArray[this.imageIndex]);
	    	$(this.options.ratingsImgRating).setProperty('value', index + 1);

	    	$(this.options.ratingsForm).send
			({
				onComplete: function(response)
				{
					this.ratingMessages.each(function(el,index){el.setStyle('display','none')});

					if(response == 'ig-login')
	    			{
						this.ratingMessages[5].setStyle('display','inline');
	    			}

	    			else if(response == 'ig-already')
	    			{
						this.ratingMessages[2].setStyle('display','inline');
	    			}

	    			else
	    			{
	    			    this.options.ratingsArray[this.imageIndex] = response;
	    			    this.options.ratedArray[this.imageIndex] = 1;
	    			    this.options.ratingsCounterArray[this.imageIndex] = this.options.ratingsCounterArray[this.imageIndex] + 1;
	    			    this.caculateDisplayRating();
	    			    this.ratingMessages.each(function(el,index){el.setStyle('display','none')});
						this.ratingMessages[4].setStyle('display','inline');
	    			}
				}.bind(this)
			});
	    }.bind(this));
	},

	swapComments: function()
	{
		this.showCorrectComments();

		if(this.options.guest == 0)
		{
			this.addCommentSubmit();
		}
    },

    showCorrectComments: function()
	{
		this.commentsContainerChildDivs = $(this.options.commentsContainer).getElements('div');
        this.commentsCounter = 0;

    	this.commentsContainerChildDivs.each(function(el,index)
		{
			this.commentDivId = el.getProperty('class');
			this.commentDivIdArray = this.commentDivId.split("_");
			this.commentDivId = this.commentDivIdArray.pop();

			if(this.commentDivId == this.options.idArray[this.imageIndex])
			{
				el.setStyle('display','block');
				this.commentsCounter++
			}
			else
			{
				el.setStyle('display', 'none');
			}
			
		}.bind(this));

		$(this.options.commentsAmount).setHTML(this.commentsCounter);

		if(this.options.main == 0)
		{
			this.totalScrollHeight = Window.getScrollHeight();
			$(this.options.lboxDark).setStyle('height',this.totalScrollHeight);
		}
	},

	addCommentSubmit: function()
	{
		$(this.options.commentsForm).removeEvents();
		$(this.options.commentsImgId).setProperty('value', this.options.idArray[this.imageIndex]);
		this.commentsMessages = $(this.options.commentsMessageContainer).getElements('span');
		this.commentsMessages.each(function(el,index){el.setStyle('display','none')});

		$(this.options.commentsForm).addEvent('submit', function(e)
		{
			new Event(e).stop();
			this.commentToSend = $(this.options.commentsTextarea).getValue();

			if(this.commentToSend.length < 1)
			{
				this.commentsMessages[0].setStyle('display','inline');
				return;
			}

			$(this.options.commentsLoadingGif).setHTML('<img src="' + this.options.imageAssetPath + 'loader.gif' + '" />');

			$(this.options.commentsForm).send
			({
				onComplete: function(response)
				{
					if(response == 0)
					{
						this.commentsMessages[1].setStyle('display','inline');
						return;
					}

					this.newCommentDiv = new Element('div',
					{
						'class': 'comments_div_' + this.options.idArray[this.imageIndex]
					});

					this.newCommentDiv.setHTML(response);
					this.newCommentDiv.injectInside(this.options.commentsContainer);

					if(this.options.main == 1 && this.options.lightboxOn == 1 && this.lboxGalleryObject.options.allowComments == 1)
					{
						this.newCommentDiv.clone().injectInside(this.lboxGalleryObject.options.commentsContainer);
					}
					if(this.options.main != 1 && this.mainGalleryObject.options.allowComments == 1)
					{
						this.newCommentDiv.clone().injectInside(this.mainGalleryObject.options.commentsContainer);
					}

					$(this.options.commentsLoadingGif).setHTML('');
					this.commentsMessages[2].setStyle('display','inline');
					$(this.options.commentsTextarea).value = '';
					$(this.options.commentsAmount).setHTML(this.commentsCounter + 1);
					this.showCorrectComments();

				}.bind(this)
			});
		}.bind(this));
	},

	showLightBox : function(index)
	{
		if(this.lboxGalleryObject.options.preload == 1)
		{
			this.lboxGalleryObject.lboxPreloadStarter();
		}

		this.bodyTag = document.getElementsByTagName("body").item(0);
		this.scrolledDown = Window.getScrollTop();
		this.totalScrollHeight = Window.getScrollHeight();
		this.totalWidth = Window.getWidth();

		this.lboxPaddingLeft = $(this.options.lboxWhite).getStyle('padding-left').toInt();
		this.lboxPaddingRight = $(this.options.lboxWhite).getStyle('padding-right').toInt();
		this.lboxPadding = (this.lboxPaddingLeft + this.lboxPaddingRight) / 2;

		this.whiteDivLeftMargin = (this.totalWidth/2) - ( (this.options.lightboxWidth)/2) + this.lboxPadding;
		$(this.options.lboxWhite).injectTop(this.bodyTag);
		$(this.options.lboxWhite).setStyles
		({
			'top': this.scrolledDown + 30,
	        'left': this.whiteDivLeftMargin,
	        'opacity': '0',
			'display': 'block',
			'float': 'left'
		});

		this.totalScrollHeight = Window.getScrollHeight();

		$(this.options.lboxDark).injectTop(this.bodyTag);
		$(this.options.lboxDark).setStyles
		({
			'width': '100%',
	        'height': this.totalScrollHeight,
	        'top': '0px',
	        'left': '0px',
	        'opacity': '0',
			'display': 'block'
		});

		this.darkDivFade = new Fx.Style( $(this.options.lboxDark) , 'opacity');
		this.darkDivFade.start(0,.7);

		this.whiteDivFadeIn = new Fx.Style( $(this.options.lboxWhite) , 'opacity');
		this.whiteDivFadeIn.start(0,1);

		this.lboxGalleryObject.swapImage(this.options.jsonImages.lbox[index], 0, index);

		if(this.lboxGalleryObject.options.showSlideshowControls == 1 || this.lboxGalleryObject.options.slideshowAutostart == 1)
    	{
        	this.lboxGalleryObject.clearSlideShow();

        	if(this.lboxGalleryObject.options.showSlideshowControls == 1)
			{
			    $(this.lboxGalleryObject.options.slideshowForward).removeEvents();
			    $(this.lboxGalleryObject.options.slideshowRewind).removeEvents();
			    
	        	$(this.lboxGalleryObject.options.slideshowForward).addEvent('click', function(e)
				{
					this.lboxGalleryObject.clearSlideShow();
					this.lboxGalleryObject.slideShowSwap(true);
				}.bind(this));

				$(this.lboxGalleryObject.options.slideshowRewind).addEvent('click', function(e)
				{
					this.lboxGalleryObject.clearSlideShow();
					this.lboxGalleryObject.slideShowSwap(false);
				}.bind(this));

			}

        	if(this.lboxGalleryObject.options.slideshowAutostart == 1)
        	{
        		this.lboxGalleryObject.slideShowStart(false);
        	}
    	}
    	
    	this.lboxThumbId = 'lbox-' + this.options.catid + '-' + index;
    	if( $chk( $(this.lboxThumbId) ) )
		{
        	this.igLboxThumbScroller = new Fx.Scroll(this.lboxGalleryObject.options.thumbContainer,{duration: 50});
            this.igLboxThumbScroller.toElement( $(this.lboxThumbId) );
		}
		
		if(this.lboxGalleryObject.options.downloadType != 'none')
		{
		    var url = this.options.host + 'index.php?option=com_igallery&task=download&type=lbox&id=' + this.options.idArray[index];
            this.downloadLink = $(this.lboxGalleryObject.options.downloadId);
            this.downloadLink.setProperty('href',url);
		}

		$(this.options.closeImage).addEvent('click', function(e)
		{
			this.lboxGalleryObject.clearSlideShow();

			this.darkDivFade.start(0.7,0).chain(function()
			{
				$(this.options.lboxDark).setStyle('display','none');
			}.bind(this));

			this.whiteDivFadeIn.start(1,0).chain(function()
			{
				$(this.lboxGalleryObject.options.largeImage).setHTML('');
				$(this.options.lboxWhite).setStyle('display','none');
			}.bind(this));

			if(this.options.allowRating == 1)
			{
				this.caculateDisplayRating();
			}

		}.bind(this));
	},

	insertMagnify : function(index, mainImageLeftMargin, mainImageTopMargin)
    {
  		this.currentLargeImage = $(this.options.largeImage).getElement('img[class=large_img]');

  		this.largeImageLeftPadding = this.currentLargeImage.getStyle('padding-left').toInt();
    	this.largeImageTopPadding = this.currentLargeImage.getStyle('padding-top').toInt();
    	this.largeImageLeftMargin = this.currentLargeImage.getStyle('margin-left').toInt();
    	this.largeImageTopMargin = this.currentLargeImage.getStyle('margin-top').toInt();

		this.magnifyMarginLeft = mainImageLeftMargin + this.options.jsonImages.main[index].width - 27 + this.largeImageLeftPadding + this.largeImageLeftMargin;
		this.magnifyMarginTop = mainImageTopMargin + this.options.jsonImages.main[index].height - 20 + this.largeImageTopPadding + this.largeImageTopMargin;
		

		this.magnifyImage = new Asset.images([this.options.imageAssetPath + 'magnify.gif' ],
		{
			onComplete: function()
			{
				this.magnifyImage[0].injectInside(this.options.largeImage).setStyles
				({
					position: 'absolute',
					left: this.magnifyMarginLeft,
					top: this.magnifyMarginTop,
					'z-index': 10,
					opacity: 0.7
				});

				this.magnifyImage[0].setProperty('id', 'magnifygif');

			}.bind(this)
		});
	},

	getUrlParamater : function (strParamName)
	{
		this.strReturn = 'unset';
		this.strHref = window.location.href;

		if(this.strHref.indexOf("?") > -1)
		{
			this.strQueryString = this.strHref.substr(this.strHref.indexOf("?")).toLowerCase();
			this.aQueryString = this.strQueryString.split("&");

			for( this.i = 0; this.i < this.aQueryString.length; this.i++ )
			{
				if( this.aQueryString[this.i].indexOf(strParamName.toLowerCase() + "=") > -1 )
				{
					this.aParam = this.aQueryString[this.i].split("=");
					this.strReturn = this.aParam[1];
					break;
				}
			}
		}
		return unescape(this.strReturn);
	}

 });

igalleryClass.implement(new Options);
