

doclay = (document.layers)? true : false
docall = (document.all)? true : false
docget = (document.getElementById)? true : false
ss = new Object();
// Set the slideshow speed (in milliseconds)
var SlideShowSpeed = 3000;


doclay = (document.layers)? true : false
docall = (document.all)? true : false
docget = (document.getElementById)? true : false
ss = new Object();
// Set the slideshow speed (in milliseconds)
var SlideShowSpeed = 3000;

// Set the duration of crossfade (in seconds)
var CrossFadeDuration = 3;

var currentImg;
var total;

baseCt = 0

imageNavigation = new Array()
var preLoad = new Array();

var tss;
var iss;

thisImg = 0;
lastImg = 0;
thisLanguage = "English";
caption = "";

start = 1;

function resume(){
    lastImg = thisImg;
    thisImg = thisImg;
    
    start = 1;
    runSlideShowParent();
    document.getElementById("ssControl").innerHTML = caption;
    document.getElementById("caption").innerHTML = gallery[ss.thisGallery].slide[thisImg].caption;
//    document.getElementById("debuginfo").innerHTML += "thisImg"+thisImg+"lastImg"+lastImg;
}

function launchImage(URL,Width,Height){
    var Scrollbars = "yes";
    if(screen.height<Height){
        var Height = (screen.height-200);
        var Scrollbars = "yes";
    }
    
    if(screen.width<Width){
        var Width = (screen.width-200);
        var Scrollbars = "yes";
    } else {
        var Width = Width;
    }
    var Left = (screen.width-Width)/2;
    var Top = (screen.height-Height)/2;
    var params = ('toolbar=no,scrollbars=' + Scrollbars + ',resizable=yes,left=' + Left +',top=' + Top +',width=' + Width + ',height=' + Height);
    
    Pop = window.open(URL, "LaunchImage", params);
    Pop.focus();
}

function over (i)  {
    //document.getElementById("thumb"+i).style.border = "1px solid white";
    
    
;
   // document.getElementById("caption").innerHTML = gallery[ss.thisGallery].slide[i].caption;
    //lastImg=thisImg;
    //thisImg=i;
    document.images.slideshow.src = preLoad[i].src;
    start = 0;
    document.getElementById("ssControl").innerHTML = '<span class="slideshownav" <a href="Javascript:resume();">Play Slide Show</a>';
}

function notOver (i)  {
/*
    document.getElementById("thumb"+i).style.borderWidth = "1px";
    document.getElementById("thumb"+thisImg).style.borderWidth = "1px";
document.getElementById("thumb"+i).style.borderStyle = "none";
    document.getElementById("thumb"+thisImg).style.borderStyle = "none";
document.getElementById("thumb"+i).style.borderColor = "none";
    document.getElementById("thumb"+thisImg).style.borderColor = "none";
  */  
    
    
    //start=1;
}

function displaySlideShow(thisGallery, language){

   
    
    ss.thisGallery = thisGallery;
    imgCt = gallery[thisGallery].slide.length;
    var cols = imgCt;
    var columns = gallery[thisGallery].columns;
    var thumbWidth = gallery[thisGallery].thumbWidth;
    var thumbHeight = gallery[thisGallery].thumbHeight;
    var largeWidth = gallery[thisGallery].largeWidth;
    var largeHeight = parseInt(gallery[thisGallery].largeHeight) + 10;
    var count = 0;
    
    square = 4;//Math.round(Math.sqrt(imgCt));
    if(cols>square){
        cols=square;
        rows = parseInt(imgCt/square);
    }
    //
    slideGallery = '';
  //  slideGallery +='<div id="debuginfo" ></div>';
    slideGallery += '<table id="thumbs" align="center" cellpadding="0" cellspacing="0">'; 
    x =	gallery[thisGallery].slide.length;
        slideGallery += '<tr><td valign="top">';
        slideGallery += '<table cellpadding="0" cellspacing="0">';
    slideGallery += '<tr>';
   
    for(i in gallery[thisGallery].slide){
        j = i+1;
        //alert(gallery[thisGallery].path+slidePath+gallery[thisGallery].slide[i].file);
        onClickStr = '';
	if(typeof(gallery[thisGallery].slide[i].thumbFile) != 'undefined'){
		if (gallery[thisGallery].slide[i].launchFile) {
			
		    onClickStr = 'launchImage(\''+gallery[thisGallery].path+gallery[thisGallery].slide[i].launchFile+'\',1024,768);';        
		}
		slideGallery +='<td style="margin:0px; " align="center" id="thumb'+i+'" onmouseover="over('+i+');" onmouseout="notOver('+i+')" onClick="'+onClickStr+'">\n';
		slideGallery +='<img src="'+gallery[thisGallery].path+gallery[thisGallery].slide[i].thumbFile+'">\n';
		slideGallery +='</td>\n';
		
		if(count == columns - 1){
			slideGallery +='</tr><tr>';
		    count = 0;
		} else {
		    count++;
		}
	}
    }
    
    slideGallery +='</table>';
        slideGallery += '<table width="100%" cellpadding="0" cellspacing="0"><tr><td align="center" class="slideshownav"><a href="Javascript:lastNext(\'previous\','+x+');">previous</a> | <a href="Javascript:lastNext(\'next\','+x+');">next</a></td></tr>';
	slideGallery += '<tr><td  id="ssControl" align="center" class="help">'+caption+'<td></tr></table></td>';
	slideGallery += '<td valign="top" style="" width="'+largeWidth+'" align="center">\n';
	slideGallery += '<img src="'+gallery[thisGallery].path+gallery[thisGallery].slide[0].displayFile+'" name="slideshow" id="slideshow" style="border:1px solid #fff;"></td><td></td></tr>\n';
    		
   
   // slideGallery +='</td><td align="center" width="'+largeWidth+'" id="caption" class="caption" height="48"><strong>'+gallery[thisGallery].slide[0].caption+'</strong></td></tr>\n';
   // slideGallery +='<tr><td><td align="center"><img src="media/graphics/spacer.gif" width="320" height="1"><td></tr>';
    


    slideGallery +='</table><br />';
    
    slideGallery = slideGallery.replace("_media/", "");

    document.getElementById("gallery").innerHTML = slideGallery;
    //document.getElementById("htmlDisplay").innerHTML = slideGallery;
    for (iss = 0; iss < imgCt; iss++){
        preLoad[iss] = new Image();
        //alert(iss);
        preLoad[iss].src = ''+gallery[thisGallery].path+gallery[thisGallery].slide[iss].displayFile;
    }
}


//this function is run first so that there is a delay on the first image
//otherwise the slideshow jumps to the second image immediately
//timer is faster for this than the loop
function runSlideShowParent(){
    tss = setTimeout('runSlideShow()', 3000);
}
function lastNext(dir,x){
// document.getElementById("debuginfo").innerHTML += "thisImg"+thisImg+"lastImg"+lastImg;
    start=0;
    
        
    lastImg = thisImg;

    if(dir == "previous"){
        if(thisImg == 0){
            thisImg = x-1;
        } else{
            thisImg = thisImg-1;
        }
    } else if(dir == "next"){
        if(thisImg == x-1){
            thisImg = 0;
        } else{
           thisImg =thisImg+1;
        }
    }
   // alert(thisImg);
/*
    document.getElementById("thumb"+thisImg).style.border = "1px solid white";
    document.getElementById("thumb"+lastImg).style.border = "1px";
*/
    setSlide()

}


function setSlide(){
    if (docall){
        document.images.slideshow.style.filter="blendTrans(duration=2)";
        document.images.slideshow.style.filter="blendTrans(duration=CrossFadeDuration)";
        document.images.slideshow.filters.blendTrans.Apply();
    }
   // document.getElementById("caption").innerHTML = gallery[ss.thisGallery].slide[thisImg].caption;
    document.images.slideshow.src = preLoad[thisImg].src;
    if(typeof(document.getElementById("thumb"+thisImg)) == "undefined"){
       // alert("undefined");
    }
/*
    document.getElementById("thumb"+thisImg).style.border = "1px solid white";
    document.getElementById("thumb"+lastImg).style.border = "1px";
  */  
}
// style:border: 1px"
//this is the automatic slideshow
function runSlideShow(){
    
    if ( start == 1 ){
    
        //counter is at beginning so that if user interrupts the slideshow with the PREVIOUS NEXT
        //then the slideshow won't jump ahead two images instead of just one
        
        lastImg = thisImg;
        if (thisImg >= imgCt-1){
            thisImg=0;
        } else {
            thisImg = thisImg + 1;
        }
        
        navigation = imageNavigation[thisImg];
        
        setSlide();
        
        if (docall) 
            document.images.slideshow.filters.blendTrans.Play();
        
        tss = setTimeout('runSlideShow()', SlideShowSpeed);
    }
}


//this is the user controlled slideshow
function layerWrite(id,text) {

    image = gallery[thisGallery].slide[thisImg].displayFile;
    navigation = imageNavigation[thisImg]
    
    if (thisImg > imgCt) {
        thisImg = 0
        navigation = imageNavigation[thisImg]
    }
    
    if (thisImg < baseCt) {
        thisImg = 5
        navigation = imageNavigation[thisImg]
    }
    
    currentImg = thisImg + 1
    total = imgCt + 1
    
}

// Set the duration of crossfade (in seconds)
var CrossFadeDuration = 3;

var currentImg;
var total;

baseCt = 0

imageNavigation = new Array()
var preLoad = new Array();

var tss;
var iss;

thisImg = 0;
lastImg = 0;
thisLanguage = "English";
caption = "";

start = 1;

function resume(){
    lastImg = thisImg;
    thisImg = thisImg;
    
    start = 1;
    runSlideShowParent();
    document.getElementById("ssControl").innerHTML = caption;
    document.getElementById("caption").innerHTML = gallery[ss.thisGallery].slide[thisImg].caption;
//    document.getElementById("debuginfo").innerHTML += "thisImg"+thisImg+"lastImg"+lastImg;
}

