Hi, I’m not the world’s best javascript coder, so I was hoping someone could point me in the right direction. I’m using a script to allow image switching on a page. It works fine when I need to switch one set of images…however, on some pages, I need to “re-use” the script for a second set of image changes. The script allows for one set of images. Here’s what I did…I copied the script and inserted it again in the head. Then, on the copied script, I changed the images and renamed all the variables. I figured this should have worked, but it didn’t, and none of the images would switch. Here’s the script…if anyone can help, I’d greatly appreciate it!
<head>
<script type=”text/javascript”>
<!–
var pic_width=322;
var pic_height=241;
var button_text=”Next Image”;
//pic1.src=”imgs/1896_GWCarver.jpg”;imgs/1896_JimCrow.jpg
if (document.images)
{
pic1= new Image(pic_width,pic_height);
pic1.src=”images/bht_wheatley.jpg”;
pic2= new Image(pic_width,pic_height);
pic2.src=”images/bht_turner.jpg”;
}
var pics= new Array(2)
pics[0]=pic1.src;
pics[1]=pic2.src;
var numpics=2;
var thenum=0;
imgName=”img1″;
function change_it2()
{
if (document.images)
{
document.write(“<IMG SRC='”+pics[thenum]+”‘ border=’0’ width='”+pic_width+”‘ height='”+pic_height+”‘ name=’img1’>n”);
}
}
function change_it3()
{
var x=0;
thenum+=1;
if (thenum>numpics-1)
{
document[imgName].src=pics[0];
thenum=0;
}
else
{
document[imgName].src=pics[thenum];
x+=1;
}
}
//–>
</script>
<body><!–here’s the function call–how do I re-use this script?–>
<script type=”text/javascript”>
<!–
change_it2();
//–>
</script>
<a class=”nextimage” href=”.” onClick=”change_it3();return false;” >next image></a>