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/galleries/'+gall+'/b'+no+'.jpg?'+new Date().getTime();
      	imgno = no; 
	  } else if (no==firstpic-1) {
	    window.location = 'galleries.php?page=gallery&galpage='+(page-1)+'&pic='+(firstpic-1)+'&gallery='+gall;
	  } else if (no==lastpic+1) {
	    window.location = 'galleries.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='formfield';
   }
   thumbno='thumb'+no;
   document.getElementById(thumbno).className='formtitle';
}

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="formfield" alt="'+alt+'" id="thumb'+pic+'" />');
	} else {
		document.write('<img src="'+src+'.jpg?'+new Date().getTime()+'" class="formfield" alt="'+alt+'" id="thumb'+pic+'" />');
	}
}

var collimages = new Array();
var i;
for (i=1;i<=4;i++) {
	collimages[i] = new Image();
	collimages[i].src = 'lib/images/sl'+i+'.jpg';
	//var imgxys = imgxys +i+' - X: '+collimagesx[i]+' - Y: '+collimagesy[i]+'\r\n';
}
//alert(imgxys);


function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 

function blendimage(divid, imageid, imagefile, millisec) { 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 
     

    //set the current image as background 
    document.getElementById(divid).style.backgroundImage = document.getElementById(imageid).style.backgroundImage; 
     
    //make image transparent 
    changeOpac(0, imageid); 
    

    //make new image 
    document.getElementById(imageid).style.backgroundImage = "url(" + imagefile + ")"; 


    //fade in image 
    for(i = 0; i <= 100; i++) { 
        setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed)); 
        timer++; 
    } 
} 

var thispic = 2;

function changecollage() {
	thispic = thispic+1;
	if (thispic==5) { 
		thispic=1;
	}
	blendimage('blend1','blendimage1',collimages[thispic].src,800);
}