﻿/*************************************************************************************************/
/* Programming by Dennis Korobov. All rights reserved. Contact: dennis.korobov@yahoo.com         */
/*************************************************************************************************/
var album = new Array();
var pathSmall = "size=small"; //"./Photos/Small";
var pathMedium = "size=medium"; //"./Photos/Medium";
var pathBig = "size=big"; //"./Photos/Big";
var pathDisplay = pathMedium;
var currentPosition = 0;
var totalPhotos = album.length;
var smallExtens = "jpg";
var mediumExtens = "jpg";
var bigExtens = "jpg";
var totalShow = 0;
var smallDisplaysIds = new Array();
var smallCurrentPosition = 0;
var description = null;
var displayPhoto = null;
var slideTimeout = null;
var timeout = 3;  // В секундах
var ie = navigator.appName.indexOf("Microsoft") != -1 ? true : false;	
				
function initAlbum(displayId, descId, smallIdPrefix, smallTotalShow) {
	var tempPosition = currentPosition;
	for (var i = 0; i < smallTotalShow; i++) {
	    var nbr = album[tempPosition].substring(album[tempPosition].indexOf('_') + 1, album[tempPosition].lastIndexOf('.'));
	    var rf = album[tempPosition].substring(0, album[tempPosition].lastIndexOf('_'));
	    var re = new RegExp("^0+");
	    nbr = nbr.replace(re, "");
        
	    smallDisplaysIds[i] = document.getElementById(smallIdPrefix + "_" + ((i + 1) < 10 ? "0" + (i + 1) : (i + 1)));
	    if (album[tempPosition] == "default.jpg") {
	        smallDisplaysIds[i] = "http://www.dsmbelgium.com/ShowFoto.aspx?file=default.jpg" + "&" + pathSmall;
	    } else {
	        smallDisplaysIds[i].src = "http://www.dsmbelgium.com/ShowFoto.aspx?id=" + rf + "&size=small&nr=" + nbr; // + "." + smallExtens;
		    smallDisplaysIds[i].style.borderColor = "#ffffff";
		}
		if (++tempPosition >= album.length) tempPosition = 0;
	}
	
	if (smallDisplaysIds[smallCurrentPosition].style != null)
	    smallDisplaysIds[smallCurrentPosition].style.borderColor = "#cc0000";
	displayPhoto = document.getElementById(displayId);
	if (ie) {
		displayPhoto.filters[0].apply();
	}

    var nbr = album[currentPosition].substring(album[currentPosition].indexOf('_') + 1, album[currentPosition].lastIndexOf('.'));
    var rf = album[currentPosition].substring(0, album[currentPosition].lastIndexOf('_'));
    var re = new RegExp("^0+");
    nbr = nbr.replace(re, "");

    displayPhoto.src = "http://www.dsmbelgium.com/ShowFoto.aspx?id=" + rf + "&size=medium&nr=" + nbr; //pathDisplay + "/" + album[currentPosition];// + "." + mediumExtens;
	if (ie) {
		displayPhoto.filters[0].play();
	}
	description = document.getElementById(descId);
	description.innerHTML = (currentPosition + 1) + " / " + album.length;
	totalShow = smallTotalShow;
}
				
function goForward() {
	if (++currentPosition >= album.length) currentPosition = 0;
	var tempPosition = currentPosition;
	if (++smallCurrentPosition >= totalShow) {
		smallCurrentPosition = 0;
		for (var i = 0; i < totalShow; i++) {
		    var nbr = album[tempPosition].substring(album[tempPosition].indexOf('_') + 1, album[tempPosition].lastIndexOf('.'));
		    var rf = album[tempPosition].substring(0, album[tempPosition].lastIndexOf('_'));
		    var re = new RegExp("^0+");
		    nbr = nbr.replace(re, "");
		    smallDisplaysIds[i].src = "http://www.dsmbelgium.com/ShowFoto.aspx?id=" + rf + "&size=small&nr=" + nbr; // + "/" + album[tempPosition];// + "." + smallExtens;
			smallDisplaysIds[i].style.borderColor = "#ffffff";
			if (++tempPosition >= album.length) tempPosition = 0;
		}
	} else {
		smallDisplaysIds[smallCurrentPosition - 1].style.borderColor = "#ffffff";
	}
	smallDisplaysIds[smallCurrentPosition].style.borderColor = "#cc0000";
	if (ie) {
		displayPhoto.filters[0].apply();
    }
    var nbr = album[currentPosition].substring(album[currentPosition].indexOf('_') + 1, album[currentPosition].lastIndexOf('.'));
    var rf = album[currentPosition].substring(0, album[currentPosition].lastIndexOf('_'));
    var re = new RegExp("^0+");
    nbr = nbr.replace(re, "");
    displayPhoto.src = "http://www.dsmbelgium.com/ShowFoto.aspx?id=" + rf + "&size=medium&nr=" + nbr;
	if (ie) {
		displayPhoto.filters[0].play();
	}
		description.innerHTML = (currentPosition + 1) + " / " + album.length;	
}
			
function goBackward() {
	if (--currentPosition < 0) currentPosition = album.length - 1;
	var tempPosition = currentPosition;
	if (--smallCurrentPosition < 0) {
		smallCurrentPosition = smallDisplaysIds.length - 1;
		for (var i = totalShow - 1; i >= 0; i--) {
		    var nbr = album[tempPosition].substring(album[tempPosition].indexOf('_') + 1, album[tempPosition].lastIndexOf('.'));
		    var rf = album[tempPosition].substring(0, album[tempPosition].lastIndexOf('_'));
		    var re = new RegExp("^0+");
		    nbr = nbr.replace(re, "");
		    smallDisplaysIds[i].src = "http://www.dsmbelgium.com/ShowFoto.aspx?id=" + rf + "&size=small&nr=" + nbr; // + "/" + album[tempPosition--];// + "." + smallExtens;
			smallDisplaysIds[i].style.borderColor = "#ffffff";
			tempPosition--;
			if (tempPosition < 0 ) tempPosition = smallDisplaysIds.length - 1;
		}
    } else {
	    smallDisplaysIds[smallCurrentPosition + 1].style.borderColor = "#ffffff";
	}
	smallDisplaysIds[smallCurrentPosition].style.borderColor = "#cc0000";
	if (ie) {
		displayPhoto.filters[0].apply();
    }
    var nbr = album[currentPosition].substring(album[currentPosition].indexOf('_') + 1, album[currentPosition].lastIndexOf('.'));
    var rf = album[currentPosition].substring(0, album[currentPosition].lastIndexOf('_'));
    var re = new RegExp("^0+");
    nbr = nbr.replace(re, "");
    displayPhoto.src = "http://www.dsmbelgium.com/ShowFoto.aspx?id=" + rf + "&size=medium&nr=" + nbr; //pathDisplay + "/" + album[currentPosition];// + "." + mediumExtens;
	if (ie) {
	   	displayPhoto.filters[0].play();
	}
	description.innerHTML = (currentPosition + 1) + " / " + album.length;
}
				
function goSelect(numberOfSmallDisplay) {
	if ((numberOfSmallDisplay > totalShow) || (numberOfSmallDisplay <= 0))
		return;
	numberOfSmallDisplay--;
	for (var i=0; i < totalShow; i++) {
		smallDisplaysIds[i].style.borderColor = "#ffffff";
	}
	smallDisplaysIds[numberOfSmallDisplay].style.borderColor = "#cc0000";
	if (smallCurrentPosition < numberOfSmallDisplay) {
		currentPosition += (numberOfSmallDisplay -	smallCurrentPosition);
		smallCurrentPosition += (numberOfSmallDisplay -	smallCurrentPosition)
	} else if (smallCurrentPosition > numberOfSmallDisplay) {
		currentPosition -= (smallCurrentPosition - numberOfSmallDisplay);
		smallCurrentPosition -= (smallCurrentPosition - numberOfSmallDisplay);
	}
	if (currentPosition > (album.length - 1))
		currentPosition -= album.length;
	if (currentPosition < 0)
		currentPosition = album.length - 1;
	description.innerHTML = (currentPosition + 1) + " / " + album.length;
	if (ie) {
		displayPhoto.filters[0].apply();
    }
    var nbr = album[currentPosition].substring(album[currentPosition].indexOf('_') + 1, album[currentPosition].lastIndexOf('.'));
    var rf = album[currentPosition].substring(0, album[currentPosition].lastIndexOf('_'));
    var re = new RegExp("^0+");
    nbr = nbr.replace(re, "");
    displayPhoto.src = "http://www.dsmbelgium.com/ShowFoto.aspx?id=" + rf + "&size=medium&nr=" + nbr; //pathDisplay + "/" + album[currentPosition];// + "." + mediumExtens;
	if (ie) {
		displayPhoto.filters[0].play();
	}
}
				
function goSlideShow() {
	var elementSlide = document.getElementById("slideshow");
	if ((slideTimeout == null) && (elementSlide.checked))
	{
		slideTimeout = window.setInterval("goForward()", timeout * 1000);
	} else if ((slideTimeout != null) && (!elementSlide.checked)) {
		window.clearInterval(slideTimeout);
		slideTimeout = null;
	}
}
				
function changeSize() {
	if (displayPhoto.width < 640) {
		pathDisplay = pathBig;
		displayPhoto.width = 640;
		displayPhoto.height = 480;
	} else {
		pathDisplay = pathMedium;
		displayPhoto.width = 450;
		displayPhoto.height = 338;
	}
displayPhoto.src = "http://www.dsmbelgium.com/ShowFoto.aspx?file=" + album[currentPosition] + "&size=medium"; //pathDisplay + "/" + album[currentPosition];// + "." + mediumExtens;
}
				
function goSlideShowWithChangeCheck() {
	var elementSlide = document.getElementById("slideshow");
	elementSlide.checked = !elementSlide.checked;
	goSlideShow();
}
