// JavaScript Document

var maxnums = '29,28,28,22,29,97';
var maxnum  = 1;

	//==================================================
	// Helpful Sub Functions
	//==================================================
	
	function TwoDigits(num) {
		if (num<10) num = '0' + num;
		return num;
	}

		
	function UpdateImageInfo(num) {
		document.getElementById('imgNum').innerHTML = 'Bild ' + num + '/' + maxnum;
	}
	
	//====================================================
	// INITIALIZATION
	//====================================================
	
	function InitPhotoExchange(code) {
		maxnum = maxnums.split(',')[code.charCodeAt(0)-65];
		UpdateImageInfo(1);
		
	}
	
		
	//====================================================
	// EXCHANGE PHOTO
	//====================================================
	// Routine to change a photo depending on the desired
	// direction (0=downwards, 1=upwards)
	//----------------------------------------------------
	
	function ExchangePhoto(direction) {
	//  fix the path to the main skirt folder here
	var imgpath = '../bilder/skirts/';
	
	//  determine infos about the image source
	var source = document.getElementById('thePhoto').src;
	var cutpos = source.lastIndexOf('/')+1;
	var path   = source.substr(0,cutpos);
	var fname  = source.substr(cutpos);
	
	var fparts = fname.split('.');
	var subfld = fparts[0].split('-')[0] + '/';
	var prefix = fparts[0].split('-')[0] + '-';
	var fnum   = fparts[0].split('-')[1];
	
		// check direction and corresponding limit 
		if (direction==1) { 
			if (fnum < maxnum) fnum++	
			else return;
		}
		else { 
			if (fnum > 1) fnum--; 
			else return;
		}
		
		// load new image and inform about the new number
		document.getElementById('thePhoto').src = imgpath + subfld + prefix + TwoDigits(fnum) + '.jpg';
		UpdateImageInfo(fnum);
	
	}
	
	
	//=======================================
	// CALLER: NEXT PHOTO & PREVIOUS PHOTO
	//=======================================
	
	function NextPhoto() {
		ExchangePhoto(1);
	}
	
	function PrevPhoto() {
		ExchangePhoto(0);
	}
	

