
function initVideoSlideshow(targetID, flvDiv){
    var theVid = $(flvDiv);
    var theBtns = $(targetID).getElement('div[class=btns]').getElements('a');
    var nextBtn = $(targetID).getElement('a[class=nextBtn]');
    var backBtn = $(targetID).getElement('a[class=backBtn]');
    var descholder = new Element('div', {
    'styles': {
        'display': 'block',
        'position':'absolute',
        'width':'244px',
        'left':'17px',
        'top':'200px',
        'fontSize':'10px',
        'color':'#6C2A7F',
        'textAlign':'center'
    },
    'id': 'captionholder'
});

$(descholder).injectAfter('flvDiv');
    nextBtn.vidHolder = theVid;
    nextBtn.vidArray = theBtns;
    nextBtn.onclick = function(){
        var nextNum = Number(this.vidHolder.currentVid)+1;
        if(nextNum >= this.vidArray.length) nextNum = 0;
        this.vidArray[nextNum].onclick();
    }
    
    backBtn.vidHolder = theVid;
    backBtn.vidArray = theBtns;
    backBtn.onclick = function(){
        var nextNum = Number(this.vidHolder.currentVid)-1;
        if(nextNum < 0) nextNum = this.vidArray.length - 1;
        this.vidArray[nextNum].onclick();
    }
   
    
    
    for(var i=0; i<theBtns.length; i++){
        theBtns[i].vidHolder = theVid;
        theBtns[i].nextBtn = nextBtn;
        theBtns[i].id = i;
        theBtns[i].theArray = theBtns;
       
        theBtns[i].onclick = function(){

            
            $$("div#mainContent td.right div").setStyle("display","inline");
            var so = new SWFObject("flvplayer.swf", "mymovie", "244", "165", "8", "#fff");
            so.addParam("wmode", "transparent");
            so.addVariable("theURL", this.getAttribute('src'));
            so.write(flvDiv);
            
            var thecaption = this.getAttribute('alt');
            thecaption = thecaption.replace("@","<br />");
            
            descholder.setHTML(thecaption);
            this.theArray[this.vidHolder.currentVid].style.backgroundPosition = "100px 100px";
            this.theArray[this.vidHolder.currentVid].style.color = "#6c2a7f";
            this.vidHolder.currentVid = this.id;
            this.style.backgroundPosition = "0px 0px";
            this.style.color = "#ffffff";
            $$("div#mainContent td.right div").setStyle("display","block");
         
        }
    }
    
    theVid.currentVid = 0;
    theBtns[0].onclick();

}

function initSlideShow(targetID, speed){
    var theImg = $(targetID).getElement('img[class=holder]');
    var theBtns = $(targetID).getElement('div[class=btns]').getElements('a');
    var theDesc = $(targetID).getElement('div[class=desc]');
    var nextBtn = $(targetID).getElement('a[class=nextBtn]');
    var backBtn = $(targetID).getElement('a[class=backBtn]');
    
    
    nextBtn.imgHolder = theImg;
    nextBtn.descHolder = theDesc;
    nextBtn.imgArray = theBtns;
    nextBtn.onclick = function(){
        var nextNum = Number(this.imgHolder.currentImg)+1;
        if(nextNum >= this.imgArray.length) nextNum = 0;
        this.imgArray[nextNum].onclick();
    }
    
    backBtn.imgHolder = theImg;
    backBtn.descHolder = theDesc;
    backBtn.imgArray = theBtns;
    backBtn.onclick = function(){
        var nextNum = Number(this.imgHolder.currentImg)-1;
        if(nextNum < 0) nextNum = this.imgArray.length - 1;
        this.imgArray[nextNum].onclick();
    }
    
    theDesc.setText(theBtns[0].getAttribute('alt'));
    theImg.setAttribute('src', theBtns[0].getAttribute('src'));
    theImg.currentImg = 0;
    
    for(var i=0; i<theBtns.length; i++){
        theBtns[i].imgHolder = theImg;
        theBtns[i].descHolder = theDesc;
        theBtns[i].nextBtn = nextBtn;
        theBtns[i].id = i;
        theBtns[i].theSpeed = speed;
        theBtns[i].onclick = function(){
            this.descHolder.setText(this.getAttribute('alt'));
            this.imgHolder.setAttribute('src', this.getAttribute('src'));
            this.imgHolder.currentImg = this.id;
            $clear(this.imgHolder.slideNext);
           this.imgHolder.slideNext = this.nextBtn.onclick.delay(this.theSpeed, this.nextBtn);
        }
    }
    nextBtn.onclick.delay(speed, nextBtn);
    
}

function endOfVid(){
    $("flvPlayerTD").getElement('a[class=nextBtn]').onclick();
}
