
function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
  	elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
  	elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
  	elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
  	vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

var deleteo = new Image();
deleteo.src = '/images/usb/deleteo.gif';
var deleten = new Image();
deleten.src = '/images/usb/deleten.gif';
var moveupo = new Image();
moveupo.src = '/images/usb/moveupo.gif';
var moveupn = new Image();
moveupn.src = '/images/usb/moveupn.gif';
var movedowno = new Image();
movedowno.src = '/images/usb/movedowno.gif';
var movedownn = new Image();
movedownn.src = '/images/usb/movedownn.gif';
var rotlefto = new Image();
rotlefto.src = '/images/usb/rotlefto.gif';
var rotleftn = new Image();
rotleftn.src = '/images/usb/rotleftn.gif';
var rotrighto = new Image();
rotrighto.src = '/images/usb/rotrighto.gif';
var rotrightn = new Image();
rotrightn.src = '/images/usb/rotrightn.gif';
var mailo = new Image();
mailo.src = '/images/usb/mailo.gif';
var mailn = new Image();
mailn.src = '/images/usb/mailn.gif';
var blanco = new Image();
blanco.src = '/images/usb/noremove.gif';

function toggleEditImage(id,action) {
	if (action == 'delete') {
		document[id].src = deleteo.src;
	}
	else if (action == 'down') {
		document[id].src = movedowno.src;
	}
	else if (action == 'up') {
		document[id].src = moveupo.src;
	}
	else if (action == 'left') {
		document[id].src = rotlefto.src;
	}
	else if (action == 'right') {
		document[id].src = rotrighto.src;
	}
	else if (action == 'mail') {
		document[id].src = mailo.src;
	}
	else if (action == 'nodelete') {
		document[id].src = deleten.src;
	}
	else if (action == 'nodown') {
		document[id].src = movedownn.src;
	}
	else if (action == 'noup') {
		document[id].src = moveupn.src;
	}
	else if (action == 'nomail') {
		document[id].src = mailn.src;
	}
	else if (action == 'noleft') {
		document[id].src = rotleftn.src;
	}
	else if (action == 'noright') {
		document[id].src = rotrightn.src;
	}
	else {
		document[id].src = blanco.src;
	}
}

function emailPhoto(folderid,picid) {
	kill();
	document.albumform.folderid.value=folderid;
	document.albumform.photoid.value=picid;
	document.albumform.action.value='mailphoto';
	document.albumform.submit();
}

function deletePhoto(folderid,picid) {
	kill();
	if (confirm('Removing photo, are you sure?')) {
		document.albumform.folderid.value=folderid;
		document.albumform.photoid.value=picid;
		document.albumform.action.value='deletephoto';
		document.albumform.submit();
	}
}

function highlightPhoto(folderid,picid) {
	kill();
	document.albumform.folderid.value=folderid;
	document.albumform.photoid.value=picid;
	document.albumform.action.value='highlightphoto';
	document.albumform.submit();
}

function moveDown(folderid,picid,orderid) {
	kill();
	var temp=orderid+1;
	//alert('move to '+temp);
	document.albumform.folderid.value=folderid;
	document.albumform.photoid.value=picid;
	document.albumform.newphotoid.value=temp;
	document.albumform.action.value='movephoto';
	document.albumform.submit();
}

function moveUp(folderid,picid,orderid) {
	kill();
	if (orderid>1) {
		var temp=orderid-1;
		//alert('move to '+temp);
		document.albumform.folderid.value=folderid;
		document.albumform.photoid.value=picid;
		document.albumform.newphotoid.value=temp;
		document.albumform.action.value='movephoto';
		document.albumform.submit();
	}
}

function rotateLeft(folderid,picid) {
	kill();
	document.albumform.folderid.value=folderid;
	document.albumform.photoid.value=picid;
	document.albumform.rotation.value='left';
	document.albumform.action.value='rotatephoto';
	document.albumform.submit();
}

function rotateRight(folderid,picid) {
	kill();
	document.albumform.folderid.value=folderid;
	document.albumform.photoid.value=picid;
	document.albumform.rotation.value='right';
	document.albumform.action.value='rotatephoto';
	document.albumform.submit();
}

Xoffset=1;    // modify these values to ...
Xoffset=1;    // modify these values to ...
Yoffset=1;    // change the popup position.
posx=0;
posy=0;
posb=0;
pose=0;

var old,skn,iex=(document.all),yyy=-1000;

var ns4=document.layers
var ns6=document.getElementById&&!document.all
var ie4=document.all

if (ns4)
  skn=document.dek;
else if (ns6)
  skn=document.getElementById("dek").style;
else if (ie4)
  skn=document.all.dek.style
if(ns4) {
  document.captureEvents(Event.MOUSEMOVE);
  document.captureEvents(Event.MOUSEDOWN);
}
else{
  skn.visibility="visible";
  skn.display="none";
}
document.onmousemove=get_mouse;
document.onmousedown=get_button;
document.oncontextmenu = new Function ("if (pose==1) return false; return true");

function ipopup(folderid,picid,picorder,enable){
   if (posb==1) {
  	var content='<TABLE WIDTH="156" BORDER=1 CELLSPACING=0 cellpadding=2 BORDERCOLOR=black><tr><td>';
      	    content+='<TABLE BORDER=0 BORDERCOLOR=black CELLPADDING=3 CELLSPACING=0 onmouseout="javascript:highlightTableRowVersionA(0);" id="myTable">';
	    if (enable) {
      	    	content+='<tr onmouseover="javascript:highlightTableRowVersionA(this, \'#b0b0ff\');"><td><img src="/images/usb/view.gif" border="0" alt="highlight photo"  title="set this photo as highlight" /></td><td align=left><a href="javascript:highlightPhoto('+folderid+','+picid+');">Highlight photo</a></td></tr>';
      	    	content+='<tr onmouseover="javascript:highlightTableRowVersionA(this, \'#b0b0ff\');"><td><img src="/images/usb/moveupo.gif" border="0" alt="move photo up"  title="move this photo one place up" /></td><td align=left><a href="javascript:moveUp('+folderid+','+picid+','+picorder+');">Move photo up</a></td></tr>';
      	    	content+='<tr onmouseover="javascript:highlightTableRowVersionA(this, \'#b0b0ff\');"><td><img src="/images/usb/movedowno.gif" border="0" alt="move photo down"  title="move this photo one place down" /></td><td align=left><a href="javascript:moveDown('+folderid+','+picid+','+picorder+');">Move photo down</a></td></tr>';
	    		content+='<tr><td colspan="2" width="170" bgcolor="#a0a0a0" style="height:1px" class="spacer"></td></tr>';
      	    	content+='<tr onmouseover="javascript:highlightTableRowVersionA(this, \'#b0b0ff\');"><td><img src="/images/usb/rotlefto.gif" border="0" alt="rotate left"  title="rotate this photo left" /></td><td align=left><a href="javascript:rotateLeft('+folderid+','+picid+');">Rotate photo left</a></td></tr>';
      	    	content+='<tr onmouseover="javascript:highlightTableRowVersionA(this, \'#b0b0ff\');"><td><img src="/images/usb/rotrighto.gif" border="0" alt="rotate right"  title="rotate this photo right" /></td><td align=left><a href="javascript:rotateRight('+folderid+','+picid+');">Rotate photo right</a></td></tr>';
	    		content+='<tr><td colspan="2" width="170" bgcolor="#a0a0a0" style="height:1px" class="spacer"></td></tr>';
      	    	content+='<tr onmouseover="javascript:highlightTableRowVersionA(this, \'#b0b0ff\');"><td><img src="/images/usb/delete.gif" border="0" alt="remove photo"  title="remove this photo" /></td><td align=left><a href="javascript:deletePhoto('+folderid+','+picid+');">Delete photo</a></td></tr>';
	    		content+='<tr><td colspan="2" width="170" bgcolor="#a0a0a0" style="height:1px" class="spacer"></td></tr>';
	    }
      	    content+='<tr onmouseover="javascript:highlightTableRowVersionA(this, \'#b0b0ff\');"><td><img src="/images/usb/mail.gif" border="0" alt="email photo"  title="email this photo" /></td><td align=left><a href="javascript:emailPhoto('+folderid+','+picid+');">Email photo</a></td></tr>';
		content+='<tr><td colspan="2" width="170" height="1" bgcolor="#a0a0a0" class="spacer"></td></tr>';
      	    content+='<tr onmouseover="javascript:highlightTableRowVersionA(this, \'#b0b0ff\');" onclick="kill();"><td width="10"></td height=\"20\"><td><a href="javascript:kill()">Cancel</a></td></TABLE></td></tr></table>';
  	if(ns4){skn.document.write(content);skn.document.close();skn.visibility="visible"}
  	if(ns6){document.getElementById("dek").innerHTML=content;skn.display=''}
  	if(ie4){document.all("dek").innerHTML=content;skn.display=''}
  	skn.left=posx+'px';
  	skn.top=posy+'px';
   	//alert('x: '+posx+', y: '+posy);
  	posb=0;
    }
}

function no_context(pos) {
	if (pos) {
		posb=1;
	}
	pose=1;
}

function get_mouse(e){
   var x=(ns4||ns6)?e.pageX:event.x;//+document.body.scrollLeft;
   posx=(x+Xoffset);
   //skn.left=(x+Xoffset)+'px';
   var y=(ns4||ns6)?e.pageY:event.y;//+document.documentElement.scrollTop;
   posy=(y+Yoffset);
   //skn.top=(y+yyy)+'px';
   //alert('x: '+x+', y: '+y);
}

function get_button(e) {
	var rightclick;
	if (!e) var e = window.event;
	if (e.which) rightclick = (e.which == 3);
	else if (e.button) rightclick = (e.button == 2);
	//if (rightclick) alert('Rightclick: ' + rightclick); // true or false
	if (rightclick) { 
		posb=1; 
		return false; 
	}
	//posb=0;
	pose=0;
  	return true;
}

function kill(){
   yyy=-1000;
   if(ns4){skn.visibility="hidden";}
   else if (ns6||ie4)
   skn.display="none"
}

//###################################################

var temp;
var picorder = new Array();
var numberofpics;
var seq;
var url;
var mainurl;
var thumbs = new Array();

function prevThumb() {
	var temptel=1;
	seq=(seq-1) % numberofpics;
	if (seq<0) {
		seq = numberofpics+seq;
	}
	for (var tel=seq; tel<(seq+9); tel++) {
		var eletel = tel % numberofpics;
		if (eletel==0) { 
			eletel = numberofpics;
		}
		thumbs[temptel]=picorder[eletel];
		document.getElementById('thumbid_'+temptel).src = url+picorder[eletel]+'.jpg';
		temptel++;
	}
}

function nextThumb() {
	var temptel=1;
	seq=(seq+1) % numberofpics;
	for (var tel=seq; tel<(seq+9); tel++) {
		var eletel = tel % numberofpics;
		if (eletel==0) { 
			eletel = numberofpics;
		}
		thumbs[temptel]=picorder[eletel];
		document.getElementById('thumbid_'+temptel).src = url+picorder[eletel]+'.jpg';
		temptel++;
	}
}

function openThumb(thumbid) {
	if (thumbs[thumbid]) {
		location.href=mainurl+'&seq='+seq+'&photoid='+thumbs[thumbid];
	}
	else {
		var temp=(seq + thumbid - 1) % numberofpics;
		if (temp==0) {
			temp = numberofpics;
		}
		location.href=mainurl+'&seq='+seq+'&photoid='+picorder[temp];
	}
}

function ipopupWrapper(folderid,thumbid,enable) {
	if (thumbs[thumbid]) {
		//alert('thumb - thumbid: '+thumbid+', picorder: '+picorder[thumbid]);
		ipopup(folderid,picorder[thumbid],thumbid,enable);
	}
	else {
		var picid=(seq + thumbid - 1) % numberofpics;
		if (picid==0) {
			picid = numberofpics;
		}
		//alert('no thumb - picid: '+picid+', picorder: '+picorder[picid]);
		ipopup(folderid,picorder[picid],picid,enable)
	}
}

var numberofalbums;
var aseq;
var aurl;
var amainurl;
var albums = new Array();
var albumtexts = new Array();

function prevAlbum() {
	var temptel=1;
	aseq=(aseq-1) % numberofalbums;
	if (aseq<0) {
		aseq = numberofalbums+aseq;
	}
	for (var tel=aseq; tel<(aseq+6); tel++) {
		var eletel = tel % numberofalbums;
		if (eletel==0) { 
			eletel = numberofalbums;
		}
		document.getElementById('albumid_'+temptel).src = aurl+albums[eletel];
		document.getElementById('albumtextid_'+temptel).innerHTML = albumtexts[eletel];
		temptel++;
	}
}

function nextAlbum() {
	var temptel=1;
	aseq=(aseq+1) % numberofalbums;
	for (var tel=aseq; tel<(aseq+6); tel++) {
		var eletel = tel % numberofalbums;
		if (eletel==0) { 
			eletel = numberofalbums;
		}
		document.getElementById('albumid_'+temptel).src = aurl+albums[eletel];
		document.getElementById('albumtextid_'+temptel).innerHTML = albumtexts[eletel];
		temptel++;
	}
}

function openAlbum(albumid) {
	var blaat = new Array();
	var blaat2 = aseq+albumid-1;
	blaat = albums[blaat2].split('/');
	//alert('blaat2 '+blaat2+', albums[blaat2] '+albums[blaat2]+', blaat[0] '+blaat[0]);
	location.href=amainurl+'?seq='+aseq+'&folderid='+blaat[1]+'&ownerid='+blaat[0];
}



