
addEvent(window, 'load', changepic); //run changepic() on startup

function changepic(){
	nPic = 23;
	
    prepend = "http://"
	prepend = prepend + location.hostname;
	prepend = prepend + "/front/";
		
		
	if (!(document.getElementById("slideshow1"))) {
		return; /* kill this function if rightcolumn aint there */
	}
	isNewPic = false;
	while (!isNewPic) {
    	picsrc = prepend + (get_random(nPic-1)+1) + ".jpg";
    	isNewPic = true;
    	    	
    	for (i=1; i<=5; i++) {   //loop thru pic1-pic4
    	    checkimage = eval("document.images.slideshow" + i);
    	    if (checkimage.src==picsrc) {
    	        isNewPic = false;
    	        //alert("false\npicsrc:<" + picsrc + ">\ncheckimage:<" + checkimage.src + ">\nimg:<" + (i+1) + ">");
    	        break;
    	    }
    	}
	}
	chosenimage = eval("document.images.slideshow" + (get_random(4)+1));  //pic1-pic4	
    chosenimage.src = picsrc;
    	
	//alert("test")
	setTimeout("changepic()", 2000);
}

/* attach our function to the onload handler of the window object without 
 * overwriting what's already there - courtesy of Scott Andrew
 * http://www.sitepoint.com/article/structural-markup-javascript
 */
function addEvent(obj, evType, fn){
 if (obj.addEventListener){
   obj.addEventListener(evType, fn, true);
   return true;
 } else if (obj.attachEvent){
   var r = obj.attachEvent("on"+evType, fn);
   return r;
 } else {
   return false;
 }
}


function get_random(max_num) {
	max_num = max_num + 1;
	return Math.floor(Math.random()*max_num);
}
