/*************************************************************** * Class Name: SlideImage * Description: We create an instance of this for each photo that goes into the slideshow * Parameters: * - strCounter: The slides index within the larger array of images * - strPath: The image location path * - strCaptionId: The ID for this slide's corresponding hidden DIV block of caption text * - strHeight: The height of the image * - strWidth: The width of the image * - strAlt: The ALT tag for the image ****************************************************************/ function SlideImg( strCounter, strPath, strCaptionId, strHeight, strWidth, strAlt ) { // Members var _strPath = strPath; var _strCounter = strCounter; var _objImg = new Image(1,1); var _strCaptionId = strCaptionId; var _height = strHeight; var _width = strWidth; var _alt = strAlt; // Properties this.id = "dv_" + _strCounter; // Methods this.getCaptionId = function() { return _strCaptionId; } this.setImg = function( val ) { _objImg = val; } this.getHeight = function() { return _height; } this.getWidth = function() { return _width; } this.getAlt = function() { return _alt; } this.getPath = function() { return _strPath; } this.loadImage = function() { _objImg.src = _strPath; } // end loadImage } // End SlideImg class /****************************************************************/ /**************************************************************** * Class Name: SlideShow * Description: Manages an array of Slide images * Parameters: * - dvCaptionPrefix: This is what all of the hidden DIV blocks are prefixed with. We need this so that each slide * within here can know who their corresponding hidden DIV block is. ****************************************************************/ function SlideShow( dvCaptionPrefix ) { var _arrSlides = new Array(); var _strPreviousId = ""; var _objCurrentSlide = null; var _intCurrentCounter = 0; var _dvCaptionPrefix = dvCaptionPrefix; this.slides = _arrSlides; this.addSlide = function( intCounter, strPath, strHeight, strWidth, strAlt ) { var objImg = new SlideImg( intCounter, strPath, _dvCaptionPrefix + intCounter, strHeight, strWidth, strAlt ); objImg.loadImage(); _arrSlides.push( objImg ); } this.getCurrentSlide = function() { return _objCurrentSlide; } this.setCurrentSlide = function( objSlide ) { _objCurrentSlide = objSlide; } this.getSlide = function( intCounter ) { var objNewSlide; setIndexes( intCounter ); objNewSlide = _arrSlides[_intCurrentSlide]; // Update who the current slide is, then return it this.setCurrentSlide( objNewSlide ); return objNewSlide; } this.size = function() { return _arrSlides.length; } function setIndexes( intCounter ) { _strPreviousId = _objCurrentSlide.id; _intCurrentSlide = parseInt( intCounter ) - 1; _intCurrentCounter = parseInt( intCounter ); } } /**************************************************************** * Class Name: Navigate * Description: Manages an array of Slide images * Parameters: * - strDivLinkPrefix: Our blocks of navigation (groups of 10) get prefixed with this. Ex. strDivPrefix_1, strDivPrefix_2 * - strAnchorLinkPrefix: All of the links within the navigation blocks share this prefix. Ex. a_1, a_2 * - strImageId: This is the id for the image whose 'src', 'height', 'width' and 'alt' attributes we swap out for the slideshow * - strCaptionId: This is the id for the DIV block where we swap out the caption text * - objSlideshow: This is a reference to the collection of slides we iterate through * - strCanvasId: This is a reference to the DIV wrapper that we fade in and out. Encompasses image and caption ****************************************************************/ function Navigate( strDivLinkPrefix, strAnchorLinkPrefix, strImageId, strCaptionId, objSlideshow, strCanvasId ) { var _intTotalCount = objSlideshow.size(); var _intCurrentIndex = 1; var _intPrevIndex = 1; var _strLinkPreface = strAnchorLinkPrefix; var _arrLinks = new Array(); var _strDivPreface = strDivLinkPrefix; var _intNavArrayPos = 0; var _bIsForward = false; var _bIsNextEnabled = true; var _bIsPrevEnabled = false; var _photoId = strImageId; var _captionId = strCaptionId; var _slides = objSlideshow; var _thisNav = this; var _imgHolderDiv = strCanvasId; var _objCanvas = new fx.Opacity( _imgHolderDiv, {duration: 400}); this.adjustContent = function() { // Set the visible text to be equal to the current item's hidden text Element.update(_captionId, this.getActiveCaption()); $(_captionId).scrollTop = 0; // Get the visible image - update his attributes var objPhoto = $(_photoId); objPhoto.src = this.slideshow.getCurrentSlide().getPath(); objPhoto.setAttribute( "alt", this.slideshow.getCurrentSlide().getAlt() ); objPhoto.setAttribute( "height", this.slideshow.getCurrentSlide().getHeight() ); objPhoto.setAttribute( "width", this.slideshow.getCurrentSlide().getWidth() ); } // Reference to our moo.fx effect this.canvas = _objCanvas; this.getLength = function() { return _arrLinks.length; } // Reference to slideshow this.slideshow = _slides; // Establish how many groups of 10 navigation links we have this.establishArrays = function() { var intCounter = 1; for( var i=1; i<=_intTotalCount; i=(i + 10)) { _arrLinks.push( _strDivPreface + intCounter ); intCounter++; } _intNavArrayPos = 0; } // Events that take place when trying to move to a new slide this.Position = function( intIndex ) { // Check that we are going to a new slide AND that we are not currently transitioning to a different one if( intIndex == _intCurrentIndex || _objCanvas.isInTransition() ) return; this.canvas.setOpacity(.5); // Update who is now the current slide _intPrevIndex = _intCurrentIndex; _intCurrentIndex = intIndex; var objSlide = this.slideshow.getSlide( _intCurrentIndex ); // Create a new image object for the image we're going to - once he is loaded, kick off the transition from old to new var img = new Image(1,1); img.onload = function() { _thisNav.canvas.options.onComplete = function(){ _thisNav.SwapPhotos();} _thisNav.canvas.toggleDim(); } // Set this image object on the respective slide and then load him objSlide.setImg( img ); objSlide.loadImage(); } /* New image has loaded in browser cache and old image has been completely faded out Update navigation, update image then fade it back in. */ this.SwapPhotos = function() { AdjustNavigationMenu(); this.adjustContent(); EnableNextButton( (_intCurrentIndex != _intTotalCount) ); EnablePrevButton( (_intCurrentIndex != 1) ); // Dereference onComplete event so we don't get stuck in a loop _objCanvas.options.onComplete = null; _objCanvas.toggle(); } // Moves to next item this.Next = function() { _bIsForward = true; var intTemp = parseInt( _intCurrentIndex ) + 1; if( intTemp <= _intTotalCount ) { this.Position( intTemp ); } else if( intTemp == _intTotalCount ) { this.Position( intTemp ); } else { //disable next button } // Check to see if we need to switch visible navs if( (_intPrevIndex % 10) == 0 ) { _intNavArrayPos++; Element.show($(getActiveNav())); Element.hide($(getPreviousNav())); } } // Logic for activating/deactivating Next button function EnableNextButton( bIsEnabled ) { if( _bIsNextEnabled != bIsEnabled ) { Element.setStyle( "aNext", {color: ( bIsEnabled ? "" : "#666666" ), textDecoration: ( bIsEnabled ? "" : "none" ), cursor: ( bIsEnabled ? "" : "default" ) }); _bIsNextEnabled = bIsEnabled; } } // Logic for activating/deactivating Previous button function EnablePrevButton( bIsEnabled ) { if( _bIsPrevEnabled != bIsEnabled ) { Element.setStyle( "aPrev", {color: ( bIsEnabled ? "" : "#666666" ), textDecoration: ( bIsEnabled ? "" : "none" ), cursor: ( bIsEnabled ? "" : "default" ) }); _bIsPrevEnabled = bIsEnabled; } } // Moves to previous item this.Prev = function() { _bIsForward = false; if( _intCurrentIndex > 1 ) { this.Position( parseInt( _intCurrentIndex ) - 1 ); } // Check to see if we need to switch visible navs if( (_intCurrentIndex % 10) == 0 ) { _intNavArrayPos--; Element.show($(getActiveNav())); Element.hide($(getPreviousNav())); } } function AdjustNavigationMenu() { $(getActiveLinkId()).className = "contentSelected"; $(getPreviousLinkId()).className = ""; } function getActiveLinkId() { return _strLinkPreface + _intCurrentIndex; } function getPreviousLinkId() { return _strLinkPreface + _intPrevIndex; } function getActiveNav() { return getMember( _intNavArrayPos ); } this.getActiveCaption = function() { return $((this.slideshow.getCurrentSlide()).getCaptionId()).innerHTML; } function getPreviousNav() { if( _bIsForward ) { return getMember(_intNavArrayPos - 1); } else { return getMember(_intNavArrayPos + 1); } } function getMember( intIndex ) { return _arrLinks[intIndex]; } }