    // the quicktime movie object
    var qtMovie = null;

	var testing = document.location.href.indexOf("test_transition") != -1;


    // this function is used to play the movie at the specified index in the list of movies
    function PlayMovieAtIndex(index) {
		// stop playing the current movie  
		try{qtMovie.playerObj.Stop();}catch (ex) {}
        
        // set the new index
        qtMovie.currentMovieIndex = index - 1;
        // trigger the play ended function
        PlaybackEnded();
    }


    function PlayerLoaded() {    
        // make sure the properties are reset on reload so event fire correctly
        qtMovie.playerObj.SetResetPropertiesOnReload(false);

        // reset prev selected movie
        if (qtMovie.prevMovieIndex != null) {
            qtMovie.moviesArray[qtMovie.prevMovieIndex].tableCell.className = "regularMovieCell";
            qtMovie.moviesArray[qtMovie.prevMovieIndex].image.src = qtMovie.moviesArray[qtMovie.prevMovieIndex].imageOutSrc;
        }
        // mark this movie as selected
        qtMovie.moviesArray[qtMovie.currentMovieIndex].tableCell.className = "selectedMovieCell";
        qtMovie.moviesArray[qtMovie.currentMovieIndex].image.src = qtMovie.moviesArray[qtMovie.currentMovieIndex].imageOverSrc;
        // make sure this image is visible/if not already (scroll to it)
        EnsureItemIsVisible(qtMovie.moviesArray[qtMovie.currentMovieIndex].tableCell, qtMovie.scrollContainer);
        // update movie title
        qtMovie.currentMovieTitleContainer.innerHTML = qtMovie.moviesArray[qtMovie.currentMovieIndex].movieTitleContainer.innerHTML.replace(/<br\s*\/?>/i, "&bull;");
        
        // set the prev movie index
        qtMovie.prevMovieIndex = qtMovie.currentMovieIndex;
    }

    function PlaybackEnded() {
    	if (testing)
        	ShowLoading();

        // move to the next movie in list
        qtMovie.currentMovieIndex = (qtMovie.currentMovieIndex + 1) % qtMovie.moviesArray.length;
        window.setTimeout(function() { if(testing) {alert("playing: " + qtMovie.moviesArray[qtMovie.currentMovieIndex].movieURL);}; qtMovie.playerObj.SetURL(qtMovie.moviesArray[qtMovie.currentMovieIndex].movieURL) }, 200);
    }
        
    function ShowLoading ()
    {
    	setSize(1, 1);
    }
    
    function HideLoading ()
    {
    	setSize(520, 315);
    }
    


    
    // build the movies array and the player
    CrossBrowserAddEventHandler(window, "load",
        function() {
            var preloadImagesArray = [];

            // set a reference to the movie object
            qtMovie = {
                playerObj: null,
                moviesArray: [],
                currentMovieIndex: movieIndex,
                prevMovieIndex: null,
                currentMovieTitleContainer: document.getElementById("divCurrentMovieTitle"),
                scrollContainer: document.getElementById("tblMovies").parentNode,
                scrollLeft: null,
                scrollRight: null,
                scrollUpdateInterval: null,
                playProgressUpdateInterval: null
            };

            // get the scroll buttons
            qtMovie.scrollLeft = getFirstChild(getPreviousSibling(qtMovie.scrollContainer, { tagName: "div", className: "divScrollLeft" }), { tagName: "img" });
            qtMovie.scrollRight = getFirstChild(getNextSibling(qtMovie.scrollContainer, { tagName: "div", className: "divScrollRight" }), { tagName: "img" });

            // set the events
            CrossBrowserAddEventHandler(qtMovie.scrollLeft, "mouseover", new Function("window.clearInterval(qtMovie.scrollUpdateInterval); qtMovie.scrollUpdateInterval = window.setInterval('scrollMovies(-1)', 100);"));
            CrossBrowserAddEventHandler(qtMovie.scrollLeft, "mouseout", new Function("window.clearInterval(qtMovie.scrollUpdateInterval);"));
            CrossBrowserAddEventHandler(qtMovie.scrollLeft, "click", new Function("scrollMovies(-10);"));
            CrossBrowserAddEventHandler(qtMovie.scrollRight, "mouseover", new Function("window.clearInterval(qtMovie.scrollUpdateInterval); qtMovie.scrollUpdateInterval = window.setInterval('scrollMovies(1)', 100);"));
            CrossBrowserAddEventHandler(qtMovie.scrollRight, "mouseout", new Function("window.clearInterval(qtMovie.scrollUpdateInterval);"));
            CrossBrowserAddEventHandler(qtMovie.scrollRight, "click", new Function("scrollMovies(10);"));
            scrollMovies(0);

            // get the first movie table cell (td)
            var tdMovie = getFirstChild(getFirstChild(getFirstChild(document.getElementById("tblMovies"), { tagName: "tbody" }), { tagName: "tr" }), { tagName: "td" });

            // build the list of movies
            while (tdMovie != null) {
                // create the movie object for this movie and add it to the collection of movies
                var image = getFirstChild(getFirstChild(tdMovie, { className: "movieImage" }), { tagName: "img" });
                var movieObject =
                    {
                        movieURL: hrefBase + tdMovie.getAttribute("movieURL"),
                        tableCell: tdMovie,
                        image: image,
                        imageOutSrc: image.src,
                        imageOverSrc: tdMovie.getAttribute("imageOverSrc"),
                        movieTitleContainer: getFirstChild(tdMovie, { className: "movieTitle" }),
                        index: -1
                    };

				if (tdMovie.getAttribute("movieURL"))
				{
			  		movieObject.tableCell.className = "regularMovieCell";
	                movieObject.index = qtMovie.moviesArray.push(movieObject) - 1;
	
	                // attach the mouse over events to the td
	                CrossBrowserAddEventHandler(tdMovie, "mouseover", new Function("if (qtMovie.currentMovieIndex != " + movieObject.index + ") {qtMovie.moviesArray[" + movieObject.index + "].image.src = '" + movieObject.imageOverSrc + "'};"));
	                CrossBrowserAddEventHandler(tdMovie, "mouseout", new Function("if (qtMovie.currentMovieIndex != " + movieObject.index + ") {qtMovie.moviesArray[" + movieObject.index + "].image.src = '" + movieObject.imageOutSrc + "'};"));
	                CrossBrowserAddEventHandler(tdMovie, "click", new Function("PlayMovieAtIndex(" + movieObject.index + ")"));
	
	                // add the over image to the preload array
	                preloadImagesArray.push(tdMovie.getAttribute("imageOverSrc"));
				}

                // move to the next movie cell
                tdMovie = getNextSibling(tdMovie, { tagName: "td" });
            }

            // show/hide scrolling arrows

            // get the player
            var objElem = document.getElementById("QT_movieOBJ");
            var embedElem = document.getElementById("QT_movieEMBED");

            if (null == objElem) {
                alert("QT plug-in could not be found...");
                return;
            }

            // update the player properties
            qtMovie.playerObj = embedElem ? embedElem : objElem;

            // attach events to the player
            CrossBrowserAddEventHandler(objElem, 'qt_begin', PlayerLoaded);
            CrossBrowserAddEventHandler(objElem, 'qt_ended', PlaybackEnded);

			// testing
            if (testing)
            {
	            qtMovie.objElem = objElem;
	            qtMovie.embedElem = embedElem;
            	CrossBrowserAddEventHandler(objElem, 'qt_canplay', HideLoading);
            	CrossBrowserAddEventHandler(objElem, 'qt_waiting', ShowLoading);
            }
            

            // make sure the properties are reset on reload so event fire correctly
           	qtMovie.playerObj.SetResetPropertiesOnReload(false);
           	qtMovie.playerObj.SetAutoPlay(true);

            // if any movies found, start the player
            if (qtMovie.moviesArray.length > 0) {
                qtMovie.currentMovieIndex = Math.max(0, Math.min(movieIndex, qtMovie.moviesArray.length)) - 1;
                PlaybackEnded();
            }

            // preload images
            for (var i = 0; i < preloadImagesArray.length; i++) {
                var preloadImage = new Image;
                preloadImage.src = preloadImagesArray[i];
            }
        }
    );
   
    
    
    function setSize(width, height)
    {
    	if (qtMovie.objElem)
    	{
	    	qtMovie.objElem.style.width = width + "px";
	    	qtMovie.objElem.style.height = height + "px";
	    	
	    	qtMovie.objElem.width = width + "px";
	    	qtMovie.objElem.height = height + "px";
    	}
    	if (qtMovie.embedElem)
    	{
	    	qtMovie.embedElem.style.width = width + "px";
	    	qtMovie.embedElem.style.height = height + "px";
	    	
	    	qtMovie.embedElem.width = width + "px";
	    	qtMovie.embedElem.height = height + "px";
    	}
    }


    function scrollMovies(direction) {
        if (direction == 0)
            qtMovie.scrollContainer.scrollLeft = 0;
            
        // scroll the container
        qtMovie.scrollContainer.scrollLeft = qtMovie.scrollContainer.scrollLeft + direction * 5;

        // show hide icons based on the scroll position
        if (direction <= 0 && qtMovie.scrollContainer.scrollLeft == 0)
                window.clearInterval(qtMovie.scrollUpdateInterval);
        else if (direction > 0 && qtMovie.scrollContainer.scrollLeft >= qtMovie.scrollContainer.scrollWidth - qtMovie.scrollContainer.offsetWidth)
                window.clearInterval(qtMovie.scrollUpdateInterval);

        // show hide icons based on the scroll position
        qtMovie.scrollLeft.style.display = qtMovie.scrollContainer.scrollLeft == 0 ? "none" : "inline";
        qtMovie.scrollRight.style.display = qtMovie.scrollContainer.scrollLeft >= qtMovie.scrollContainer.scrollWidth - qtMovie.scrollContainer.offsetWidth ? "none" : "inline";
    }