slideShowClass = new Class
({

    initialize: function(main,magnify,largeImgDiv,host,galleryFolder,imageFolder,imgFileNameArray,
    index,numPics,slideshowPause,slideshowPlay,guest,allowRating,idArray,ratingsContainer,ratingsInfoDiv,
        ratingForm,ratingFormImgId,ratingFormImgRating,ratingsMessageContainer,ratedContainer,numRatingsSpan,
        allowComments,commentsAmountDiv,commentsDataContainer,commentsContainer,commentsForm,commentsTextarea,
        commentsImgId,commentsGif,darkDiv,commentsMessageContainer,desContainer,showDescriptions,lightbox,
        slideshowControls,imgholder,mainBehaviors,lboxSlideShow)
    {
            this.main = main;
            this.magnify = magnify;
            this.largeImgDiv = largeImgDiv;
            this.host = host;
            this.galleryFolder = galleryFolder;
            this.imageFolder = imageFolder;
            this.imgFileNameArray = imgFileNameArray;
            this.index = index;
            this.numPics = numPics;
            this.slideshowPause = slideshowPause + 1000;
            this.slideshowPlay = slideshowPlay;

            this.guest = guest;
            this.allowRating = allowRating;
            this.idArray = idArray;
            this.ratingsContainer = ratingsContainer;
                this.ratingsInfoDiv = ratingsInfoDiv;
                this.ratingForm = ratingForm;
                this.ratingFormImgId = ratingFormImgId;
                this.ratingFormImgRating = ratingFormImgRating;
                this.ratingsMessageContainer = ratingsMessageContainer;
                this.ratedContainer = ratedContainer;
                this.numRatingsSpan = numRatingsSpan;
                this.allowComments = allowComments;
                this.commentsAmountDiv = commentsAmountDiv;
                this.commentsDataContainer = commentsDataContainer;
                this.commentsContainer = commentsContainer;
                this.commentsForm = commentsForm;
                this.commentsTextarea = commentsTextarea;
                this.commentsImgId = commentsImgId;
                this.commentsGif = commentsGif;
                this.darkDiv = darkDiv;
                this.commentsMessageContainer = commentsMessageContainer;
                this.desContainer = desContainer;
                this.showDescriptions = showDescriptions;
                this.lightbox = lightbox;
                this.slideshowControls = slideshowControls;
                this.imgholder = imgholder;
                this.mainBehaviors = mainBehaviors;
                this.lboxSlideShow = lboxSlideShow;

    },

    startSlideShow : function(autostart)
        {
                if(autostart == false)
                {
                        this.slideShowFunction(true);
                }
                this.slideShowVar = this.slideShowFunction.periodical(this.slideshowPause, this, true);
                if(this.slideshowControls == 1)
                {
                        $(this.slideshowPlay).setProperty('src', this.host + '/components/com_igallery/images/sl_stop.png');
                        $(this.slideshowPlay).removeEvents();
                        $(this.slideshowPlay).addEvent('click', function(e)
                        {
                                this.clearSlideShow();
                        }.bind(this));
                }
        },

    clearSlideShow : function()
        {

                $clear(this.slideShowVar);
                if(this.slideshowControls == 1)
                {
                        $(this.slideshowPlay).setProperty('src', this.host + '/components/com_igallery/images/sl_play.png');
                        $(this.slideshowPlay).removeEvents();
                        $(this.slideshowPlay).addEvent('click', function(e)
                        {
                                this.startSlideShow(false);
                        }.bind(this));
                }
        },

    slideShowFunction : function(forward)
        {
                this.forward = forward;

                if(this.forward == false)
            {
                    if(this.index > 1)
                        {
                                this.index = this.index - 2;
                        }
                        else
                        {
                                this.index = this.numPics - (2 - this.index);
                        }
            }

            if(this.allowRating == 1)
                {
                        this.mainRatings = new ratingsClass(this.guest,this.idArray,this.host,this.index,this.ratingsContainer,
                        this.ratingsInfoDiv,this.ratingForm,this.ratingFormImgId,this.ratingFormImgRating,this.ratingsMessageContainer,
                        this.ratedContainer,this.numRatingsSpan);
                }

                if(this.allowComments == 1)
                {
                        this.mainComments = new commentsClass(this.guest,this.idArray,this.host,this.commentsAmountDiv,
                        this.commentsDataContainer,this.commentsContainer,
                        this.commentsForm,this.commentsTextarea,this.commentsImgId,this.commentsGif,this.index,
                        this.darkDiv,this.commentsMessageContainer,this.lightbox);
                }

                if(this.showDescriptions == 1)
                {
                        this.descriptionDivs = $(this.desContainer).getElements('div[class=des_div]');
                        this.descriptionDivs.each(function(el,index)
                        {
                                el.setStyle('display', 'none');
                        });
                        $(this.desContainer).scrollTo(0,0);
                        this.descriptionDivs[this.index].setStyle('display', 'block');
                }


            if(this.main == true)
                {
                        if (this.magnify == 1 && $('magnifygif') != null)
                        {
                                $('magnifygif').remove();
                        }
                }

                if(this.main == true)
                {
                        $(this.largeImgDiv).removeEvents('click');

                        $(this.largeImgDiv).setStyle('cursor', 'pointer');

                        $(this.largeImgDiv).addEvent('click', function(e)
                        {
                                this.mainBehaviors.igniteLightBox(this.index - 1);
                        }.bind(this));
                }

                if(this.main == true)
                {
                        if(this.lboxSlideShow != null)
                                {
                                        this.lboxSlideShow.clearSlideShow();
                                        this.lboxSlideShow.index = this.index + 1;
                                        if(this.lboxSlideShow.index >= this.numPics)
                                        {
                                                this.lboxSlideShow.index = 0;
                                        }

                                }
                }

                this.imageToFadeOut = $(this.largeImgDiv).getElement('img[class=large_img]');

                this.imageFadeAway = new Fx.Style(this.imageToFadeOut, 'opacity').start(1,0).chain(function()
                {
                        this.imageToFadeOut.remove();
                }.bind(this));

                this.ImageAsset = this.imageToFadeIn = new Asset.images([this.host + 'images/stories/igallery/' + this.galleryFolder + '/' + this.imageFolder + '/' + this.imgFileNameArray[this.index] ],
                {
                        onComplete: function()
                        {
                                this.ImageAsset.injectTop( $(this.imgholder) )
                                this.ImageAssetInjected = $(this.imgholder).getElement('img');

                                this.imageAssetSizeArray = this.ImageAssetInjected.getSize();
                                this.imageWidth = this.imageAssetSizeArray.size.x;
                                this.imageHeight = this.imageAssetSizeArray.size.y;
                                //$(this.imgholder).empty();

                                this.imageToFadeInEl = new Element('img',
                                {
                                    'src': null
                                });

                                this.imageToFadeInEl.setStyle('opacity',0);
                                this.imageToFadeInEl.injectTop(this.largeImgDiv);
                                this.imageToFadeInEl.setProperty('src', this.host + 'images/stories/igallery/' + this.galleryFolder + '/' + this.imageFolder + '/' + this.imgFileNameArray[this.index]);
                                this.imageToFadeInEl.setProperty('class', 'large_img');


                                this.largeImgDivSizeArray = $(this.largeImgDiv).getSize();

                                this.imageToFadeInLeftMargin = (this.largeImgDivSizeArray.size.x - this.imageWidth) /2;
                                this.imageToFadeInTopMargin = (this.largeImgDivSizeArray.size.y - this.imageHeight) /2;


                                this.imageToFadeInEl.setStyles
                                ({
                                        display: 'block',
                                        position: 'absolute',
                                        left: this.imageToFadeInLeftMargin,
                                        top: this.imageToFadeInTopMargin
                                });



                                this.imageFadeIn = new Fx.Style(this.imageToFadeInEl, 'opacity').start(0,1).chain(function()
                                {
                                        if(this.main == true)
                                        {
                                                if (this.magnify == 1)
                                                {
                                                        this.insertMagnify = new insertMagnifyClass(this.largeImgDiv,this.host,this.imageWidth,this.imageHeight);
                                                }
                                        }
                                }.bind(this));

                                this.index++;
                                if(this.index == this.numPics )
                                {
                                        this.index = 0;
                                }

                        }.bind(this)
                });


        }




});

imageFaderClass = new Class
({
        initialize: function(main,magnify,largeImgDiv,host,galleryFolder,imageFolder,imgFileNameArray,index,fade,first,imgholder)
    {
            this.main = main;
            this.magnify = magnify;
            this.largeImgDiv = largeImgDiv;
            this.host = host;
            this.galleryFolder = galleryFolder;
            this.imageFolder = imageFolder;
            this.imgFileNameArray = imgFileNameArray;
            this.index = index;
            this.fade = fade;
            this.first = first;
            this.imgholder = imgholder

                if(this.main == true)
                {
                        if (this.magnify == 1 && $('magnifygif') != null)
                        {
                                $('magnifygif').remove();
                        }
                }

                if(this.first == false)
                {
                        this.imageToFadeOut = $(this.largeImgDiv).getElement('img[class=large_img]');

                        if(this.fade == true)
                        {
                                this.imageFadeAway = new Fx.Style(this.imageToFadeOut, 'opacity').start(1,0).chain(function()
                                {
                                        this.imageToFadeOut.remove();
                                }.bind(this));
                        }
                        else
                        {
                                this.imageFadeAway = new Fx.Style(this.imageToFadeOut, 'opacity').set(0).chain(function()
                                {
                                        this.imageToFadeOut.remove();
                                }.bind(this));
                        }
                }

                this.ImageAsset = this.imageToFadeIn = new Asset.images([this.host + 'images/stories/igallery/' + this.galleryFolder + '/' + this.imageFolder + '/' + this.imgFileNameArray[index] ],
                {
                        onComplete: function()
                        {
                                this.ImageAsset.injectTop( $(this.imgholder) )
                                this.ImageAssetInjected = $(this.imgholder).getElement('img');

                                this.imageAssetSizeArray = this.ImageAssetInjected.getSize();
                                this.imageWidth = this.imageAssetSizeArray.size.x;
                                this.imageHeight = this.imageAssetSizeArray.size.y;

                                //$(this.imgholder).empty()

                                this.imageToFadeInEl = new Element('img',
                                {
                                    'src': null
                                });

                                this.imageToFadeInEl.setStyle('opacity',0);
                                this.imageToFadeInEl.injectTop(this.largeImgDiv);
                                this.imageToFadeInEl.setProperty('src', this.host + 'images/stories/igallery/' + this.galleryFolder + '/' + this.imageFolder + '/' + this.imgFileNameArray[index]);
                                this.imageToFadeInEl.setProperty('class', 'large_img');

                                this.largeImgDivSizeArray = $(this.largeImgDiv).getSize();

                                this.imageToFadeInLeftMargin = (this.largeImgDivSizeArray.size.x - this.imageWidth) /2;
                                this.imageToFadeInTopMargin = (this.largeImgDivSizeArray.size.y - this.imageHeight) /2;


                                this.imageToFadeInEl.setStyles
                                ({
                                        display: 'block',
                                        position: 'absolute',
                                        left: this.imageToFadeInLeftMargin,
                                        top: this.imageToFadeInTopMargin
                                });


                                if(this.fade == true)
                                {
                                        this.imageFadeIn = new Fx.Style(this.imageToFadeInEl, 'opacity').start(0,1).chain(function()
                                        {
                                                if(this.main == true)
                                                {
                                                        if (this.magnify == 1)
                                                        {
                                                                this.insertMagnify = new insertMagnifyClass(this.largeImgDiv,this.host,this.imageWidth,this.imageHeight);
                                                        }
                                                }
                                        }.bind(this));
                                }
                                else
                                {
                                        this.imageFadeIn = new Fx.Style(this.imageToFadeInEl, 'opacity').start(1,1).chain(function()
                                        {
                                                if(this.main == true)
                                                {
                                                        if (this.magnify == 1)
                                                        {
                                                                this.insertMagnify = new insertMagnifyClass(this.largeImgDiv,this.host,this.imageWidth,this.imageHeight);
                                                        }
                                                }
                                        }.bind(this));
                                }

                        }.bind(this)
                });
    }

});

insertMagnifyClass = new Class
({
        initialize: function(largeImgDiv,host,imageWidth,imageHeight)
    {
            this.largeImgDiv = largeImgDiv;
            this.host = host;
            this.imageWidth = imageWidth;
            this.imageHeight = imageHeight;

            this.mainImage = $(this.largeImgDiv).getElement('img');
                this.mainImageLeft = this.mainImage.getLeft();
                this.containerLeft = $(this.largeImgDiv).getLeft();
                this.leftMargin = this.mainImageLeft - this.containerLeft;

                this.mainImageTop = this.mainImage.getTop();
                this.containerTop = $(this.largeImgDiv).getTop();
                this.mainImageTopMargin = this.mainImageTop - this.containerTop;

                this.magnifyMarginLeft = this.leftMargin + this.imageWidth - 27;
                this.magnifyMarginTop = this.imageHeight + this.mainImageTopMargin - 20;


                this.magnify = new Asset.images([this.host + 'components/com_igallery/images/magnify.gif' ],
                {
                        onComplete: function()
                        {
                                this.magnify[0].injectTop(this.largeImgDiv).setStyles
                                ({
                                        position: 'absolute',
                                        top: this.magnifyMarginTop,
                                        left: this.magnifyMarginLeft,
                                        'z-index': 1020,
                                        opacity: 0
                                });
                                this.magnify[0].setProperty('id', 'magnifygif');
                                this.magnifyFadeIn = new Fx.Style(this.magnify[0], 'opacity').set(0.5);
                        }.bind(this)
                });
        }
});



preloaderClass = new Class
({
    initialize: function(host,galleryFolder,imageFolder,imgFileNameArray,numPics)
    {
            this.host = host;
            this.galleryFolder = galleryFolder;
            this.imageFolder = imageFolder;
            this.imgFileNameArray = imgFileNameArray;
            this.numPics = numPics;
            this.counter = 0;

            this.preloaderVar = this.preloaderFunction.periodical(750, this);
    },

    preloaderFunction : function()
        {
            new Asset.images([this.host + 'images/stories/igallery/' + this.galleryFolder + '/' + this.imageFolder + '/' + this.imgFileNameArray[this.counter] ],
                {
                    onComplete: function()
                         {

                    }
                });

                this.counter++;

                if(this.counter == this.numPics)
                {
                        $clear(this.preloaderVar);
                }
        }

});

addArrowBehaviors = new Class
({
    initialize: function(arrow, pixels, mode, container)
    {
            this.arrow = arrow;
            this.pixels = pixels;
            this.mode = mode;
                this.container = container;

                this.arrowScroller = new Fx.Scroll(this.container);

                $(this.arrow).addEvent('click', function(e)
                {
                        this.containerSizeArray = $(this.container).getSize();
                        this.currentScrollX = this.containerSizeArray.scroll.x;
                        this.currentScrollY = this.containerSizeArray.scroll.y;
                        this.contentWidth = this.containerSizeArray.scrollSize.x;
                        this.contentHeight = this.containerSizeArray.scrollSize.y;

                        if (this.mode == 'horizontal')
                        {
                                this.arrowScroller.scrollTo(this.currentScrollX + this.pixels, this.currentScrollY);
                        }

                        if (this.mode == 'vertical')
                        {
                                this.arrowScroller.scrollTo(this.currentScrollX, this.currentScrollY + this.pixels);
                        }

            }.bind(this));
    }
});


commentsClass = new Class
({
        initialize: function(guest,idArray,host,commentsAmountDiv,commentsDataContainer,commentsContainer,commentsForm,commentsTextarea,
        commentsImgId,commentsGif,imgIndex,darkDiv,commentsMessageContainer,lightbox)
    {
            this.guest = guest;
            this.idArray = idArray;
            this.host = host;

            this.commentsAmountDiv = commentsAmountDiv;
            this.commentsDataContainer = commentsDataContainer;
            this.commentsContainer = commentsContainer;
            this.commentsForm = commentsForm;
            this.commentsTextarea = commentsTextarea;
            this.commentsImgId = commentsImgId;
            this.commentsGif = commentsGif;
            this.imgIndex = imgIndex;
            this.darkDiv = darkDiv;
            this.commentsMessageContainer = commentsMessageContainer;
                this.lightbox = lightbox;





                if(this.guest == 0)
                {
                        $(this.commentsImgId).setProperty('value', this.idArray[this.imgIndex]);
                        $(this.commentsForm).removeEvents();

                        this.commentsMessages = $(this.commentsMessageContainer).getElements('span');
                    this.commentsMessages.each(function(el,index){el.setStyle('display','none')});
                }
                //alert(this.commentsMessageContainer);
                this.caculateComments();

                //ajax comments bit
                if(this.guest == 0)
                {
                        $(this.commentsForm).addEvent('submit', function(e)
                        {
                                new Event(e).stop();
                                this.commentToSend = $(this.commentsTextarea).getValue();

                                if(this.commentToSend.length < 1)
                                {
                                        this.commentsMessages[0].setStyle('display','inline');
                                        this.commentsMessages[1].setStyle('display','none');
                                        this.commentsMessages[2].setStyle('display','none');
                                }
                                else
                                {
                                        $(this.commentsGif).setHTML('<img src="' + this.host + 'components/com_igallery/images/loader.gif');

                                        $(this.commentsForm).send
                                        ({
                                                onComplete: function(response)
                                                {
                                                        if(response == 0)
                                                        {
                                                                this.commentsMessages[0].setStyle('display','none');
                                                                this.commentsMessages[1].setStyle('display','inline');
                                                                this.commentsMessages[2].setStyle('display','none');
                                                        }
                                                        else
                                                        {
                                                                this.newCommentDiv = new Element('div',
                                                                {
                                                                    'class': 'main_comments_div_' + this.idArray[this.imgIndex]
                                                                });
                                                                this.newCommentDiv.injectInside(this.commentsDataContainer);



                                                                this.newCommentDiv.setStyles({'border-bottom': '1px solid #cccccc',padding: '8px 0px',display: 'none'});


                                                                this.responseWithLineBreak = response.replace(new RegExp("\\n","g"),"<br />" );

                                                                this.newCommentDiv.setHTML(this.responseWithLineBreak);
                                                                $(this.commentsGif).setHTML('');

                                                                this.commentsMessages[0].setStyle('display','none');
                                                                this.commentsMessages[1].setStyle('display','none');
                                                                this.commentsMessages[2].setStyle('display','inline');

                                                                $(this.commentsTextarea).value = '';
                                                                this.caculateComments();
                                                        }
                                                }.bind(this)
                                        });

                                }

                        }.bind(this));

                }
    },

    caculateComments: function()
    {

            this.commentDataDivs = $(this.commentsDataContainer).getElements('div');
            this.commentsContainerDiv = $(this.commentsContainer);

            this.commentsContainerChildDivs = $(this.commentsContainer).getElements('div');
            this.commentsContainerChildDivs.each(function(el,index)
            {
                    el.remove();
            });

                this.commentsCounter = 0;
                this.commentDataDivs.each(function(el,index)
                {
                        this.commentDivId = el.getProperty('class');
                        this.commentDivImgIdArray = this.commentDivId.split("_");
                        this.commentDivImgId = this.commentDivImgIdArray.pop();

                        if(this.commentDivImgId == this.idArray[this.imgIndex])
                        {
                                //el.setStyle('display','block');
                                this.clone = el.clone().injectInside(this.commentsContainerDiv);
                                this.clone.setStyle('display','block')
                                this.commentsCounter++
                        }
                }.bind(this));

                $(this.commentsAmountDiv).setHTML(this.commentsCounter);

                this.totalScrollHeight = Window.getScrollHeight();
                if(this.lightbox == 1)
                {
                        $(this.darkDiv).setStyle('height',this.totalScrollHeight + 30);
                }
    }


});

ratingsClass = new Class
({
        initialize: function(guest,idArray,host,imgIndex,ratingsContainer,ratingsInfoDiv,ratingForm,
        ratingFormImgId,ratingFormImgRating,ratingsMessageContainer,ratedContainer,numRatingsSpan)
        {
                this.guest = guest;
            this.idArray = idArray;
            this.host = host;
            this.imgIndex = imgIndex;

            this.ratingsContainer = ratingsContainer;

            this.ratingsInfoDiv = ratingsInfoDiv;
            this.ratingForm = ratingForm;
            this.ratingFormImgId = ratingFormImgId;
            this.ratingFormImgRating = ratingFormImgRating;
            this.ratingsMessageContainer = ratingsMessageContainer;
            this.ratedContainer = ratedContainer;
                this.numRatingsSpan = numRatingsSpan;

            this.newRatedArray = new Array();
            this.ratedDivs = $(this.ratedContainer).getElements('div');
                this.ratedCounter = 0;
                this.ratedDivs.each(function(el,index)
                {
                        this.ratedDivValue = el.innerHTML;
                        this.ratedDivInt = parseInt(this.ratedDivValue);
                        this.newRatedArray[index] = this.ratedDivInt;
                }.bind(this));

            this.caculateRating();

            this.ratingMessages = $(this.ratingsMessageContainer).getElements('span');
            this.ratingMessages.each(function(el,index){el.setStyle('display','none')});
            if(this.guest == 1)
                {
                    this.ratingMessages[0].setStyle('display','inline');
                }
                if(this.guest == 0 && this.newRatedArray[this.imgIndex] == 0)
                {
                    this.ratingMessages[1].setStyle('display','inline');
                }
                if(this.guest == 0 && this.newRatedArray[this.imgIndex] == 1)
                {
                    this.ratingMessages[2].setStyle('display','inline');
                }

                if(this.guest == 0)
                {
                        //set the mouse enter and mouse leave
                        this.ratingStars.each(function(el,index)
                        {
                                el.removeEvents();
                                if(this.newRatedArray[this.imgIndex] == 0)
                                {
                                    el.addEvent('mouseenter', function()
                                    {
                                            for(this.i = 0; this.i<5; this.i++)
                                                {
                                                        if(this.i <= index)
                                                        {
                                                                this.ratingStars[this.i].setProperty('src', this.host + 'components/com_igallery/images/star-blue.gif');
                                                        }
                                                        else
                                                        {
                                                                this.ratingStars[this.i].setProperty('src', this.host + 'components/com_igallery/images/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.host + 'components/com_igallery/images/star-blue.gif');
                                                        }
                                                        else
                                                        {
                                                                this.ratingStars[this.i].setProperty('src', this.host + 'components/com_igallery/images/star-white.gif');
                                                        }
                                                        if(this.imgRating - Math.floor(this.imgRating) > 0)
                                                        {
                                                                this.ratingStars[Math.floor(this.imgRating)].setProperty('src', this.host + 'components/com_igallery/images/star-half.gif');
                                                        }
                                                }
                                    }.bind(this));


                                    //submit the form
                                    el.addEvent('click', function()
                                    {
                                            this.ratingMessages.each(function(el,index){el.setStyle('display','none')});
                                            this.ratingMessages[3].setStyle('display','inline');

                                            $(this.ratingFormImgId).setProperty('value', this.idArray[this.imgIndex]);
                                            $(this.ratingFormImgRating).setProperty('value', index + 1);

                                            $(this.ratingForm).send
                                                ({
                                                        onComplete: function(response)
                                                        {

                                                                this.ratingMessages.each(function(el,index){el.setStyle('display','none')});
                                                            if(response == 0)
                                                            {
                                                                        this.ratingMessages[5].setStyle('display','inline');
                                                            }
                                                            if(response == 1)
                                                            {
                                                                        this.ratingMessages[2].setStyle('display','inline');
                                                            }
                                                            if(response == 2)
                                                            {
                                                                        this.ratingMessages[4].setStyle('display','inline');
                                                                        this.newRatingDiv = new Element('div',
                                                                        {
                                                                            'class': 'ratings_div_' + this.idArray[this.imgIndex]
                                                                        });
                                                                        this.newRatingDiv.setStyle('display','none');
                                                                        this.newRatingDiv.injectInside(this.ratingsContainer);
                                                                        this.newRatingDiv.setHTML(index + 1);

                                                                        this.ratedDivs[this.imgIndex].setHTML(1);

                                                                        this.caculateRating();
                                                            }

                                                        }.bind(this)
                                                });

                                    }.bind(this));

                                }

                        }.bind(this));

                }
        },

        caculateRating: function()
        {
                //caculate the rating

                this.ratingDivs = $(this.ratingsContainer).getElements('div');
                this.ratingCounter = 0;
                this.ratingSum = 0;
                this.ratingDivs.each(function(el,index)
                {
                        this.ratingDivId = el.getProperty('class');
                        this.ratingDivImgIdArray = this.ratingDivId.split("_");
                        this.ratingDivImgId = this.ratingDivImgIdArray.pop();

                        if(this.ratingDivImgId == this.idArray[this.imgIndex])
                        {
                                this.ratingNumber = parseInt(el.innerHTML);
                                this.ratingSum = this.ratingSum + this.ratingNumber;
                                this.ratingCounter++
                        }
                }.bind(this));

                $(this.numRatingsSpan).setHTML(this.ratingCounter);

                if(this.ratingSum == 0 && this.ratingCounter == 0)
                {
                        this.imgRating = 0;
                }
                else
                {
                        this.imgRatingtoRound = this.ratingSum/this.ratingCounter;
                        this.imgRating = Math.round( (this.imgRatingtoRound * 2) ) /2;
                }

                //set the rating
                this.ratingStars = $(this.ratingsInfoDiv).getElements('img');
                for(this.k = 0; this.k<5; this.k++)
                {
                        this.ratingStars[this.k].setProperty('src', this.host + 'components/com_igallery/images/star-white.gif');
                }

                for(this.k = 0; this.k<Math.floor(this.imgRating); this.k++)
                {
                        this.ratingStars[this.k].setProperty('src', this.host + 'components/com_igallery/images/star-blue.gif');
                }

                if(this.imgRating - Math.floor(this.imgRating) > 0)
                {
                        this.ratingStars[Math.floor(this.imgRating)].setProperty('src', this.host + 'components/com_igallery/images/star-half.gif');
                }
        }

});

