// to add "../" before the image folder for the landscape image
// (pages at different levels of directory need different numbers of "../" added)

// get url
var strURL = location.href

// what is name of root folder?
var root_folder = "chemung"

// find where the root folder is in url
var start = strURL.indexOf(root_folder)
//alert("start: " + start)

// get the rest of the url to right of root folder
strURL = strURL.slice(start, strURL.length)
//alert("strURL: " + strURL)

// get the first "/" after root folder
start = strURL.indexOf("/")

// get the rest of the url after first "/"
strURL = strURL.slice(start+1, strURL.length)

// how many "/" after that? count them
var strCharacters = strURL.split("")
var backslashes =  0
for(i=0; i<strCharacters.length; i++){
	if(strCharacters[i]=="/"){
		backslashes++
	}
}
//alert("backslashes: " + backslashes)

// this function is used when writing code to page
function addBackslashes(){
	var strToAdd = ""
	
	// if none needed, return strToAdd empty
	if(backslashes == -1){
		return strToAdd
	
	// otherwise, count how many backslashes are needed and collect the string in strToAdd, then return it
	} else {
		for (i=0; i < backslashes; i++){
			strToAdd += "../"
		}
		return strToAdd
	}
}

// write code for image adding correct number of backslashes "../" e.g "../../images/landscape2.jpg"
// and generate a random number for selecting one of the images
var txt = "<td title='Scenes from Chemung County' id='landscape' align='center' background='" + addBackslashes() + "images/landscape" + (Math.round(Math.random()*6) + 1) + ".gif' height=50></td>"
document.writeln(txt)