// JScript File

var MS_isNS = (document.layers) ? 1 : 0; 

var MS_isIE = (document.all) ? 1 : 0; 
var MS_isMZ = (!MS_isIE && document.getElementById) ? 1 : 0; 

var MS_exhibitionHtml1, MS_exhibitionHtml2;
var MS_basePath, MS_selectedIndex, MS_thumbPosition, MS_continueScroll, MS_imageCount, MS_totalVisibleWidth, MS_thumbWidth;


function MS_initPage(basePath, imageCount, totalVisibleWidth, thumbWidth) 
{
	MS_initStrings();

    MS_basePath = basePath;
    MS_imageCount = imageCount;
    MS_totalVisibleWidth = totalVisibleWidth;
    MS_thumbWidth = thumbWidth;

	var images = document.getElementsByTagName('img');
	var preloadImages = new Array();
	var imgSrc = new Array();
	var imgSrcOver = new Array();
	
	for (i=0; i<images.length; i++) 
	{	    
	    if (images[i].getAttribute('srcindex')) 
	    {	    
			imgSrc[i] = images[i].getAttribute('src');
			imgSrcOver[i] = images[i].getAttribute('srcover');			
			
			preloadImages[i] = new Image();
	        preloadImages[i].src = imgSrcOver[i];	        
			
			images[i].setAttribute('srcout', imgSrc[i]);			
			
			images[i].onmouseover = MS_thumbnailMouseOver;
			images[i].onmouseout = MS_thumbnailMouseOut;
			images[i].onclick = MS_thumbnailMouseClick;
	    }
	}
	
	MS_selectedIndex = 1;
	MS_thumbPosition = 0;
	
    if (document.getElementById("MS_thumb" + MS_selectedIndex)) 
    {
        var thumb = document.getElementById("MS_thumb" + MS_selectedIndex);
    	thumb.setAttribute('src', thumb.getAttribute('srcover'));
    }
}

function MS_thumbnailMouseOver()
{
	this.setAttribute('src', this.getAttribute('srcover'));

    if (document.getElementById("MS_exhibition_html1")) {
        document.getElementById("MS_exhibition_html1").innerHTML = exhibitionHtml1[parseInt(this.getAttribute('srcindex'))];
    }
}

function MS_thumbnailMouseOut()
{
    if (parseInt(this.getAttribute('srcindex')) != MS_selectedIndex) {    
	    this.setAttribute('src', this.getAttribute('srcout'));
	}
	
    if (document.getElementById("MS_exhibition_html1")) {
        document.getElementById("MS_exhibition_html1").innerHTML = "<p/>";
    }
}

function MS_thumbnailMouseClick()
{
    MS_selectThumbnail(parseInt(this.getAttribute('srcindex')));    
//    return false;
}

function MS_selectThumbnail(index)
{
    if (document.getElementById("MS_thumb" + index)) 
    {
        var thumb = document.getElementById("MS_thumb" + index);
	    thumb.src = thumb.getAttribute('srcover');
    }
    
  //  if (document.getElementById("MS_big_img")) 
  //  {
  //      var bigImg = document.getElementById("MS_big_img");
  //      bigImg.src = MS_basePath + MS_padDigits(index, 2) + '.jpg';
  //  }

    if (index != MS_selectedIndex && document.getElementById("MS_thumb" + MS_selectedIndex)) 
    {
        var selectedThumb = document.getElementById("MS_thumb" + MS_selectedIndex);
	    selectedThumb.src = selectedThumb.getAttribute('srcout');
    }

   // if (document.getElementById("MS_exhibition_html2")) {
   //     document.getElementById("MS_exhibition_html2").innerHTML = exhibitionHtml2[index];
   // }

    MS_selectedIndex = index;
//    MS_scrollToIndex(MS_selectedIndex - 1);
    if (MS_imageCount > 5)
    {
        MS_scrollToIndex(MS_selectedIndex - 1);
    }

}

function MS_scrollLeft() 
{
    if (MS_selectedIndex > 1) 
    {
        MS_selectThumbnail(MS_selectedIndex - 1);
    }
}

function MS_scrollRight()
{
    if (MS_selectedIndex < MS_imageCount) 
    {
        MS_selectThumbnail(MS_selectedIndex + 1);
    }
}

/*
function MS_scrollLeft() 
{
    if (MS_thumbPosition > 0) 
    {
        MS_scrollLayerTo("MS_thumb_strip", 5, 15, MS_thumbWidth, 1);
        MS_thumbPosition -= 1;
    }
}

function MS_scrollRight()
{
    if (MS_thumbPosition < MS_imageCount - MS_totalVisibleWidth / (MS_thumbWidth - 1)) 
    {
        MS_scrollLayerTo("MS_thumb_strip", 5, 15, MS_thumbWidth, -1);
        MS_thumbPosition += 1;
    }
}
*/

function MS_scrollToIndex(index)
{
    var nextPosition; 

    if (index < 2) {
        nextPosition = 0;
    }
    else if (index >= MS_imageCount - 2) {
        nextPosition = MS_imageCount - MS_totalVisibleWidth / (MS_thumbWidth - 1);
    }
    else {
        nextPosition = index - 2;
    }    

    var offset = nextPosition * MS_thumbWidth - MS_thumbPosition * MS_thumbWidth;
    var direction;
    
    if (offset < 0) {
        direction = 1;
        offset = -offset;
    }
    else {
        direction = -1;
    }

    MS_scrollLayerTo("MS_thumb_strip", 10 * Math.abs(nextPosition - MS_thumbPosition), 15, offset, direction );
    
    MS_thumbPosition = nextPosition;
}

function MS_scrollLayerTo(layerName, steps, delay, offset, direction) 
{
    if (MS_getLayer(layerName)) 
    {
        continueScroll = true;
        setTimeout("MS_scrollOneStep(\"" + layerName + "\", " + steps + ", 0, " + delay + ", " + offset + ", " + direction + ")", delay);
    }
}

/*
function MS_scrollOneStep(layerName, pxPerIteration, delay, offset, direction) 
{
    if (continueScroll && offset > 0) 
    {
        MS_moveLayerBy(MS_getLayer(layerName), direction * pxPerIteration, 0);
        offset = offset - pxPerIteration;
        setTimeout("MS_scrollOneStep(\"" + layerName + "\", " + pxPerIteration + ", " + delay + ", " + offset + ", " + direction + ")", delay);
    }
}
*/

function MS_scrollOneStep(layerName, totalSteps, actualStep, delay, offset, direction) 
{
    if (continueScroll && actualStep < totalSteps) 
    {        
        if (actualStep < totalSteps / 2)
        {
            currentX = MS_easeInOut(0, offset, totalSteps, actualStep, 3);
            nextX = MS_easeInOut(0, offset, totalSteps, actualStep + 1, 3);
        }
        {
            currentX = MS_easeInOut(0, offset, totalSteps, actualStep, .7);
            nextX = MS_easeInOut(0, offset, totalSteps, actualStep + 1, .7);
        }
        
        MS_moveLayerBy(MS_getLayer(layerName), direction * (nextX - currentX), 0);
        actualStep += 1;

        setTimeout("MS_scrollOneStep(\"" + layerName + "\", " + totalSteps + ", " + actualStep + ", " + delay + ", " + offset + ", " + direction + ")", delay);
    }
}

function MS_easeInOut(minValue, maxValue, totalSteps, actualStep, powr) 
{
	var delta = maxValue - minValue;
	var stepp = minValue + (Math.pow(((1 / totalSteps) * actualStep), powr) * delta);
	return Math.ceil(stepp);
}

function MS_getLayer(name) 
{ 
    if (MS_isMZ) return document.getElementById(name); 
    else if (MS_isIE) return eval('document.all.' + name); 
    else { 
        var layer; 
        for (var i = 0; i < document.layers.length; i++) { 
            layer = document.layers[i]; if (layer.name == name) return layer; 
        } 
    } 
} 

function MS_getLeft(layer) 
{ 
    if (MS_isNS) return(layer.left); 
    else {
        var left = parseInt(layer.style.left.replace('px', '')); 
        if (isNaN(left)) left = 0;
        return left;
    }
} 

function MS_getTop(layer) 
{ 
    if (MS_isNS) return(layer.top); 
    else {
        var top = parseInt(layer.style.top.replace('px', '')); 
        if (isNaN(top)) top = 0;
        return top;
    }
} 

function MS_moveLayerBy(layer, x, y) 
{ 
    if (MS_isNS) layer.moveBy(x, y); 
    else { 
        layer.style.left = MS_getLeft(layer) + x + 'px'; 
        layer.style.top = MS_getTop(layer) + y + 'px'; 
    } 
} 

function MS_padDigits(n, totalDigits) 
{ 
    n = n.toString(); 
    var pd = ''; 
    if (totalDigits > n.length) 
    { 
        for (i=0; i < (totalDigits-n.length); i++) 
        { 
            pd += '0'; 
        } 
    } 
    return pd + n.toString(); 
} 

