Hey All im kinda new with javascript and I have a lil script made but need to add to it but kind of lost on what to do. Its a gallery that works fine but i have a part where there are two images a before and after.
one image shows with the chgimg function when onclick thumb displayed in the gallery.
I believe i need either a switch case or if statement
that says if main_img is after/1.jpg main_img2 is b4/1.jpg
thanks for the help :D
here is the html for eg.
<div class="section" id="section1">
<img src="images/gallery/lg/after/1.jpg" width="465" height="310" id="main_img" />
</div>
<div class="section" id="section2"><img src="images/gallery/lg/after/1.jpg" width="465" height="310" id="main_img2" /></div>
here is the javascript for better understanding
<script type="text/javascript">
function chgImg(pic){
document.getElementById('main_img').src=pic;
}
</script>
<script type="text/javascript">
d = document;
pictno = 4;
j=0;
pct=new Array;
for (i=pictno;i>0;i--){
pct[j]=i; j++;
}
curp = d.location.search.substr(1);
if (curp == '') curp=1;
for (i=0; i<pictno;i+=12){
if (curp == (i/12 + 1)){
}
}
d.write('<table cellspacing="5"><tr>');
currno = Math.floor(curp * 12 -12);
d.write('<div style="visibility:hidden; overflow:hidden; height:1px;">');
for (i=0;i<currno;i++){
d.write('<a href="images/gallery/lg/after/'+ pct[i] + '.jpg"><img src="images/gallery/tn/after/' + pct[i] + '.jpg" border="0"></a>\n');
}
d.write('</div>');
iPreload = new Array();
for (i=currno; i< ( pictno < (curp * 12) ? pictno : (curp * 12));i++){
if ((i % 3) == 0 && i != currno) {
d.write ('</tr><tr>');
}
iPreload[i] = new Image();
iPreload[i].src = "images/gallery/lg/after/'+ pct[i] + '.jpg";
d.write ('<td style="padding:5px;" align="center"><a href="javascript:;" onclick="chgImg(\'images/gallery/lg/after/' + pct[i] + '.jpg\')"><img src="images/gallery/tn/after/' + pct[i] + '.jpg" border="0"></a></td>');
}
d.write ('</tr></table>');
d.write('<div style="visibility:hidden; overflow:hidden; height:1px;">');
for (i= ( pictno < (curp * 3) ? pictno : (curp * 3));i<pictno;i++){
d.write('<a href="images/gallery/lg/after/'+ pct[i] + '.jpg" ><img src="images/gallery/tn/after/' + pct[i] + '.jpg" border="0"></a><br>');
}
d.write('</div>');
for (i=0; i<pictno;i+=12){
if (curp == (i/12 + 1)){
d.write ((i/12 + 1) +' ');
} else {
d.write ('<a href = gallery.html?' + (i/12 + 1) + '>'+ (i/12 + 1) + '</a> ');
}
}
d.write ('<br> My Image Gallery<br><br>');
-->
</script>