igalleryClass = new Class
({

initialize: function(preload,lboxPreload,host,galleryFolder,numPics,thumbContainer,
lboxThumbContainer,thumbTable,lboxThumbTable,desContainer,lboxDesContainer,
largeImgDiv,lboxLargeImgDiv,scrollBoundry,scrollSpeed,
lboxScrollBoundry,lboxScrollSpeed,fade,lboxFade,lightbox,
lightboxWidth,showScrollBar,showLboxScrollBar,darkDiv,whiteDiv,closeImage,upArrow,
downArrow,leftArrow,rightArrow,lboxUpArrow,lboxDownArrow,lboxLeftArrow,lboxRightArrow,
showUpDown,showLeftRight,lboxShowUpDown,lboxShowLeftRight,magnify,allowComments,allowRating,
lboxAllowComments,lboxAllowRating,idArray,guest,ratingsContainer,ratingsInfoDiv,ratingForm,
ratingFormImgId,ratingFormImgRating,ratingsMessageContainer,ratedContainer,numRatingsSpan,
commentsAmountDiv,commentsDataContainer,commentsContainer,commentsForm,commentsTextarea,
commentsImgId,commentsGif,commentsMessageContainer,lboxCommentsMessageContainer,lboxRatingsContainer,lboxRatingsInfoDiv,lboxRatingForm,lboxRatingFormImgId,
lboxRatingFormImgRating,lboxRatingsMessageContainer,lboxRatedContainer,lboxNumRatingsSpan,
lboxCommentsAmountDiv,lboxCommentsContainer,lboxCommentsForm,lboxCommentsTextarea,
lboxCommentsImgId,lboxCommentsGif,showLargeImage,slideshow,slideshowControls,slideshowPause,slideshowAutostart,
slideshowPlay,slideshowForward,slideshowRewind,lboxSlideshow,lboxSlideshowControls,
lboxSlideshowPause,lboxSlideshowAutostart,
lboxSlideshowPlay,lboxSlideshowForward,lboxSlideshowRewind,showThumbs,showDescriptions,
lboxShowThumbs,lboxShowDescriptions,imgholder)
{


        this.preload = preload;
        this.lboxPreload = lboxPreload;
        this.host = host;
        this.galleryFolder = galleryFolder;
        this.numPics = numPics;
        this.thumbContainer = thumbContainer;
        this.lboxThumbContainer = lboxThumbContainer;
        this.thumbTable = thumbTable;
        this.lboxThumbTable = lboxThumbTable;
        this.desContainer = desContainer;
        this.lboxDesContainer = lboxDesContainer;
        this.largeImgDiv = largeImgDiv;
        this.lboxLargeImgDiv = lboxLargeImgDiv;
        this.scrollBoundry = scrollBoundry;
        this.scrollSpeed = scrollSpeed;
        this.lboxScrollBoundry = lboxScrollBoundry;
        this.lboxScrollSpeed = lboxScrollSpeed;
        this.fade = fade;
        this.lboxFade = lboxFade;
        this.lightbox = lightbox;
        this.lightboxWidth = lightboxWidth;
        this.showScrollBar = showScrollBar;
        this.showLboxScrollBar = showLboxScrollBar;
        this.darkDiv = darkDiv;
        this.whiteDiv = whiteDiv;
        this.closeImage = closeImage;
        this.upArrow = upArrow;
        this.downArrow = downArrow;
        this.leftArrow = leftArrow;
        this.rightArrow = rightArrow;
        this.lboxUpArrow = lboxUpArrow;
        this.lboxDownArrow = lboxDownArrow;
        this.lboxLeftArrow = lboxLeftArrow;
        this.lboxRightArrow = lboxRightArrow;
        this.showUpDown = showUpDown;
        this.showLeftRight = showLeftRight;
        this.lboxShowUpDown = lboxShowUpDown;
        this.lboxShowLeftRight = lboxShowLeftRight;
        this.magnify = magnify;
        this.allowComments = allowComments;
        this.allowRating = allowRating;
        this.lboxAllowComments = lboxAllowComments;
        this.lboxAllowRating = lboxAllowRating;
        this.idArray = idArray;
        this.guest = guest;
        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.commentsAmountDiv = commentsAmountDiv;
        this.commentsDataContainer = commentsDataContainer;
        this.commentsContainer = commentsContainer;
        this.commentsForm = commentsForm;
        this.commentsTextarea = commentsTextarea;
        this.commentsImgId = commentsImgId;
        this.commentsGif = commentsGif;
        this.commentsMessageContainer = commentsMessageContainer;
        this.lboxCommentsMessageContainer = lboxCommentsMessageContainer;
        this.lboxRatingsContainer = lboxRatingsContainer;
        this.lboxRatingsInfoDiv = lboxRatingsInfoDiv;
        this.lboxRatingForm = lboxRatingForm;
        this.lboxRatingFormImgId = lboxRatingFormImgId;
        this.lboxRatingFormImgRating = lboxRatingFormImgRating;
        this.lboxRatingsMessageContainer = lboxRatingsMessageContainer;
        this.lboxRatedContainer = lboxRatedContainer;
        this.lboxNumRatingsSpan = lboxNumRatingsSpan;
        this.lboxCommentsAmountDiv = lboxCommentsAmountDiv;
        this.lboxCommentsContainer = lboxCommentsContainer;
        this.lboxCommentsForm = lboxCommentsForm;
        this.lboxCommentsTextarea = lboxCommentsTextarea;
        this.lboxCommentsImgId = lboxCommentsImgId;
        this.lboxCommentsGif = lboxCommentsGif;
        this.showLargeImage = showLargeImage;
        this.slideshow = slideshow;
        this.slideshowControls = slideshowControls;
        this.slideshowPause = slideshowPause;
        this.slideshowAutostart = slideshowAutostart;
        this.slideshowPlay = slideshowPlay;
        this.slideshowForward = slideshowForward;
        this.slideshowRewind = slideshowRewind;
        this.lboxSlideshow = lboxSlideshow;
        this.lboxSlideshowControls = lboxSlideshowControls;
        this.lboxSlideshowPause = lboxSlideshowPause;
        this.lboxSlideshowAutostart = lboxSlideshowAutostart;
        this.lboxSlideshowPlay = lboxSlideshowPlay;
        this.lboxSlideshowForward = lboxSlideshowForward;
        this.lboxSlideshowRewind = lboxSlideshowRewind;
        this.showThumbs = showThumbs;
        this.showDescriptions = showDescriptions;
        this.lboxShowThumbs = lboxShowThumbs;
        this.lboxShowDescriptions = lboxShowDescriptions;
        this.imgholder = imgholder;


        //make the filename array from the thumb filenames
        this.thumbPathsArray = $(this.thumbTable).getElements('img');
        this.imgFileNameArray = new Array();
        this.thumbPathsArray.each(function(el,index)
        {
                this.imgPathParts = el.src.split("/");
                this.imgFileName = this.imgPathParts.pop();
                this.imgFileNameArray[index] = this.imgFileName;
        }.bind(this));



        //make the lightbox behaviors class
        if(this.lightbox == 1)
        {
                        this.lboxBehaviors = new addBehaviors(this.lboxThumbContainer,this.lboxScrollBoundry,
                        this.lboxScrollSpeed,this.lboxThumbTable,this.lboxFade,false,this.lboxLargeImgDiv,this.host,
                        this.galleryFolder,'lightbox',this.imgFileNameArray,this.lightbox,this.lboxDesContainer,
                        this.lightboxWidth,this.darkDiv,this.whiteDiv,this.closeImage,this.lboxLargeImgDiv,
                        this.lboxPreload,this.lboxUpArrow,this.lboxDownArrow,this.lboxLeftArrow,this.lboxRightArrow,
                        this.lboxShowUpDown,this.lboxShowLeftRight,null,0,this.numPics,this.lboxPreload,
                        this.lboxDesContainer,this.lboxAllowComments,this.lboxAllowRating,this.idArray,this.guest,
                        this.ratingsContainer,this.lboxRatingsInfoDiv,this.lboxRatingForm,this.lboxRatingFormImgId,
                        this.lboxRatingFormImgRating,this.lboxRatingsMessageContainer,this.ratedContainer,
                        this.lboxNumRatingsSpan,this.lboxCommentsAmountDiv,this.commentsDataContainer,
                        this.lboxCommentsContainer,this.lboxCommentsForm,this.lboxCommentsTextarea,
                        this.lboxCommentsImgId,this.lboxCommentsGif,this.lboxCommentsMessageContainer,this.lboxRatingsInfoDiv,this.lboxRatingForm,
                        this.lboxRatingFormImgId,this.lboxRatingFormImgRating,this.lboxRatingsMessageContainer,
                        this.lboxNumRatingsSpan,this.lboxCommentsForm,this.lboxCommentsAmountDiv,
                        this.lboxCommentsContainer,this.lboxCommentsForm,this.lboxCommentsTextarea,
                        this.lboxCommentsImgId,this.lboxCommentsGif,this.lboxAllowComments,this.lboxAllowRating,
                        this.showLargeImage,this.slideShow,this.lboxSlideShow,this.lboxSlideshowAutostart,
                        this.commentsMessageContainer,this.lboxCommentsMessageContainer,
                        this.lboxShowThumbs,this.showThumbs,this.lboxShowThumbs,
                        this.lboxShowDescriptions,this.showDescriptions,this.lboxShowDescriptions,
                        this.imgholder);
        }

        //insert the large image
        this.ImageAsset = new Asset.images([this.host + 'images/stories/igallery/' + this.galleryFolder + '/large/' + this.imgFileNameArray[0] ],
        {
                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 + '/large/' + this.imgFileNameArray[0]);
                        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,
                                opacity: 1
                        });

                        //make lightbox slideshow object
                        if(this.lboxSlideshow == 1 && this.lightbox == 1)
                        {
                                this.lboxSlideShow = new slideShowClass(false,null,this.lboxLargeImgDiv,this.host,
                                this.galleryFolder,'lightbox',this.imgFileNameArray,1,this.numPics,this.lboxSlideshowPause,
                                this.lboxSlideshowPlay,this.guest,this.lboxAllowRating,this.idArray,this.ratingsContainer,this.lboxRatingsInfoDiv,
                                this.lboxRatingForm,this.lboxRatingFormImgId,this.lboxRatingFormImgRating,this.lboxRatingsMessageContainer,this.ratedContainer,this.lboxNumRatingsSpan,
                                this.lboxAllowComments,this.lboxCommentsAmountDiv,this.commentsDataContainer,this.lboxCommentsContainer,this.lboxCommentsForm,this.lboxCommentsTextarea,
                                this.lboxCommentsImgId,this.lboxCommentsGif,this.darkDiv,this.lboxCommentsMessageContainer,this.lboxDesContainer,
                                this.lboxShowDescriptions,this.lightbox,this.lboxSlideshowControls,this.imgholder,null,null);
                        }
                        else
                        {
                                this.lboxSlideShow = null;
                        }

                        //make the main behaviors class
                        this.mainBehaviors = new addBehaviors(this.thumbContainer,this.scrollBoundry,this.scrollSpeed,
                        this.thumbTable,this.fade,true,this.largeImgDiv,this.host,this.galleryFolder,
                        'large',this.imgFileNameArray,this.lightbox,this.desContainer,this.lightboxWidth,
                        this.darkDiv,this.whiteDiv,this.closeImage,this.lboxLargeImgDiv,this.preload,this.upArrow,
                        this.downArrow,this.leftArrow,this.rightArrow,this.showUpDown,this.showLeftRight,null,
                        this.magnify,this.numPics,this.lboxPreload,this.lboxDesContainer,
                        this.allowComments,this.allowRating,this.idArray,this.guest,this.ratingsContainer,
                        this.ratingsInfoDiv,this.ratingForm,this.ratingFormImgId,this.ratingFormImgRating,
                        this.ratingsMessageContainer,this.ratedContainer,this.numRatingsSpan,this.commentsAmountDiv,
                        this.commentsDataContainer,this.commentsContainer,this.commentsForm,this.commentsTextarea,
                        this.commentsImgId,this.commentsGif,this.commentsMessageContainer,this.lboxRatingsInfoDiv,this.lboxRatingForm,
                        this.lboxRatingFormImgId,this.lboxRatingFormImgRating,this.lboxRatingsMessageContainer,
                        this.lboxNumRatingsSpan,this.lboxCommentsForm,this.lboxCommentsAmountDiv,
                        this.lboxCommentsContainer,this.lboxCommentsForm,this.lboxCommentsTextarea,
                        this.lboxCommentsImgId,this.lboxCommentsGif,this.lboxAllowComments,this.lboxAllowRating,
                        this.showLargeImage,this.slideShow,this.lboxSlideShow,this.lboxSlideshowAutostart,
                        this.commentsMessageContainer,this.lboxCommentsMessageContainer,
                        this.showThumbs,this.showThumbs,this.lboxShowThumbs,
                        this.showDescriptions,this.showDescriptions,this.lboxShowDescriptions,this.imgholder);


                        //insert the magnify image
                        if (this.magnify == 1)
                        {
                                this.insertMagnify = new insertMagnifyClass(this.largeImgDiv,this.host,this.imageWidth,this.imageHeight);
                        }


                        //set the behavior for the first big image
                        this.firstThumbLink = $(this.thumbTable).getElement('a')
                        this.linkClass = this.firstThumbLink.getProperty('class');
                        this.linkTarget = this.firstThumbLink.getProperty('target');

                        if(this.linkClass == 'picture_link')
                        {
                                $(this.largeImgDiv).setStyle('cursor', 'pointer');

                                $(this.largeImgDiv).removeEvents('click');

                                $(this.largeImgDiv).addEvent('click', function(e)
                                {
                                        if (this.linkTarget == '_blank')
                                        {
                                                window.open(this.firstThumbLink);
                                        }
                                        else
                                        {
                                                window.location = this.firstThumbLink;
                                        }
                                }.bind(this));
                        }

                        if(this.lightbox == 1)
                        {

                                if(this.linkClass == 'no_link' )
                                {
                                        $(this.largeImgDiv).removeEvents('click');

                                        $(this.largeImgDiv).setStyle('cursor', 'pointer');

                                        $(this.largeImgDiv).addEvent('click', function(e)
                                        {
                                                this.mainBehaviors.igniteLightBox(0);
                                        }.bind(this));
                                }

                        }

                                //make slideshow object
                                if(this.slideshow == 1)
                                {
                                        this.slideShow = new slideShowClass(true,this.magnify,this.largeImgDiv,this.host,
                                        this.galleryFolder,'large',this.imgFileNameArray,1,this.numPics,this.slideshowPause,
                                        this.slideshowPlay,this.guest,this.allowRating,this.idArray,this.ratingsContainer,this.ratingsInfoDiv,
                                        this.ratingForm,this.ratingFormImgId,this.ratingFormImgRating,this.ratingsMessageContainer,this.ratedContainer,this.numRatingsSpan,
                                        this.allowComments,this.commentsAmountDiv,this.commentsDataContainer,this.commentsContainer,this.commentsForm,this.commentsTextarea,
                                        this.commentsImgId,this.commentsGif,this.darkDiv,this.commentsMessageContainer,this.desContainer,
                                        this.showDescriptions,this.lightbox,this.slideshowControls,this.imgholder,this.mainBehaviors,this.lboxSlideShow);
                                }
                                else
                                {
                                        this.slideShow = null;
                                }
                                this.mainBehaviors.slideShow = this.slideShow;



                                if(this.slideshow == 1)
                                {
                                        if(this.slideshowControls == 1)
                                        {
                                                $(this.slideshowPlay).addEvent('click', function(e)
                                                {
                                                        this.slideShow.startSlideShow(false);

                                                }.bind(this));

                                                $(this.slideshowForward).addEvent('click', function(e)
                                                {
                                                        this.slideShow.clearSlideShow();
                                                        this.slideShow.slideShowFunction(true);

                                                }.bind(this));

                                                $(this.slideshowRewind).addEvent('click', function(e)
                                                {
                                                        this.slideShow.clearSlideShow();
                                                        this.slideShow.slideShowFunction(false);

                                                }.bind(this));

                                        }

                                        if(this.slideshowAutostart == 1)
                                        {
                                                this.slideShow.startSlideShow(true);
                                        }
                                }

                                if(this.lboxSlideshow == 1 && this.lightbox == 1)
                                {
                                        if(this.lboxSlideshowControls == 1)
                                        {
                                                $(this.lboxSlideshowPlay).addEvent('click', function(e)
                                                {

                                                        this.lboxSlideShow.startSlideShow(false);

                                                }.bind(this));

                                                $(this.lboxSlideshowForward).addEvent('click', function(e)
                                                {
                                                        this.lboxSlideShow.clearSlideShow();
                                                        this.lboxSlideShow.slideShowFunction(true);

                                                }.bind(this));

                                                $(this.lboxSlideshowRewind).addEvent('click', function(e)
                                                {
                                                        this.lboxSlideShow.clearSlideShow();
                                                        this.lboxSlideShow.slideShowFunction(false);

                                                }.bind(this));

                                        }



                                }


                }.bind(this)
        });


        //make the comments/rating classes
        if(this.allowRating == 1)
        {
                this.mainRatings = new ratingsClass(this.guest,this.idArray,this.host,0,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,0,this.darkDiv,
                this.commentsMessageContainer,this.lightbox);
        }

        if(this.lboxAllowRating == 1 && this.lightbox == 1)
        {
                this.mainRatings = new ratingsClass(this.guest,this.idArray,this.host,0,this.ratingsContainer,
                this.lboxRatingsInfoDiv,this.lboxRatingForm,this.lboxRatingFormImgId,this.lboxRatingFormImgRating,this.lboxRatingsMessageContainer,
                this.ratedContainer,this.lboxNumRatingsSpan);
        }

        if(this.lboxAllowComments == 1 && this.lightbox == 1)
        {
                this.mainComments = new commentsClass(this.guest,this.idArray,this.host,this.lboxCommentsAmountDiv,
                this.commentsDataContainer,this.lboxCommentsContainer,
                this.lboxCommentsForm,this.lboxCommentsTextarea,this.lboxCommentsImgId,this.lboxCommentsGif,0,
                this.darkDiv,this.lboxCommentsMessageContainer,this.lightbox);
        }



}

});//end igallery class


