// Set window- and layer-related variables
var curSlide;
var zIdx;
var but1="http://www.nlr.ru/petersburg/spbpcards/images/b1.gif";
var but2="http://www.nlr.ru/petersburg/spbpcards/images/b2.gif";

// Set browser-determined global variables

var NN  = (document.layers ? true : false);
var dom = (document.getElementById)? true : false;
var IE4 = (!dom && document.all) ? true : false;
var hideName = (NN ? 'hide' : 'hidden');
var showName = (NN ? 'show' : 'visible');
var num0;

if((!dom) && (!NN) && (!IE4)) wbr=false;


//Set image-related variables
var img = new Array();
var layerList = new Array();
var imgPath;
var imgSmPath;

// Set tour-realted variables
var showSpeed;
var tourOn;


// Define a function to generate layers
function genLayer(sName, sLeft, sTop, sWdh, sHgt, sVis, copy) {
	if (NN) {
	document.writeln('<LAYER NAME="' + sName + '" LEFT=' + sLeft + 
     ' TOP=' + sTop + 
	' WIDTH=' + sWdh + ' HEIGHT=' + sHgt + ' VISIBILITY="' + sVis +           '"' + ' z-Index=' + (++zIdx) + '>' + copy + '</LAYER>');
		}
	else {
		document.writeln('<DIV ID="' + sName + 
          '" STYLE="position:absolute; overflow:none; left:' + 
		sLeft + 'px; top:' + sTop + 'px; width:' + sWdh + 
          'px; height:' + sHgt + 'px;' + 
		' visibility:' + sVis + '; z-Index:' + (++zIdx) + '">' + 		copy + '</DIV>'
			);
		}
	}

// Define an object constructor for each slide
function slide(imgStr,v) {
	this.name = imgStr;
	this.structure = 
           "<A HREF=javascript:winOpen('" + imgPath + imgStr + 
           "_1_m.jpg','newwin'," + v + ")>" +
		"<IMG SRC=" + imgSmPath + imgStr + ".jpg" +            
           " border=0></A><BR><BR>" + 
		"<A HREF=javascript:winOpen('" + imgPath + imgStr + 
           "_2_m.jpg','newwin1',true)>" + 
		"See the reverse side</A>";

	// Preload corresponding images while we're at it
	imagePreLoad(imgStr);

	return this;
	}

// Define a function to preload the images
function imagePreLoad(imgStr) {
	// Images for the slides
	img[img.length]	= new Image();
	img[img.length - 1].src =  imgSmPath + imgStr + '.jpg';
	}


// Define a function to hide layers
function hideLayer(name) {
	refLayer(name).visibility = hideName;
	}

// Define a function to reveal layers
function showLayer(name) {
	refLayer(name).visibility = showName;
	}

// Define a central function to reference layers
function refLayer(name) {
	if (NN) { return document.layers[name]; }
	else if(IE4) return eval('document.all.' + name + '.style'); 
    else if(dom) return document.getElementById(name).style;
	}


// Function to change slides if the user navigates with the arrows
function changeSlide(offset) {
	// Hide the existing Layer
	hideLayer('slide' + curSlide);

	// Calculate the next layer index number
	curSlide = (curSlide + offset < 0 ? slideShow.length - 1 : 
		(curSlide + offset == slideShow.length ? 0 : curSlide + offset));

	// Show the desired layer
	showLayer('slide' + curSlide);
	}

// Function to change the slide if user navigates with the menu
function setSlide(ref) {
	if (tourOn) { return; }
	hideLayer('slide' + curSlide);
      window.document.images[num0+curSlide].src=but1;

	curSlide = ref;
	showLayer('slide' + curSlide);
      window.document.images[num0+curSlide].src=but2;
	}

//Automation or stopautomation
function changeAuto(a){
if (a==1) {
hideLayer('automation');
showLayer('stopautomation');
}
else {
hideLayer('stopautomation');
showLayer('automation');
}
}

// Start or stop the automated tour
function autoPilot() {
	// Stop the tour if it is running
	if (tourOn) { 
           
		clearInterval(auto); 
		
		}
	// Otherwise begin the tour from the currently viewed slide
	else {
		auto = setInterval('automate()', showSpeed);
			

		// Show the menu if it is not currrently visible
	
	
		}
	tourOn = !tourOn;
	}

// Automate the slideshow
function automate() {
	// Incite the image rollver
        window.document.images[num0+curSlide].src=but1;

	
	// Incite the slide change
	changeSlide(1);

	// Incite the image rollver
     	window.document.images[num0+curSlide].src=but2;
	}

function winOpen(url,wname,v){
var hw;
if(v) hw="resizable=yes,scrollbars=yes,width=600,height=400";
else hw="resizable=yes,scrollbars=yes,width=380,height=580";
var desc= window.open(url,wname,hw); 
}

