/* these variables have a c8m_ decoration to avoid collisions with other common names */
var c8m_activeImage = false;
var c8m_imageGalleryLeftPos = false;
var c8m_imageGalleryWidth = false;
var c8m_imageGalleryObj = false;
var c8m_maxGalleryXPos = false;
var c8m_slideSpeed = 2;
var c8m_imageGalleryCaptions = new Array();
var c8m_slideSpeed1 = 0;
var c8m_currentSlide = 1;
var c8m_minSlideCount = 1;
var c8m_maxSlideCount = 16;
var c8m_perPageSlides = 4;
var c8m_blockLeft = true;
var c8m_blockRight = false;

/* added function decoration to avoid collisions */
function c8m_startSlide(e){
    if (document.all) 
        e = event;
    var id = this.id;
    var imagescount=0;
    this.getElementsByTagName('IMG')[0].src = '$cms.media("' + this.id + '_over.gif", "designimages").url';
    var anchor_tags=document.getElementById('c8m_theImages').getElementsByTagName('a');
    // the following code added to handle the dynamic image count
    for (i=0; i<anchor_tags.length; i++) {
      if (anchor_tags[i].getAttributeNode('class')!=null && anchor_tags[i].getAttributeNode('class').nodeValue=='clip') {
	imagescount++;
      }
    }
    
    if(imagescount!=0) {
        c8m_maxSlideCount=imagescount+1; // Adding one because the next slide should not be allowed 
                                      // and the current one has to be allowed
    }	
    if (this.id == 'c8m_arrow_left' && c8m_blockLeft == false) {
        c8m_slideSpeed1 = -1;
        c8m_currentSlide = c8m_currentSlide - 1;
        if (c8m_currentSlide != c8m_maxSlideCount - c8m_perPageSlides) {
            c8m_blockRight = false;
        }
        else {
            c8m_blockRight = right;
        }
        if (c8m_currentSlide != c8m_minSlideCount) {
            document.getElementById("imgLeft").src = "http://media.wacotrib.com/designimages/c8m_photo_box_back_greyed.gif";
            document.getElementById("imgLeft").title = "View previous";
            c8m_blockLeft = false;
        }
        else {
            document.getElementById("imgLeft").src = "http://media.wacotrib.com/designimages/c8m_photo_box_back.gif";
            document.getElementById("imgLeft").title = "";
            c8m_blockLeft = true;
        }
        c8m_gallerySlide();
    }
    else 
        if (this.id == 'c8m_arrow_right' && c8m_blockRight == false) {
            c8m_slideSpeed1 = 1;
            c8m_currentSlide = c8m_currentSlide - (-1);
            if (c8m_currentSlide != c8m_maxSlideCount - c8m_perPageSlides) {
                document.getElementById("imgRight").src = "http://media.wacotrib.com/designimages/c8m_photo_box_forward_greyed.gif";
                document.getElementById("imgRight").title = "View more";
                c8m_blockRight = false;
            }
            else {
                document.getElementById("imgRight").src = "http://media.wacotrib.com/designimages/c8m_photo_box_forward.gif";
                document.getElementById("imgRight").title = "";
                c8m_blockRight = true;
            }
            if (c8m_currentSlide != c8m_minSlideCount) {
                c8m_blockLeft = false;
            }
            else {
                c8m_blockLeft = true;
            }
            c8m_gallerySlide();
        }
    
    
}

/* added function decoration to avoid collisions */
function c8m_releaseSlide(){
    var id = this.id;
    this.getElementsByTagName('IMG')[0].src = 'media.wacotrib.com/images/' + this.id + '.gif'; 
    c8m_slideSpeed = 0;
}

/* added function decoration to avoid collisions */
function c8m_gallerySlide(){
    if (c8m_slideSpeed != 0) {//debugger;
        var leftPos = c8m_imageGalleryObj.offsetLeft;
        
        {
            var leftPos1 = leftPos - c8m_slideSpeed1 * (137);
            c8m_imageGalleryObj.style.left = leftPos1 + 'px';
        }
    }

}

/* added function decoration to avoid collisions */
function c8m_showImage(){
    if (c8m_activeImage) {
        c8m_activeImage.style.filter = 'alpha(opacity=50)';
        c8m_activeImage.style.opacity = 0.5;
    }
    this.style.filter = 'alpha(opacity=100)';
    this.style.opacity = 1;
    c8m_activeImage = this;
}

/* added function decoration to avoid collisions */
function c8m_showLeftHighLight(){
    var id = this.id;
    if (c8m_currentSlide > c8m_minSlideCount) {
        this.getElementsByTagName('IMG')[0].src = 'http://media.wacotrib.com/designimages/c8m_photo_box_back_greyed.gif';
        this.getElementsByTagName('IMG')[0].title = 'View previous';
    }
    
}

/* added function decoration to avoid collisions */
function c8m_showRightHighLight(){
    var id = this.id;
    if (c8m_currentSlide < c8m_maxSlideCount - c8m_perPageSlides) {
        this.getElementsByTagName('IMG')[0].src = 'http://media.wacotrib.com/designimages/c8m_photo_box_forward_greyed.gif';
        this.getElementsByTagName('IMG')[0].title = "View more";
    }
    
}

/* added function decoration to avoid collisions */
function c8m_removeLeftHighLight(){
    this.getElementsByTagName('IMG')[0].src = 'http://media.wacotrib.com/designimages/c8m_photo_box_back.gif';
    this.getElementsByTagName('IMG')[0].title ="";
}

/* added function decoration to avoid collisions */
function c8m_removeRightHighLight(){
    this.getElementsByTagName('IMG')[0].src = 'http://media.wacotrib.com/designimages/c8m_photo_box_forward.gif';
    this.getElementsByTagName('IMG')[0].title = "";
}

/* added function decoration to avoid collisions */
function c8m_initSlideShow(){
    document.getElementById('c8m_arrow_left').onclick = c8m_startSlide;
    document.getElementById('c8m_arrow_right').onclick = c8m_startSlide;
    document.getElementById('c8m_arrow_left').onmouseover = c8m_showLeftHighLight;
    document.getElementById('c8m_arrow_right').onmouseover = c8m_showRightHighLight;
    document.getElementById('c8m_arrow_left').onmouseout = c8m_removeLeftHighLight;
    document.getElementById('c8m_arrow_right').onmouseout = c8m_removeRightHighLight;
    
    c8m_imageGalleryObj = document.getElementById('c8m_theImages');
    c8m_imageGalleryLeftPos = c8m_imageGalleryObj.offsetLeft;
    c8m_imageGalleryWidth = document.getElementById('c8m_galleryContainer').offsetWidth - 80;
    c8m_maxGalleryXPos = c8m_imageGalleryObj.offsetLeft;
    minGalleryXPos = c8m_imageGalleryWidth - document.getElementById('slideEnd').offsetLeft;
    var slidec8m_showImages = c8m_imageGalleryObj.getElementsByTagName('IMG');
    
    var divs = c8m_imageGalleryObj.getElementsByTagName('DIV');
    for (var no = 0; no < divs.length; no++) {
        if (divs[no].className == 'imageCaption') 
            c8m_imageGalleryCaptions[c8m_imageGalleryCaptions.length] = divs[no].innerHTML;
    }
}

window.onload = c8m_initSlideShow;
/* end of file */
