function linkover(name) {
  document.getElementById(name).style.backgroundImage="url('images/button.jpg')";
  document.getElementById(name).style.borderColor='#666666';	
}

function linkout(name) {
  document.getElementById(name).style.backgroundImage='';
  document.getElementById(name).style.border='none';	
}

function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
}

function gallery(no) {
   if (no>0 && no<totalimg+1) {
   	  if (no>firstpic-1 && no<lastpic+1) {
	  	selectedborder(no);
   		document.getElementById("image").src = 'files/media/galleries/'+gall+'/b'+no+'.jpg?'+new Date().getTime();
      	imgno = no; 
	  } else if (no==firstpic-1) {
	    window.location = 'media.php?page=gallery&galpage='+(page-1)+'&pic='+(firstpic-1)+'&gallery='+gall;
	  } else if (no==lastpic+1) {
	    window.location = 'media.php?page=gallery&galpage='+(page+1)+'&pic='+(lastpic+1)+'&gallery='+gall;
	  }
	  document.getElementById("caption").lastChild.nodeValue = captions[no];
   }
}

function selectedborder(no) {
   var i;
   for (i=firstpic;i<=lastpic;i++) {
      thumbno='thumb'+i;
      document.getElementById(thumbno).className='blackcell';
   }
   thumbno='thumb'+no;
   document.getElementById(thumbno).className='greycell';
}

function changepic(source,id) {  //changes source of a picture to include random digits, to bypass caching!
   		document.getElementById(id).src = source+'?'+new Date().getTime();
}

function changelink(source,id) {
   		document.getElementById(id).href = source;
}

function adminpic(src) { 
	document.write('<img id="image" src="'+src+'.jpg?'+new Date().getTime()+'" alt="" />');
}

function showhide(show, hide) {
	document.getElementById(show).style.display = 'inline';
	document.getElementById(hide).style.display = 'none';
}

function imgload(src,alt,pic) {
	var firstchar=src.substring(1,0);
	if (firstchar=="b") {
		document.write('<img id="image" src="'+src+'.jpg?'+new Date().getTime()+'" class="blackcell" alt="'+alt+'" id="thumb'+pic+'" />');
	} else {
		document.write('<img src="'+src+'.jpg?'+new Date().getTime()+'" class="blackcell" alt="'+alt+'" id="thumb'+pic+'" />');
	}
}