/* These following links need to be included in the calling code.
   <script src="/scripts/jquery.js"></script>
   <script src="/scripts/jqueryui.js"></script>   */ 

/* Next strategy to replace the code below: 
       http://jonraasch.com/blog/a-simple-jquery-slideshow */

function slideManager(displayScriptUrl, imageDirUrl) {  
    /* displayScriptUrl is the address of the XML file that identifies slides and click links from the web root.
       imageDirUrl is the address of the image directory from the web root.  Ending slash is NOT required.
       An example display script file is below
       This is the line to be included in the calling program    
                  <div id="slideShow">&nbsp;</div>          */
    $.ajax({
        url: displayScriptUrl,   /* '/images/displayscript.xml', */
        type: 'get',
        dataType: 'xml',
        success: function(xmlDoc, textStatus) {
                     var imgDivs = ''
                     var elemColl = xmlDoc.getElementsByTagName("Scene") 
                     var i
                     var inclLink = true  
                     for (i=0;i<elemColl.length;i++) {
                         imgDivs += i == 0 ? '<div class="active">\r\n' : '<div>\r\n'; 
                         if (elemColl[i].getElementsByTagName('Link').length > 0 &&
                                           elemColl[i].getElementsByTagName('Link')[0].hasChildNodes()) {
                             imgDivs += '<a href="' + 
                                        elemColl[i].getElementsByTagName('Link')[0].childNodes[0].nodeValue + 
                                        '" target="blank">\r\n';
                             inclLink = true;    
                         } else {
                             inclLink = false;
                         }
                         
                         /* imgDivs += '<img src="/images/' +  */
                         imgDivs += '<img style="border: none;" src="' + imageDirUrl + '/' +
                                    elemColl[i].getElementsByTagName('File')[0].childNodes[0].nodeValue + 
                                    '" />\r\n';
                         if (inclLink === true) {
                             imgDivs += '</a>\r\n';
                         }
                         /* Could also insert a caption here to appear in the div and below the image */
                         imgDivs += '</div>\r\n'; 
                     } 
                     /*  alert(imgDivs);          */ 
                     $('#slideShow').html(imgDivs);
                     setInterval("slideSwitch()", 4000);
                 }
    }) 
}

function slideSwitch() {
    var $active = $('#slideShow DIV.active');
    
    if ( $active.length == 0 ) {
        $active = $('#slideShow DIV:last');
    }
    
    // use this to pull the divs in the order they appear in the markup
    var $next = $active.next().length ? $active.next() : $('#slideShow DIV:first');
    
    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );
    
    $active.addClass('last-active');
    
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

/*
<?xml version="1.0" encoding="utf-8"?>
<DisplayScript>
        <Scene>
        <File>tahc_rh1.png</File>
                <Link></Link>
                <Note></Note>
        </Scene>
        <Scene>
        <File>tahc_hcin2.png</File>
                <Link></Link>
                <Note></Note>
        </Scene>
        <Scene>
        <File>2011survey.png</File>
                <Link>http://hcin.securestreamingstore.com/product_info.php?cPath=$
                <Note></Note>
        </Scene>
        <Scene>
        <File>ct_qt_1.png</File>
                <Link></Link>
                <Note></Note>
        </Scene>
        <Scene>
        <File>ct_qt_2.png</File>
                <Link></Link>
                <Note></Note>
        </Scene>

        <Scene>
        <File>RachelHammonMonitor3.jpg</File>
        <Link></Link>
        <Note>Starting slide: screen shot from Rachel Hammon presentation on a ske$
    </Scene>
    <Instruction>Filespecs: 110hx190w. JPG,PNG,GIF; white BG. Place files in prefe$
</DisplayScript>
*/

