// JavaScript Document
// Find out which parameters are assigned in the URL for use in html-page
// source http://www.netlobo.com/url_query_string_javascript.html
function query(parm){ 
	parm = parm.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
	var regexS = "[\\?,]"+parm+"=([^,#]*)";  
	var regex = new RegExp( regexS );  
	var results = regex.exec( window.location.href ); 
	if( results == null )    return "";// if a requested parameter doesn't exist in the query string then an empty string is returned
		else
	return results[1];}
// -- Decide on the position and size of the albumWindow depending on screen sizes.
// -- lower res (<1024 and <768) should not be a player since lowres/lowres.html takes care of that --
function getScreen() {//--- Determine max width for popup window depending on screen dimensions.
indexwidth=1024;indexheight=760;
albumwidth=1020;albumheight=700;
indexleft=0;indextop=0;
popleft=0;poptop=0;
lowres=0;f11='no'
if (screen.height<=805){f11='yes'} // 
if (screen.width>1900) { // 1920px and above
	indexleft=175;
	indextop=150;
	popleft=220;
	poptop=175;
}
else if (screen.width>1150) { // 1150px and above
	indexleft=60;
	indextop=40;
	popleft=75;
	poptop=25;
}
else if (screen.width>=1024) { // 1024px and above
//	indexwidth=1000;
	indexheight=700;
//	albumwidth=1020;
}
else {
	lowres=1;
	albumwidth=710;
	albumheight=518;
}
} // closing curly for function
//---- next set attribues for opening album windows--------------------------------
var attribs="toolbar=0,scrollbars=0,status=0,menubar=0,resizable=1";
//---- MM_behaviour functions below --------------------------------
if (root!='../') {var root='';} // calling files not in root need path to root set
//alert('control.js -'+root+'-');
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_findObj(n, d) { //v4.01 Is used by the other functions --------------
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=root+a[i+2];} // 'root' is added to accomodate calls not from root
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
//---------------------------------------------------------------------------------
function MM_showHideLayers() { //v9.0 Needs previous function
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function MM_changeProp(objId,x,theProp,theValue) { //v9.0
  var obj = null; with (document){ if (getElementById)
  obj = getElementById(objId); }
  if (obj){
    if (theValue == true || theValue == false)
      eval("obj.style."+theProp+"="+theValue);
    else eval("obj.style."+theProp+"='"+theValue+"'");
  }
}
// ---- Next: liste to keyboard inputs and respond ------------
document.onkeyup = MonitorKeyUp;
document.onkeydown = MonitorKeyDn;
var ctrl='no'; var shft='no'; var type; var lang;
function MonitorKeyUp(e)
{
	if (!e) e=window.event;
	var cell = document.getElementById("keymonitor");
	cell.innerHTML = executeKey(e);
}
function MonitorKeyDn(e)
{
	if (!e) e=window.event;
	var cell = document.getElementById("keymonitor");
	cell.innerHTML = controlKey(e);
}
function setRow(r){dsGalleries.setCurrentRow(r);}
function setPhoto(p){dsPhotos.setCurrentRow(p);}

function setNewInterval(newValue) {
	gSlideShowInterval=newValue*1000;StartSlideShow(); // addition to original
	radioObj = document.forms['interval'].elements['time']; // modification of original
//	if(!radioObj)return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
function controlKey(e)
{
		document.getElementById('thumbContainer').focus()
//		document.getElementById('thumbContainer')
	var code; 
	if ((e.charCode) && (e.keyCode==0))
	{
		code = e.charCode;
	} else {
		code = e.keyCode;
	}
	if (code==16) {//shift down
		shft='yes';// alert(shft);
		document.getElementById('thumbContainer').focus()
//		document.getElementById('thumbContainer')
	} 
	if (code==17) {//ctrl down
		ctrl='yes';// alert(ctrl);
	} 
}
function executeKey(e)
{
		document.getElementById('thumbContainer').focus()
//		document.getElementById('thumbContainer')
	var code; 
	if ((e.charCode) && (e.keyCode==0))
	{
		code = e.charCode;
	} else {
		code = e.keyCode;
	}
	if (code==13) {//Enter
		if (type!='album') StartSlideShow();
	} 
	if (code==16) {//shift-up
		shft='no';// need to reset shift to 'no'
	} 
	if (code==17) {//ctrl-up
		ctrl='no';// need to reset ctrl to 'no'
	} 
	if (code==19) {//Pause
		if (type!='album') {if (gSlideShowOn) {StopSlideShow();}
		else {StartSlideShow();}}
	} 
	if (code==33 && ctrl=='no') {//Page Up
		if (prevAlbum>=0 && prevAlbum<rowcount-2){setRow(prevAlbum);}
	} 
	if (code==34 && ctrl=='no') {//Page Down
		if (nextAlbum<rowcount){setRow(nextAlbum);}
		else {setRow(0);}
	} 
	if (code==35 && ctrl=='no') {//End
		setPhoto(photocount-1); 
		if (type!='album') {ShowCurrentImage();StopSlideShow();}
	} 
	if (code==36 && ctrl=='no') {//Home
		lastImg='no';setPhoto(0);
		if (type!='album') {ShowCurrentImage();StopSlideShow();}
	} 
	if ((code==33 || code==36) && ctrl=='yes') {//ctrlHome or ctrlPgUp
		setRow(0);lastImg='no';setPhoto(0);
		if (type!='album') {ShowCurrentImage();StopSlideShow();}
	} 
	if ((code==34 || code==35) && ctrl=='yes') {//ctrl+End or ctrlPgDn
		setPhoto(0);setRow(rowcount-1);
	} 
	if ((code==9 || code==32) && shft=='no') {//Tab or Spacebar
		code=39;// which is arrow-right
	} 
	if ((code==9 || code==32) && shft=='yes') {//Tab or Spacebar, Shift down
		code=37;// which is arrow-left
	} 
	if (code==37 || code==38) {//Arrow left
		if (type=='album' && curPhoto!=0) {setPhoto(prevPhoto);}
		else if (type=='album' && curPhoto==0) {setPhoto(photocount-1);}
		else {StopSlideShow(); AdvanceToNextImage(true);}
	} 
//	if (code==38) {//Arrow Up
//		if (type!='album') {
//		AdvanceToNextImage(true);if (!gSlideShowOn) StartSlideShow();
//		}
//	} 
	if (code==39 || code==40) {//arrow right
		if (type=='album' && nextPhoto < photocount) {setPhoto(nextPhoto);}
		else if (type=='album' && nextPhoto==photocount) {setPhoto(0);}
		else {AdvanceToNextImage(); if (gSlideShowOn) StopSlideShow(); }
	} 
//	if (code==40) {//Arrow Down
//		if (type!='album') {
//		AdvanceToNextImage(); if (!gSlideShowOn) StartSlideShow();
//		}
//	}
	if (code==49 || code==97) {//1
		if (type!='album') setNewInterval(1);
	} 
	if (code==50 || code==98) {//2
		if (type!='album') setNewInterval(2);
	} 
	if (code==51 || code==99) {//3
		if (type!='album') setNewInterval(3);
	} 
	if (code==52 || code==100) {//4
		if (type!='album') setNewInterval(4);
	} 
	if (code==53 || code==101) {//5
		if (type!='album') setNewInterval(5);
	} 
	if (code==72 || code==191) {//h || ?
		if (type=='album'){MM_openBrWindow('required/help/album_h'+lang+'.html?def=0','','left=100,top=40,width=447,height=575,status=no,scrollbars=no,resizable=yes');}
		if (type=='sshow'||type=='cont'){MM_openBrWindow('required/help/album_h'+lang+'.html?def=1','','left=100,top=40,width=447,height=575,status=no,scrollbars=no,resizable=yes');}
	} 
	if (code==107) {//+
		if (type!='album') {
		if (gSlideShowInterval<5000) {
		gSlideShowInterval=gSlideShowInterval+1000;
		setNewInterval(gSlideShowInterval/1000);}}
	} 
	if (code==109) {//-
		if (type!='album') {
		if (gSlideShowInterval>1000) {
		gSlideShowInterval=gSlideShowInterval-1000;
		setNewInterval(gSlideShowInterval/1000);}}
	} 
	if (code==116) {//F5
//		alert ('F5 was pressed');
		if (type!='album') setNewInterval(3);
	} 
	if (code==122) {// F11
		MM_changeProp('f11','','visibility','hidden');
		MM_changeProp('f11en','','visibility','hidden');
	} 
	if (code==65) {//a
		//alert (photocount-1);
		document.getElementById('album').click()
	} 
	if (code==67) {//c
		//alert (photocount-1);
		document.getElementById('cont').click()
	} 
	if (code==83) {//s
		//alert (photocount-1);
		document.getElementById('sshow').click()
	} 
	if (code==27 || code==88) {//Escape or x
		self.close ()
	} 
	if (code==115) {//F4
		//alert (photocount-1);
//		document.getElementById('sshow').click()
	self.close ()
	} 
}

