﻿function CustomizeSpotlightComponentObject(spotlight, width)
{
    //spotlight.ContainingDiv2 = document.getElementById('C'+spotlight.ComponentID);
   // spotlight.ContainingDiv = $('#C'+spotlight.ComponentID+' #moduleElement')[0];
    spotlight.ContainingDiv =$('#C'+spotlight.ComponentID).find('#moduleElement')[0]
    if(spotlight.AutoSize==0)
    {
        $(spotlight.ContainingDiv).width(spotlight.CustomWidth);
    }
    else
    {
        var tempWidth = $(spotlight.ContainingDiv).width();
        //alert(tempWidth);
        //alert($(spotlight.ContainingDiv.parentNode.parentNode.parentNode).width());
        $(spotlight.ContainingDiv).width(tempWidth-16);
    }
    __width = $(spotlight.ContainingDiv).width();
    spotlight.renderedWidth = 0;
    //spotlight.ContainingDiv.style.border = "1px solid green";
    
    spotlight.render = function()
    {
        // Chapters Button Bar
        this.ChaptersBarDiv = document.createElement("div");
        this.ContainingDiv.appendChild(this.ChaptersBarDiv);
        $(this.ChaptersBarDiv).addClass("spotlight_chapters_buttons");
        if(this.Chapters.length<2)
        {
            $(this.ContainingDiv).addClass("spotlight_single_chapter");
        }
        
        // Chapters Content Container
        this.ChaptersContainerDiv = document.createElement("div");
        this.ContainingDiv.appendChild(this.ChaptersContainerDiv);
        $(this.ChaptersContainerDiv).addClass("spotlight_chapters_content");
        
        // Render Chapters (now that container and button bar exist)
        for(var i=0,j=this.Chapters.length;i<j;i++)
        {
            //alert("i: "+i+"\ntitle: "+this.Chapters[i].Title);
            this.Chapters[i].render();
            //alert("Rendering OK: "+this.Chapters[i].Title);
        }
        this.fixChaptersButtonsWidth();
        
        this.renderedWidth = $(this.ChaptersContainerDiv).width();
        this.activate(1,1);
    }
    
    spotlight.fixChaptersButtonsWidth = function()
    {
        var targetsum = $(this.ChaptersBarDiv).width();
        if (jQuery.browser.safari)
        {
            for(var i=0,j=this.Chapters.length;i<j;i++)
            {
                $(this.Chapters[i].ChapterButtonDiv).width(targetsum/j);
            }
        }
        if(jQuery.browser.msie || jQuery.browser.safari) //Last Button sometimes gets hidden or is too short because msie does do fractional width percentages well (or at all?)--only integer width percentages...
        {
            var sum = 0;
            for(var i=0,j=this.Chapters.length;i<j;i++)
            {
                sum += $(this.Chapters[i].ChapterButtonDiv).width();
                //alert($(this.Chapters[i].ChapterButtonDiv).width());
            }
            //alert("targetsum:"+targetsum+"\nsum:"+sum);
            if(sum!=targetsum)
            {
                var theChapter = this.Chapters[this.Chapters.length-1];
                //$(theChapter.ChapterButtonDiv).width( $(theChapter.ChapterButtonDiv).width() + (targetsum-sum));
                $(theChapter.ChapterButtonDiv).css("width", $(theChapter.ChapterButtonDiv).width() + (targetsum-sum));
                //alert("Last:"+$(theChapter.ChapterButtonDiv).width());
            }
        }
    }

    spotlight.activate = function(iChapter,iSlide)
    {
        iChapter--;
        if(typeof iSlide != "undefined")
        {
            iSlide--; //make 0-based for js obj
        }
        else
        {
            iSlide = false;
        }
        var iActive = this.getActiveChapter();
        //alert(isNaN(iActive));
        if(!(iActive===false))
        {
            this.Chapters[iActive].deactivate();
        }
        this.Chapters[iChapter].activate(iSlide);

        if(this.Chapters[iChapter].Type==1 && this.Chapters[iChapter].AutoPlay)
        {
            //autoPlay
            this.Chapters[iChapter].startAutoPlay();
        }
    }
    
    spotlight.getActiveChapter = function()
    {
        for(var i=0,j=this.Chapters.length;i<j;i++)
        {
            if(this.Chapters[i].isActive==true)
            {
                return i;
            }
        }
        return false;
    }
    spotlight.getFontByType = function(FontType)
    {
        for(var i=0,j=this.Fonts.length;i<j;i++)
        {
            if(this.Fonts[i].Type==FontType)
            {
                return this.Fonts[i];
            }
        }
        return false;
    }

    // MS Ajax doesn't let you prototype server-side classes, no problem because Alex is awesome.
    for (var x = 0; x < spotlight.Fonts.length; x++)
    {
        CustomizeFontObject(spotlight.Fonts[x],spotlight);
    }
    for (var x = 0; x < spotlight.Chapters.length; x++)
    {
        CustomizeChapterObject(spotlight.Chapters[x],spotlight);
    }
}

function CustomizeFontObject(font,parent)
{
    // Extend class here
}

function CustomizeChapterObject(chapter,parent)
{
    chapter.Parent = parent;
    chapter.isActive = false;
    chapter.fadeOutHeight = 0;
    chapter.autoPlayTimer = false;
    chapter.slideButtonsToDisplay = 10;
    chapter.slideButtonListPosition = 0;
    chapter.AutoPlayInterval *= 1000;
    chapter.visibleSlideButtons = true;
    chapter.isFading = false;
    
    // Debug Variables
//    chapter.MinimumHeight = 300;
//    chapter.FadeTransitions = false;
//    if(chapter.Position==1)
//        chapter.AutoPlay = false;
//    if(chapter.Position==2)
//        chapter.Type = 2;
//    chapter.AutoPlayInterval = 5000;
//    chapter.Margin = 5;
//    chapter.LoopChapter=true;
    
    chapter.startAutoPlay = function()
    {
        clearTimeout(this.autoPlayTimer);
        $(this.SlidePlayButtonDiv).removeClass("spotlight_slides_playButton");
        $(this.SlidePlayButtonDiv).addClass("spotlight_slides_pauseButton");
        this.autoPlayTimer = setTimeout( function(){ chapter.nextAutoPlay(); }, this.AutoPlayInterval );
    }
    
    chapter.cancelAutoPlay = function()
    {
        clearTimeout(this.autoPlayTimer);
        this.autoPlayTimer = false;
        if(typeof this.SlidePlayButtonDiv != "undefined") $(this.SlidePlayButtonDiv).removeClass("spotlight_slides_pauseButton");
        if(typeof this.SlidePlayButtonDiv != "undefined") $(this.SlidePlayButtonDiv).addClass("spotlight_slides_playButton");
    }
    
    chapter.nextAutoPlay = function()
    {
        clearTimeout(this.autoPlayTimer);
        //alert("activechapter:"+this.Parent.getActiveChapter()+"\nposition-1:"+(this.Position-1)+"\nautoplay:"+this.AutoPlay);
        if(this.Parent.getActiveChapter()!=this.Position-1)
        {
            return false;
        }
        if(this.LoopChapter || (this.getActiveSlide()<this.Slides.length-1))
        {
            this.nextButtonClickFn(true);
            this.autoPlayTimer = setTimeout( function(){ chapter.nextAutoPlay();}, this.AutoPlayInterval );
        }
        else if ( (!this.LoopChapter) && !(this.getActiveSlide()<this.Slides.length-1) )
        {
            this.cancelAutoPlay();
        }
    }
    
    chapter.chapterButtonClickFn = function()
    {
        chapter.Parent.activate(chapter.Position,1); // chapter = closure var = this
    }
    chapter.slidePlayButtonClickFn = function()
    {
        //alert("Playing Chapter: "+this.Position);
        if(chapter.autoPlayTimer)
        {
            chapter.cancelAutoPlay();
        }
        else
        {
            chapter.startAutoPlay();
        }
    }
    chapter.previousButtonClickFn = function()
    {
        if(chapter.isFading) return false;
        chapter.cancelAutoPlay();
        var currentSlide = chapter.getActiveSlide();
        if(currentSlide==0)
        {
            // figure out where the start of the last page should be and then => chapter.showSlideButtonSet(lastPageStartIndex);
            chapter.showSlideButtonSet(chapter.Slides.length-(chapter.Slides.length % chapter.slideButtonsToDisplay));
            chapter.activate(chapter.Slides.length-1);
        }
        else
        {
            if(currentSlide==(chapter.slideButtonPosition))
            {
                chapter.showSlideButtonSet(chapter.slideButtonPosition-chapter.slideButtonsToDisplay);
            }
            chapter.activate(currentSlide-1);
        }
    }
    chapter.nextButtonClickFn = function(autoPlayed)
    {
        if(chapter.isFading) return false;
        if(! (autoPlayed===true) )
        {
            chapter.cancelAutoPlay();
        }
        //alert("Loop:"+chapter.LoopChapter);
        //alert(!(autoPlayed && !chapter.LoopChapter));
        var currentSlide = chapter.getActiveSlide();
        if(currentSlide==chapter.Slides.length-1)
        {
            chapter.showSlideButtonSet(0);
            chapter.activate(0);
        }
        else
        {
            //alert("chapter.slideButtonPosition+chapter.slideButtonsToDisplay-1="+(chapter.slideButtonPosition+chapter.slideButtonsToDisplay-1));
            if(currentSlide==(chapter.slideButtonPosition+chapter.slideButtonsToDisplay-1))
            {
                chapter.showSlideButtonSet(currentSlide+1);
            }
            chapter.activate(currentSlide+1);
        }
    }
    
    chapter.nextSetButtonClickFn = function()
    {
        if(chapter.isFading) return false;
        chapter.cancelAutoPlay();
        var currentSlide = chapter.getActiveSlide();
        var lastVisible = chapter.getLastVisibleSlideButtonIndex();
        if(!( (chapter.Slides.length-chapter.slideButtonPosition)>chapter.slideButtonsToDisplay))
        {
            // On the last set so do nothing -- or possibly loop back to beginning?
        }
        else
        {
            // Not on the last set, so advance to next set
            //alert("nextSetButtonClickFn::lastVisible="+lastVisible);
            chapter.showSlideButtonSet(lastVisible+1);
            chapter.activate(lastVisible+1);
        }
    }
    
    chapter.previousSetButtonClickFn = function()
    {
        if(chapter.isFading) return false;
        chapter.cancelAutoPlay();
        var currentSlide = chapter.getActiveSlide();
        var lastVisible = chapter.getLastVisibleSlideButtonIndex();
        if(!( (chapter.Slides.length-chapter.slideButtonPosition)>chapter.slideButtonsToDisplay))
        {
            // On the last set
            chapter.showSlideButtonSet(lastVisible-(chapter.slideButtonsToDisplay)+1-(chapter.Slides.length-chapter.slideButtonPosition));
            //chapter.activate(chapter.slideButtonPosition+chapter.slideButtonsToDisplay-1);
            chapter.activate(lastVisible-(chapter.Slides.length-chapter.slideButtonPosition)+1);
        }
        else if (chapter.slideButtonPosition==0)
        {
            //On first set so don't do anything -- or loop to last set?
        }
        else
        {
            // Not on the last set, so advance to next set
            //alert("nextSetButtonClickFn::lastVisible="+lastVisible);
            chapter.showSlideButtonSet(lastVisible-(chapter.slideButtonsToDisplay*2)+1);
            chapter.activate(lastVisible-(chapter.slideButtonsToDisplay));
            chapter.activate(lastVisible-(chapter.slideButtonsToDisplay*2)+1);
        }
    }
    
    chapter.getLastVisibleSlideButtonIndex = function()
    {
        for(var i=this.Slides.length-1;i>-1;i--)
        {
            if(this.Slides[i].isSlideButtonVisible())
                return i;
        }
        return i;
    }
    
    chapter.deactivate = function()
    {
        if(this.Type==3) // IE keeps playing video eventhough it's display:none; unless you delete it
        {
            this.deleteVideoElements();
        }
        if(this.Type==2) // IE keeps playing video eventhough it's display:none; unless you delete it
        {
            this.deleteFlashElements();
        }
    
        this.isActive = false;
        $(this.ChapterButtonDiv).removeClass("spotlight_active");
        $(this.ChapterContainerDiv).removeClass("spotlight_active");
        this.cancelAutoPlay();
    }
    
    chapter.showSlideButtonSet = function(Position)
    {
        this.slideButtonsToDisplay = (this.Parent.renderedWidth>340)?(10):(5);
        this.slideButtonPosition = Position;
        //alert("showSlideButtonSet::Position="+Position);
        this.showSlideButtons(this.slideButtonPosition,this.slideButtonsToDisplay);
    }
    
    chapter.activate = function(iSlide)
    {
        if(this.Type==3)
        {
            this.addVideoElements();
        }
        if(this.Type==2)
        {
            this.addFlashElements();
        }
        if( (this.Type==1) && (!this.isActive))
        {
            if( (this.Slides.length<6) || (this.Slides.length<11 && this.Parent.renderedWidth > 340 ) )
            {
                this.SlidePrevSetButtonDiv.style.display="none";
                this.SlideNextSetButtonDiv.style.display="none";
            }
            this.showSlideButtonSet(0);
        }
        
        this.isActive = true;
        $(this.ChapterButtonDiv).addClass("spotlight_active");
        $(this.ChapterContainerDiv).addClass("spotlight_active");
        
        // Activate iSlide if set
        if(!(isNaN(iSlide)))
        {
            var iActive = this.getActiveSlide();
            if(iSlide!=iActive || iActive===false)
            {
                if(!(iActive===false))
                {
                    this.Slides[iActive].deactivate();
                }
                //alert("Slides.length:"+this.Slides.length+"\niSlide:"+iSlide);
                if(this.Slides.length>iSlide && iSlide>-1)
                {
                    if(jQuery.browser.safari)
                        setTimeout(function(){chapter.Slides[iSlide].activate();},1);
                    else
                        this.Slides[iSlide].activate();
                }
            }
        }
        
        // IE6 is sloppy
        if(jQuery.browser.msie==true && parseInt(jQuery.browser.version)==6)
        {
            this.setSlideButtonWidth();
            $(this.SlideButtonsDiv).css("bottom","20px");
        }
        // The heights of cotent columns are set on page load by a call to adjustLayout();
        // The following borrows from adjustLayout(); to acheive a similar effect when the content is taller than the nav menus on either side
        if(!jQuery.browser.mozilla)
        {
            setTimeout(function(){if(true||window.spotlightResizedHeight!==true){window.spotlightResizedHeight=true;chapter.adjustColumnHeights();}},130);
        }            
        if(!jQuery.browser.safari)
        {
            chapter.adjustColumnHeights();
        }
    }
    
    chapter.adjustColumnHeights = function()
    {
        /* Updated for .Net pages - 01/12/2009 by RRR */
        $("#linkList3").css("height","");
        $("#linkList4").css("height","");
        $("#supportingElements").css("height","");
        $("#ctl00_ContentPlaceHolder1_supportingElements").css("height","");
        
        if(jQuery.browser.mozilla)
        {
            return;
//            var l3Height = document.defaultView.getComputedStyle(document.getElementById("linkList3"),null).getPropertyValue("height");
//            var l4Height = document.defaultView.getComputedStyle($("#linkList4")[0],null).getPropertyValue("height");
//            var seHeight = document.defaultView.getComputedStyle($("#supportingElements")[0],null).getPropertyValue("height");
//            var ppHeight = document.defaultView.getComputedStyle($("#pageProperties")[0],null).getPropertyValue("height");
//            var stHeight = document.defaultView.getComputedStyle($("#linkList4")[0],null).getPropertyValue("height");
//            var sbHeight = document.defaultView.getComputedStyle($("#spanBottom")[0],null).getPropertyValue("height");
//            var rplHeight = document.defaultView.getComputedStyle($("#relatedPageLinks")[0],null).getPropertyValue("height");
//            var c0Height = document.defaultView.getComputedStyle($("#column0")[0],null).getPropertyValue("height");
//            var c1Height = document.defaultView.getComputedStyle($("#column1")[0],null).getPropertyValue("height");
//            var c2Height = document.defaultView.getComputedStyle($("#column2")[0],null).getPropertyValue("height");
//            var c3Height = document.defaultView.getComputedStyle($("#column3")[0],null).getPropertyValue("height");
//            var c4Height = document.defaultView.getComputedStyle($("#column4")[0],null).getPropertyValue("height");
        }
        else
        {
            var l3Height = $("#linkList3").height();
            var l4Height = $("#linkList4").height();            
            var seHeight = $("#supportingElements").height();
            if (!seHeight)
                seHeight = $("#ctl00_ContentPlaceHolder1_supportingElements").height();            
            var ppHeight = $("#pageProperties").height();            
            var stHeight = $("#spanTop").height();
            if (!stHeight)
                stHeight = $("#ctl00_ContentPlaceHolder1_spanTop").height();            
            var sbHeight = $("#spanBottom").height();
            if (!sbHeight)
                sbHeight = $("#ctl00_ContentPlaceHolder1_spanBottom").height();            
            var rplHeight = $("#relatedPageLinks").height();
            var c0Height = $("#column0").height();
            if (!c0Height)
                c0Height = $("#ctl00_ContentPlaceHolder1_column0").height();
            var c1Height = $("#column1").height();
            if (!c1Height)
                c1Height = $("#ctl00_ContentPlaceHolder1_column1").height();
            var c2Height = $("#column2").height();
            if (!c2Height)
                c2Height = $("#ctl00_ContentPlaceHolder1_column2").height();
            var c3Height = $("#column3").height();
            if (!c3Height)
                c3Height = $("#ctl00_ContentPlaceHolder1_column3").height();
            var c4Height = $("#column4").height();
            if (!c4Height)
                c4Height = $("#ctl00_ContentPlaceHolder1_column4").height();
        }
    //        $("#spotlight").css("position","absolute");
    //        $("#spotlight").css("top","0px");
    //        $("#spotlight").css("left","0px");
            //setTimeout(function(){alert($("#spotlight").height())},5000);
            var colMaxHeight = Math.max(c0Height,c1Height,c2Height,c3Height,c4Height);
            var seCalcHeight = colMaxHeight+rplHeight+sbHeight+stHeight+ppHeight+ ( (jQuery.browser.mozilla || jQuery.browser.safari) ? (32) : (0) );
            var maxHeight = Math.max(l3Height,l4Height,seCalcHeight);
            
            $("#linkList3").height(maxHeight);
            $("#linkList4").height(maxHeight);            
            $("#supportingElements").height(maxHeight);
            $("#ctl00_ContentPlaceHolder1_supportingElements").height(maxHeight);
            
            //$("#supportingElements").css("border","1px solid green");
            //alert(l3Height+"|"+l4Height+"|"+maxHeight);
            //alert("c0:"+c0Height+"\nc1:"+c1Height);
    }
    
    chapter.showSlideButtons = function (Start,Count)
    {
        for(var i=0,j=this.Slides.length;i<j;i++)
        {
            if(i>=Start && i<(Start+Count))
            {
                this.Slides[i].showSlideButton();
            }
            else
            {
                this.Slides[i].hideSlideButton();
            }
        }
    }
    
    chapter.setSlideButtonWidth = function()
    {
        $(this.SlideButtonsDiv).width( $(this.ChapterContainerDiv).width() ); //ChapterContainerDiv
    }
    
    chapter.getActiveSlide = function()
    {
        for(var i=0,j=this.Slides.length;i<j;i++)
        {
            if(this.Slides[i].isActive==true)
            {
                return i;
            }
        }
        return false;
    }
    
    chapter.render = function ()
    {
        var fontChapterButton = this.Parent.getFontByType(1);
        //alert((function(theObj){var retval ="";for(prop in theObj){retval+=prop+":"+theObj[prop]+"\n";}return retval;})(fontChapterButton));
        // Chapter Button @ Top
        this.ChapterButtonDiv = document.createElement("div");
        $(this.ChapterButtonDiv).css("font-family",fontChapterButton.Name);
        $(this.ChapterButtonDiv).css("font-size",fontChapterButton.Size);
        $(this.ChapterButtonDiv).css("color","#"+fontChapterButton.Color);
        $(this.ChapterButtonDiv).addClass("spotlight_chapter_button");
        $(this.ChapterButtonDiv).addClass("spotlight_no_text_select");
        if(this.Position==1) //Position is 1-based, not 0
        {
            $(this.ChapterButtonDiv).addClass("spotlight_firstChild");
            //$(this.ChapterButtonDiv).addClass("spotlight_active");
        }
        if(this.Position==this.Parent.Chapters.length-1)
        {
            $(this.ChapterButtonDiv).addClass("spotlight_lastChild");
        }

        $(this.ChapterButtonDiv).bind("click",this.chapterButtonClickFn);
            
        $(this.ChapterButtonDiv).attr("id","C"+this.ComponentId+"_cb"+this.Position);
        $(this.ChapterButtonDiv).css("width",(100.00/this.Parent.Chapters.length)+"%");
        this.ChapterButtonInnerDiv = document.createElement("div");
        this.ChapterButtonDiv.appendChild(this.ChapterButtonInnerDiv);
        $(this.ChapterButtonInnerDiv).addClass("spotlight_inner");
        if(this.Position==1)
        {
            $(this.ChapterButtonInnerDiv).addClass("spotlight_inner_firstChild");
        }
        if(this.Position==this.Parent.Chapters.length)
        {
            $(this.ChapterButtonInnerDiv).addClass("spotlight_inner_lastChild");
        }
        $(this.ChapterButtonInnerDiv).text(this.Title);
        
        // Chapter Container in chapters_content container
        this.ChapterContainerDiv = document.createElement("div");
        $(this.ChapterContainerDiv).addClass("spotlight_chapter");
        $(this.ChapterContainerDiv).attr("id","C"+this.ComponentId+"_c"+this.Position);

        // Append Button and Content to Parent Component
        this.Parent.ChaptersBarDiv.appendChild(this.ChapterButtonDiv); // Parent Reference
        this.Parent.ChaptersContainerDiv.appendChild(this.ChapterContainerDiv); // Parent Reference
        
        // Pages Containers inside Chapter Container
        this.SlidesContainerDiv = document.createElement("div");
        $(this.SlidesContainerDiv).addClass("spotlight_slides");
        this.ChapterContainerDiv.appendChild(this.SlidesContainerDiv);
        
        // Pages Buttons Bar inside Chapter Container
        this.SlideButtonsDiv = document.createElement("div");

        //$(this.SlideButtonsDiv).width( $(this.ChapterContainerDiv).width() );
        $(this.SlideButtonsDiv).width( $(this.Parent.ChaptersContainerDiv).width() );
        //alert($(this.ChapterContainerDiv).width());
        //$(this.SlideButtonsDiv)[0].style.width = $(this.ChapterContainerDiv).width()+"px"; 
        //$('body').click(function(){ alert( $(chapter.ChapterContainerDiv).width() ) });
        $(this.SlideButtonsDiv).addClass("spotlight_slides_buttons");
        this.ChapterContainerDiv.appendChild(this.SlideButtonsDiv);
        if(this.Slides.length<2)
        {
            $(this.ChapterContainerDiv).addClass("spotlight_single_slide");
            this.visibleSlideButtons = false;
        }
        
        if(this.AutoPlay)
        {
            this.SlidePlayButtonDiv = document.createElement("div");
            $(this.SlidePlayButtonDiv).addClass("spotlight_slides_playButton");
            this.SlideButtonsDiv.appendChild(this.SlidePlayButtonDiv);
            $(this.SlidePlayButtonDiv).bind("click",this.slidePlayButtonClickFn);
        }
        
        
        this.SlideCenterButtonsDiv = document.createElement("div");
        $(this.SlideCenterButtonsDiv).addClass("spotlight_slides_centerButtons");
        this.SlideButtonsDiv.appendChild(this.SlideCenterButtonsDiv);
        
        this.SlidePrevSetButtonDiv = document.createElement("span");
        $(this.SlidePrevSetButtonDiv).addClass("spotlight_slides_prevSetButton");
        $(this.SlidePrevSetButtonDiv).addClass("spotlight_no_text_select");
        this.SlideCenterButtonsDiv.appendChild(this.SlidePrevSetButtonDiv);
        $(this.SlidePrevSetButtonDiv).html("&nbsp;&nbsp;&nbsp;");
        $(this.SlidePrevSetButtonDiv).bind("click",this.previousSetButtonClickFn);
        
        this.SlidePreviousButtonDiv = document.createElement("span");
        $(this.SlidePreviousButtonDiv).addClass("spotlight_slides_previousButton");
        $(this.SlidePreviousButtonDiv).addClass("spotlight_no_text_select");
        this.SlideCenterButtonsDiv.appendChild(this.SlidePreviousButtonDiv);
        $(this.SlidePreviousButtonDiv).html("&nbsp;&nbsp;&nbsp;");
        $(this.SlidePreviousButtonDiv).bind("click",this.previousButtonClickFn);
        
        this.SlideNumberButtonsDiv = document.createElement("span");
        $(this.SlideNumberButtonsDiv).addClass("spotlight_slides_numberButtons");
        this.SlideCenterButtonsDiv.appendChild(this.SlideNumberButtonsDiv);
        
        this.SlideNextButtonDiv = document.createElement("span");
        $(this.SlideNextButtonDiv).addClass("spotlight_slides_nextButton");
        $(this.SlideNextButtonDiv).addClass("spotlight_no_text_select");
        this.SlideCenterButtonsDiv.appendChild(this.SlideNextButtonDiv);
        $(this.SlideNextButtonDiv).html("&nbsp;&nbsp;&nbsp;");
        $(this.SlideNextButtonDiv).bind("click",this.nextButtonClickFn);
        
        this.SlideNextSetButtonDiv = document.createElement("span");
        $(this.SlideNextSetButtonDiv).addClass("spotlight_slides_nextSetButton");
        $(this.SlideNextSetButtonDiv).addClass("spotlight_no_text_select");
        this.SlideCenterButtonsDiv.appendChild(this.SlideNextSetButtonDiv);
        $(this.SlideNextSetButtonDiv).html("&nbsp;&nbsp;&nbsp;");
        $(this.SlideNextSetButtonDiv).bind("click",this.nextSetButtonClickFn);
        
        /* Add add Pause, First, Previous, Next, Last Buttons */
        //alert("Rendering Chapter Content: "+this.Title);  
        this.renderContent();
        //alert("Rendering OK: "+this.Title);
    }
    
    chapter.areSlideButtonsVisible = function ()
    {
        return this.visibleSlideButtons;
    }
    
    chapter.renderContent = function()
    {
        // Render Pages (now that Pages Container and Pages Buttons Bar exist)
        if(this.Type==1)
        {
            //Minimum Height Fix
            $(this.ChapterContainerDiv).css("min-height",this.MinimumHeight+"px");
            if(jQuery.browser.msie==true && parseInt(jQuery.browser.version)==6)
            {
                $(this.ChapterContainerDiv).css("height",this.MinimumHeight+"px");
            }
            
            for(var i=0,j=this.Slides.length;i<j;i++)
            {
                this.Slides[i].render();
            }
        }
        else
        {
            //Minimum Height Fix
            if(this.MinimumHeight<(this.Margin*2)) /* IE7 dies without this range check */
            {
                this.MinimumHeight = this.Margin*2+1;
            }
            $(this.ChapterContainerDiv).css("min-height",(this.MinimumHeight - (this.Margin*2) )+"px");
                
            if(jQuery.browser.msie==true && parseInt(jQuery.browser.version)==6)
            {
                $(this.ChapterContainerDiv).css("height",(this.MinimumHeight - (this.Margin*2) )+"px");
            }
            $(this.ChapterContainerDiv).css("padding",this.Margin+"px");

            if(this.Type==2)
            {
                $(this.ChapterContainerDiv).css("text-align","center");
                // This rendered when chapter is activated (see notes in deactivate method)
                //this.addFlashElements();
            }
            else if(this.Type==3)
            {
                $(this.ChapterContainerDiv).css("text-align","center");
                // This rendered when chapter is activated (see notes in deactivate method)
                //this.addVideoElements();
            }
            else
            {
                // Could alternatively just output html from a CustomHtml property of the ComponentChapter object
                // But Javascript in the html would have to be sent separately and "eval()"-ed
                $(this.ChapterContainerDiv).css("text-align","center");
                $(this.ChapterContainerDiv).html("[Unknown Chapter Type]");
            }
        }
    }
    
    chapter.addFlashElements = function()
    {
        //Need this so that IE6 will be able to calculate the width properly
        $(this.ChapterContainerDiv).html("<div style='width:100%;'>Loading...</div>");
        
        this.videoHeight = this.FlashVideo.Height;
        this.videoWidth = this.FlashVideo.Width;
        //alert("Flash\nWidth:"+this.videoWidth+"\nHeight:"+this.videoHeight);
        //var maxWidth = (this.Parent.AutoSize==0) ? ( this.Parent.CustomWidth - ( 2 * this.Margin ) - 2 ) : ( $(this.ChapterContainerDiv).width()- ( 2 * this.Margin ) );
        var maxWidth = (this.Parent.AutoSize == 0) ? ( this.Parent.CustomWidth - ( 2 * this.Margin ) - 2 ) : ( $(this.Parent.ChaptersContainerDiv).width() - ( 2 * this.Margin ) );
        //alert(maxWidth);
        if(this.FlashVideo.Width > maxWidth)
        {
            this.videoWidth = maxWidth;
            //alert("this.videoWidth:"+this.videoWidth);
            //alert("$(this.ChapterContainerDiv).css('padding'):"+$(this.ChapterContainerDiv).css("padding"));
            this.videoHeight = (this.videoWidth * this.FlashVideo.Height) / this.FlashVideo.Width;//this.videoWidth / (1+(1/4));
        }
        if(this.videoHeight == 0)
        {
            if(jQuery.browser.msie && parseInt(jQuery.browser.version) == 6)
            {
                this.videoWidth=maxWidth;
                this.videoHeight=this.videoWidth*.75;
                
            }
            else
            {
                this.videoHeight="";
                this.videoWidth="";
            }
        }
        
        //alert("Flash\nWidth:"+this.videoWidth+"\nHeight:"+this.videoHeight);
    
        //This is pulled from /js/globalPage.js -- can't just call the getFlashPlayer function because it uses "standard out" document.write which won't work here--"standard out" will go to the wrong part of the page if run here
        var flashHtml = "";
        // Still relies on /js/globalPage.js to set MM_FlashCanPlay        
        if ( MM_FlashCanPlay )
        {
            flashHtml = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
            flashHtml += '  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
            flashHtml += ' ID="'+this.FlashVideo.Id+'" WIDTH="'+this.videoWidth+'" HEIGHT="'+this.videoHeight+'" ALIGN="">';
            flashHtml += '<PARAM NAME=movie VALUE="/flashmovie.html?ID='+this.FlashVideo.Id+'"><PARAM NAME=menu VALUE=false><PARAM NAME=quality VALUE=high><PARAM NAME=wmode VALUE=transparent><PARAM NAME=bgcolor VALUE=#FFFFFF>'; 
            flashHtml += '<EMBED src="/flashmovie.html?ID='+this.FlashVideo.Id+'" menu=false quality=high wmode=transparent bgcolor=#FFFFFF  ';
            flashHtml += ' swLiveConnect=FALSE WIDTH="'+this.videoWidth+'" HEIGHT="'+this.videoHeight+'" NAME="flashcomp'+this.FlashVideo.Id+'" ALIGN=""';
            flashHtml += ' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">';
            flashHtml += '</EMBED>';
            flashHtml += '</OBJECT>';
        }
        else
        {
            //render placeholder image
            flashHtml = '<img border="0" src="/display_image.aspx?id=' + this.ImageId + '" height="' + this.videoHeight + '" width="' + this.videoWidth + '" alt="You must have Flash Player installed to view this." />';
            //render the flash object with no height or width to try to prompt the user to install flash
            flashHtml += '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
            flashHtml += '  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
            flashHtml += ' ID="'+this.FlashVideo.Id+'" WIDTH="0" HEIGHT="0" ALIGN="">';
            flashHtml += '<PARAM NAME=movie VALUE="/flashmovie.html?ID='+this.FlashVideo.Id+'"><PARAM NAME=menu VALUE=false><PARAM NAME=quality VALUE=high><PARAM NAME=wmode VALUE=transparent><PARAM NAME=bgcolor VALUE=#FFFFFF>'; 
            flashHtml += '<EMBED src="/flashmovie.html?ID='+this.FlashVideo.Id+'" menu=false quality=high wmode=transparent bgcolor=#FFFFFF  ';
            flashHtml += ' swLiveConnect=FALSE WIDTH="0" HEIGHT="0" NAME="flashcomp'+this.FlashVideo.Id+'" ALIGN=""';
            flashHtml += ' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">';
            flashHtml += '</EMBED>';
            flashHtml += '</OBJECT>';
        }
        //$(this.ChapterContainerDiv)[0].innerHTML = flashHtml;
        $(this.ChapterContainerDiv).html(flashHtml);
    }
    chapter.deleteFlashElements = function()
    {
        //this.ChapterContainerDiv.innerHTML = "";
        $(this.ChapterContainerDiv).html("");
    }
    
    chapter.addVideoElements = function()
    {
        $(this.ChapterContainerDiv).css("text-align","center");
        this.VideoDiv = document.createElement("div");
        this.ChapterContainerDiv.appendChild(this.VideoDiv)
        $(this.VideoDiv).attr("id","player"+this.ComponentId+"_c"+this.Id);
        $(this.VideoDiv).css("width","auto");
        $(this.VideoDiv).html('<table><tr><td style="background-color:#ffffcc; border-color:#dadada; border-width:1px; border-style:solid; font-family:Arial; font-weight:bold; font-size:11px; padding:5px;">You Either Have Javascript off or an old version of Macromedia\'s Flash Player. <a href="http://www.macromedia.com/go/getflashplayer" >Click here to get the latest Flash Player.</a></td></tr></table>'); 
        
        this.videoHeight = this.Height;
        this.videoWidth = this.Width;
        // Uncomment the following to make video scale to fit the window, but change to use AutoSize as check instead of just CUstomWidth
        /*this.videoHeight = 0;
        this.videoWidth = 0;
        if(this.Parent.CustomWidth)
        {
            this.videoWidth = this.Parent.CustomWidth- ( 2 * this.Margin )-2;
            this.videoHeight = parseInt((this.videoWidth*this.Width) / this.Height); // / (1+(1/4)) ;
        }
        else
        {
            this.videoWidth = $(this.ChapterContainerDiv).width()- ( 2 * this.Margin );
            this.videoHeight = parseInt((this.videoWidth*this.Width) / this.Height); // / (1+(1/4)); //(1+(1/3)
        }*/
        //alert("Video\nWidth:"+this.videoWidth+"\nHeight:"+this.videoHeight);
        
        // Check to see if size is bigger than size of component, if so, scale video down.
        //alert($(this.ChapterContainerDiv).width());
        //alert(this.Width);
        if( ((this.Parent.AutoSize==1) && this.Width > ( $(this.ChapterContainerDiv).width() - ( 2 * this.Margin ) ) )      ||     (this.Width > (this.Parent.CustomWidth- ( 2 * this.Margin )-2)) )
        {
            this.videoWidth = (this.Parent.AutoSize==0)? (this.Parent.CustomWidth- ( 2 * this.Margin )-2) : ($(this.ChapterContainerDiv).width()- ( 2 * this.Margin ));
            this.videoHeight = parseInt((this.Height*this.videoWidth) / this.Width); // / (1+(1/4)) ;
            //alert("ow:"+this.Width+" oh:"+this.Height);
            //alert("w:"+this.videoWidth+" h:"+this.videoHeight);
        }
        
        this.so = new SWFObject('/FlashPlayer/flvplayer.swf','player'+this.ComponentId+'_c'+this.Id, this.videoWidth,this.videoHeight,'7');
        this.so.addVariable("file","rtmp://ujc.flashsvc.vitalstreamcdn.com/ujc_vitalstream_com/_definst_/"+this.VitalStreamVideo.VideoPath); //change file 
        this.so.addVariable("id", this.VitalStreamVideo.Filename); //change id
        this.so.addVariable('usefullscreen','false');
        if(this.ImageId > 0)
            this.so.addVariable("image", "/display_image.aspx?ID=" + this.ImageId);
        this.so.addParam("allowfullscreen", "false");
        this.so.addParam("wmode","transparent");
        this.so.addVariable("displayheight", this.videoHeight-19);
        this.so.addVariable("backcolor", "0x7c8687");
        this.so.addVariable("frontcolor", "0xffffff");
        this.so.addVariable("lightcolor", "0xd6ecf7");
        this.so.write('player'+this.ComponentId+'_c'+this.Id);
        $(this.ChapterContainerDiv).css("height",this.videoHeight);
        $(this.ChapterContainerDiv).css("overflow","hidden");
        //setTimeout( function(){alert("Chapter Height: "+$(this.ChapterContainerDiv).height()+"\nPlayer Height:"+$('#player'+this.ComponentId+'_c'+this.Id).height());},1000);
    }
    
    chapter.deleteVideoElements = function()
    {
        delete this.so;
        delete this.VideoDiv;
        //this.ChapterContainerDiv.innerHTML = "";
        $(this.ChapterContainerDiv).html("");
    }


    for (var x = 0; x < chapter.Slides.length; x++)
    {
        CustomizeSlideshowObject(chapter.Slides[x],chapter);
    }
}


function CustomizeSlideshowObject(slide,parent)
{

    slide.Parent = parent;
    
    slide.isActive = false;
    
    slide.numberButtonClickFn = function()
    {
        if(slide.Parent.isFading) return false;
        slide.Parent.cancelAutoPlay();
        slide.Parent.activate(slide.Position-1); //slide=closure var=this
    }
    
    slide.deactivate = function()
    {
        this.isActive = false;
        
        if(this.Parent.FadeTransitions)
        {
            //$(this.SlideContainerDiv).removeClass("spotlight_active");
            this.Parent.fadeOutHeight = $(this.SlideContainerDiv).height();
            if(jQuery.browser.msie)
            {
                this.Parent.fadeOutHeight += this.Parent.Margin;
            }
            $(this.SlideContainerDiv).css("top","0px");
            $(this.SlideContainerDiv).css("position","absolute");
            this.Parent.isFading = true;
            $(this.SlideContainerDiv).fadeOut("slow",slide.deactivateFadeOutFn);
        }
        else
        {
            $(this.SlideContainerDiv).removeClass("spotlight_active");
        }
        
        $(this.SlideButtonDiv).removeClass("spotlight_active");
    }
    slide.deactivateFadeOutFn = function()
    {
        $(slide.SlideContainerDiv).css("position","");
        $(slide.SlideContainerDiv).removeClass("spotlight_active");
    }
    
    slide.activate = function()
    {
        this.isActive = true;
        //this.Parent.setSlideButtonWidth();
        if(jQuery.browser.msie && parseInt(jQuery.browser.version)==6 && this.Parent.Parent.AutoSize==1)
        {
            $(this.SlideContainerDiv).html(this.renderInnerHtml());
        }
        if(this.Parent.FadeTransitions)
        {
            if(this.Parent.fadeOutHeight > $(this.SlideContainerDiv).height())
            {
                $(this.SlideContainerDiv).height(this.Parent.fadeOutHeight);
                //this.slideButtonsFix();
            }
            
            //$(this.SlideContainerDiv).addClass("spotlight_active");
            $(this.SlideContainerDiv).fadeIn("slow",slide.activateFadeInFn);
        }
        else
        {
            if(jQuery.browser.safari)
                setTimeout(function(){slide.slideButtonsFix();},1);
            else
                slide.slideButtonsFix();
            $(this.SlideContainerDiv).addClass("spotlight_active");
        }
        $(this.SlideButtonDiv).addClass("spotlight_active");
    }
    slide.activateFadeInFn = function()
    {
        $(slide.SlideContainerDiv).addClass("spotlight_active");
        $(slide.SlideContainerDiv).height("auto");
        if(jQuery.browser.msie && parseInt(jQuery.browser.version)==6)
        {
            $(slide.Parent.SlideButtonsDiv).css("bottom","20px");
            $(slide.Parent.SlideButtonsDiv).css("bottom","22px");
        }
        if(jQuery.browser.safari)
        {
            setTimeout(function(){slide.slideButtonsFix();},1);
        }
        else
            slide.slideButtonsFix();
            
        slide.Parent.isFading = false;
    }
    slide.slideButtonsFix = function()
    {
        // Safari is sloppy... VERY sloppy.
        if(jQuery.browser.safari )
        {
            var height = $(this.SlideContainerDiv).height();
            //alert("NO TIMER\nHeight: "+height+"\nMinimumHeight: "+slide.Parent.MinimumHeight+"\nMargin*2: "+(slide.Parent.Margin*2)+"\nChapter Height: "+$(slide.Parent.ChapterContainerDiv).height()+"\nSlide Buttons Height"+$(slide.Parent.SlideButtonsDiv).height());
            //setTimeout(function(){alert("Height: "+height+"\nMinimumHeight: "+slide.Parent.MinimumHeight+"\nMargin*2: "+(slide.Parent.Margin*2)+"\nChapter Height: "+$(slide.Parent.ChapterContainerDiv).height()+"\nSlide Buttons Height"+$(slide.Parent.SlideButtonsDiv).height());},500);
            //alert(height);
            //alert((this.Parent.MinimumHeight - 20));
            if( height < (this.Parent.MinimumHeight - 20) )
            {
                //alert(height+"\n"+typeof this.Parent.MinimumHeight);
                height=this.Parent.MinimumHeight-20;
            }
            else if (height<this.Parent.MinimumHeight)
            {
                var diff = this.Parent.MinimumHeight - height;
                //alert("diff"+diff);
                height = this.Parent.MinimumHeight+diff+(this.Parent.Margin*2)-2;
            }
            else
            {
                height += (this.Parent.Margin*2)+0;
            }
            $(this.Parent.SlideButtonsDiv).css("bottom","auto");
            $(this.Parent.ChapterContainerDiv).css("overflow","hidden");
            $(this.SlideContainerDiv).css("overflow","hidden");
            $(this.Parent.SlideButtonsDiv).css("top", height+"px");
            //setTimeout(function(){alert("Height: "+height+"\nMinimumHeight: "+slide.Parent.MinimumHeight+"\nMargin*2: "+(slide.Parent.Margin*2)+"\nChapter Height: "+$(slide.Parent.ChapterContainerDiv).height()+"\nSlide Buttons Height"+$(slide.Parent.SlideButtonsDiv).height());},1);
        }
        else if (jQuery.browser.msie && parseInt(jQuery.browser.version)==6)
        {
            var height = $(this.SlideContainerDiv).height();
            //alert("Height: "+height+"\nMinimumHeight: "+this.Parent.MinimumHeight+"\nMargin*2: "+(this.Parent.Margin*2)+"\nChapter Height: "+$(this.Parent.ChapterContainerDiv).height()+"\nSlide Buttons Height"+$(this.Parent.SlideButtonsDiv).height());
            if(height<this.Parent.MinimumHeight)
            {
                height=this.Parent.MinimumHeight-20;
            }
            else
            {
                height += (this.Parent.Margin*2)+0;
            }
            $(this.Parent.SlideButtonsDiv).css("bottom","auto");
            $(this.Parent.SlideButtonsDiv).css("top", height+"px");
            //if(this.Type==1)
            //{
                 if(height>this.Parent.MinimumHeight)
                 {
                    $(this.Parent.ChapterContainerDiv).css("height", (height+(this.Parent.Margin*2))+"px");
                 }
           // }
        }
    }
    
    slide.isSlideButtonVisible = function()
    {
        return !($(this.SlideButtonDiv).css("display")=="none");
    }
    
    slide.showSlideButton = function()
    {
        $(this.SlideButtonDiv).css("display","");
    }
    
    slide.hideSlideButton = function()
    {
        $(this.SlideButtonDiv).css("display","none");
    }
    
    slide.render = function(objParent)
    {
        // Slide Button
        this.SlideButtonDiv = document.createElement("div");
        $(this.SlideButtonDiv).addClass("spotlight_slide_button");
        $(this.SlideButtonDiv).attr("id","C"+this.Parent.ComponentId+"_c"+this.Parent.Position+"_sb"+this.Position);
        $(this.SlideButtonDiv).text(this.Position);
        $(this.SlideButtonDiv).bind("click",this.numberButtonClickFn);
        
        // Slide Container
        this.SlideContainerDiv = document.createElement("div");
        $(this.SlideContainerDiv).addClass("spotlight_slide");
        $(this.SlideContainerDiv).attr("id","C"+this.Parent.ComponentId+"_c"+this.Parent.Position+"_s"+this.Position);
        $(this.SlideContainerDiv).css("padding",this.Parent.Margin+"px");
        $(this.SlideContainerDiv).css("padding-bottom",(this.Parent.Margin+( (this.Parent.areSlideButtonsVisible()) ? (20) : (0) ) )+"px");
        
        // Add button and container to ChapterContainer
        // Might have to create a method on Chapter class to handle adding of slide buttons to meet the 10 or 5 max show limit.
        // onClick event handlers for slide buttons / next-previous buttons will have to consider this also
        this.Parent.SlideNumberButtonsDiv.appendChild(this.SlideButtonDiv);
        this.Parent.SlidesContainerDiv.appendChild(this.SlideContainerDiv);
            
        // Add Slide Container Content
        $(this.SlideContainerDiv).html(this.renderInnerHtml());
    }
    
    slide.renderInnerHtml = function ()
    {
        var fontTitle = this.Parent.Parent.getFontByType(2);
        //alert((function(theObj){var retval ="";for(prop in theObj){retval+=prop+":"+theObj[prop]+"\n";}return retval;})(fontTitle));
        var fontBody = this.Parent.Parent.getFontByType(3);
        var fontLink = this.Parent.Parent.getFontByType(4);
            
        var theWidth = 0;
        if (this.Parent.Parent.AutoSize == 0)
            theWidth = this.Parent.Parent.CustomWidth - ( 2 * this.Parent.Margin ) - 2;
        else if(__width)
            theWidth = __width - ( 2 * this.Parent.Margin );
        else
            theWidth = $(this.Parent.ChapterContainerDiv).width() - ( 2 * this.Parent.Margin );
        //alert("theWidth:"+theWidth);

        if(this.ImageWidth > theWidth && theWidth>0)
        {
            this.ImageHeight = ( this.ImageHeight * theWidth ) / this.ImageWidth;
            this.ImageWidth = theWidth;
        }
        //alert(this.ImageWidth+","+this.ImageHeight);
        //	this.ImageHeight=0;
        //this.ImageWidth=0;
        var html = "";
        // Insert Image if type 1 and not bottom
        if(this.Type==1 && this.Alignment!="bottom")
        {
            html += "<div style='";
            if(this.Alignment!="top")
            {
                if(this.Alignment=="left")
                    html += "float:left;margin-right:15px;";
                else if(this.Alignment=="right")
                    html += "float:right;margin-left:15px;";
            }
            else
            {
                html += "text-align:center;margin:auto;";
            }
            html += "'>";
            this.AltText = this.AltText.replace("'", "`");
            html += "<img border=\"0\" id=\"spotlight_slide_picture_c"+this.Parent.Position+"s"+this.Position+"\" src=\"/display_image.aspx?id="+this.ImageId+"\" height='"+this.ImageHeight+"' width='"+this.ImageWidth+"' alt='"+this.AltText+"' "+ ( (this.AltText!="" && (typeof this.AltText != "undefined" && typeof this.AltText != "null"))?("onmouseover=\"Tip('"+this.AltText+"')\""):("") ) + "></div>";
        }

        // insert text if of type 1 or 2
        if(this.Type==1 || this.Type==2)
        {
            html+="<div style='float:left;";
            if(this.Type==1 && (this.Alignment=="left" || this.Alignment=="right") && (theWidth-this.ImageWidth-15 > 20) )
            {
                html+="width:"+(theWidth-this.ImageWidth-20)+"px;";
            }
            else if ( this.Type==1 && (this.Alignment=="left" || this.Alignment=="right") && (theWidth-this.ImageWidth-15 < 20) )
            {
                html+="width:"+theWidth+"px;clear:both;";
            }
            html+="'>";
            // insert title if exists
            if(this.Title != "")
                html += "<div class=\"spotlight_slide_title\" style=\"font-family:"+fontTitle.Name+";font-size:"+fontTitle.Size+";color:#"+fontTitle.Color+";\">"+this.Title+"</div>";

            if(this.Body != "")
                html += "<div class=\"spotlight_slide_body\" style=\"font-family:"+fontBody.Name+";font-size:"+fontBody.Size+";color:#"+fontBody.Color+";\">"+this.Body+"</div>";

            if(this.LinkType>0)
            {
                var target = '_self';
                if(this.LinkType == 1)// external link
                {
                    target = this.LinkRelationId == 1 ? '_blank' : '_self';
                }
                html += "<a class=\"spotlight_slide_link\" style=\"font-family:"+fontLink.Name+";font-size:"+fontLink.Size+";color:#"+fontLink.Color+";\" href=\""+this.LinkUrl+"\" target=\""+target+"\">"+this.LinkText+"</a>"
            }

            html+="</div>";
        }

        // insert image if of type 3 or bottom
        if((this.Type==1 && this.Alignment=="bottom"))
        {
            //html += "<img style=\"margin:auto;display:block;\" src=\"/display_image.aspx?id="+this.ImageId+"\" height='"+this.ImageHeight+"' width='"+this.ImageWidth+"' alt='"+this.AltText+"' "+ ( (this.AltText!="" && (typeof this.AltText != "undefined"))?("onmouseover=\"Tip('"+this.AltText+"')\""):("") ) + ">";
            html += "<div style='text-align:center;'><img border=\"0\" id=\"spotlight_slide_picture_c"+this.Parent.Position+"s"+this.Position+"\" style=\"margin:auto;\" src=\"/display_image.aspx?id="+this.ImageId+"\" height='"+this.ImageHeight+"' width='"+this.ImageWidth+"' alt='"+this.AltText+"' "+ ( (this.AltText!="" && (typeof this.AltText != "undefined" && typeof this.AltText != "null"))?("onmouseover=\"Tip('"+this.AltText+"')\""):("") ) + " /></div>";
            //clear:both;
            
        }
        else if (this.Type==3)
        {
            html += "<div style='text-align:center;'>";
            
            if(this.LinkType>0)
                html+= "<a href=\""+this.LinkUrl+"\" alt=\"\">";
            
            html += "<img border=\"0\" id=\"spotlight_slide_picture_c"+this.Parent.Position+"s"+this.Position+"\" style=\"margin:auto;display:block;";
            if(this.Alignment=="left")
            {
                html+="float:left;";
            }
            else if(this.Alignment=="right")
            {
                html+="float:right;";
            }
            html += "\" src=\"/display_image.aspx?id="+this.ImageId+"\" height='"+this.ImageHeight+"' width='"+this.ImageWidth+"' alt='"+this.AltText+"' "+ ( (this.AltText!="" && (typeof this.AltText != "undefined" && typeof this.AltText != "null"))?("onmouseover=\"Tip('"+this.AltText+"')\""):("") ) + " /></div>";
            
            if(this.LinkType>0)
                html+= "</a>";
        }

        html+="<div style='clear:both;'></div>";

        //html = "<img src=\"/display_image.aspx?id="+this.ImageId+"\">"+this.Title+"<br />"+this.Body;
        return html;
    }
}
