window.onload = showImage;
var slideShowTimer = 0;

var pauseSome = 0;

var total = 5 // enter the total number of images

function showImage() {

	ad = document.getElementById('slide_display');
	
	weightOption = 1; //Set to 1 to give a 50/50 chance for a particular banner to appear first
	important = 2; //Set the jpeg number of that banner here
	
	if(weightOption == 1){
		flip = Math.floor(Math.random()*2) + 1;
		if(flip == 1){
			ad.src = 'slideshow/' + important + '.jpg';
			linkSwitcher(important);
			slideShowTimer = setInterval('slideShow(important)', 8000)
			}
	
		
	else {
	
		pick = Math.floor(Math.random()*total) + 1;
	
		ad.src = 'slideshow/' + pick + '.jpg';
		linkSwitcher(pick);
		slideShowTimer = setInterval('slideShow(pick)', 8000)
		}
	}
	}
	
function switchImage(direction) {

	currentAd = document.getElementById('slide_display');
	
	
	if(direction == 'forward') {
		
		stripPath = currentAd.src.split('slideshow/');
		getNum = stripPath[1].split('.jpg');
		newNum = parseInt(getNum[0]) +1;
		
		if(newNum > total) {
			newNum = 1;
			}

		currentAd.src = stripPath[0]+'slideshow/'+newNum+'.jpg'
		
		
			
		
		}
		
	if(direction == 'back') {
		stripPath = currentAd.src.split('slideshow/');
		getNum = stripPath[1].split('.jpg');
		newNum = parseInt(getNum[0]) -1;
		
		if(newNum == 0) {
			newNum = total;
			}

		currentAd.src = stripPath[0]+'slideshow/'+newNum+'.jpg'
			}
				
	linkSwitcher(newNum);		
	clearInterval(slideShowTimer);
	clearTimeout(pauseSome);
	pauseSome = setTimeout('restartTimer(newNum)', 10000);
	
	}
	
	
function slideShow(pick) {

	currentAd = document.getElementById('slide_display');

	stripPath = currentAd.src.split('slideshow/');
	getNum = stripPath[1].split('.jpg');
	newNum = parseInt(getNum[0]) +1;

	if(newNum > total) {
		newNum = 1;
		}

	currentAd.src = stripPath[0]+'slideshow/'+newNum+'.jpg'
	
	linkSwitcher(newNum);
	}
	
function restartTimer(newNum) {
	
	slideShowTimer = setInterval('slideShow()', 8000);
	linkSwitcher(newNum);	
	}
	
	
function linkSwitcher(fileNum) {

	adFinder = document.getElementById('linkholder');
	linkTo = document.getElementById('dynlink');
	
	
	
	if(isIE() == true) {
		
		
		adLoc = fileNum-1;
		adLoc = adLoc + fileNum;
		
		
		// This example works.  IE needs an odd number from 1-9 to make this work    -------    alert(adFinder.childNodes[1].href);
	
		if(adLoc%2){
			
			adFinder.childNodes[0].href = adFinder.childNodes[adLoc].href;
			linkTo.href = adFinder.childNodes[adLoc].href;
			
		}
		else{
			
			adFinder.childNodes[0].href = adFinder.childNodes[adLoc].href;
			linkTo.href = adFinder.childNodes[adLoc].href;
			}
			
		}
	
	else{
	
	adder = fileNum + 1;
	adLoc = fileNum + adder;
	
	if(adLoc%2){
		adFinder.childNodes[1].href = adFinder.childNodes[adLoc].href;

		linkTo.href = adFinder.childNodes[adLoc].href;
		}
	else{
		adLoc++;
		adFinder.childNodes[1].href = adFinder.childNodes[adLoc].href;
		linkTo.href = adFinder.childNodes[adLoc].href;
		}
		}
	}
	


function isIE() {

	return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);

}


