function cacheImgs(){
	if(!document.getElementsByTagName) return false;
	cached = new Array();
	var loc_elements = document.getElementsByTagName("img");
	for(var i=0; i<loc_elements.length; i++){
		if(loc_elements[i].parentNode.parentNode.getAttribute('id') == 'image_field'){
			cached[i] = new Image();
			cached[i].src = 'images/thumbnails/'+loc_elements[i].getAttribute('id').substr(2)+'_on.jpg';
		}
	}
}

function setRollovers(){
		if(!document.getElementsByTagName) return false;
		var nav_elements = document.getElementsByTagName("a");
		for(var i=0; i<nav_elements.length; i++){
			
			if(nav_elements[i].parentNode.getAttribute('id') == 'image_field'){
				nav_elements[i].onmouseover = switchOn;
				nav_elements[i].onmouseout = switchOff;
			}
		}
}


function setLinks(){
		if(!document.getElementsByTagName) return false;
		var nav_links = document.getElementsByTagName("a");
		for(var i=0; i<nav_links.length; i++){
			
			if(nav_links[i].parentNode.getAttribute('id') == 'image_field'){

				var imgToPop = nav_links[i].childNodes;
				
				for(var w=0; w<imgToPop.length; w++){
					if(imgToPop[w].nodeType == 1){
						var pop_id = imgToPop[w].getAttribute('id');
						output = 'nav_links[i].onclick = function() { show_lot("'+pop_id+'") };';
						eval(output);
					}
				}
			}
		}
}

function switchOn(){
	var imgToSwap = this.childNodes;
	for(var i=0; i<imgToSwap.length; i++){
		if(imgToSwap[i].nodeType == 1){
			var source 		= imgToSwap[i].src.lastIndexOf('/') + 1;
			var image_path 	= imgToSwap[i].src.substring(0,source);
			var fileSrc 	= imgToSwap[i].src.substring(source);
			var spot 		= (fileSrc.length - 6);
			
			var newSrc  	= fileSrc.substring(0,spot);
			if(fileSrc.substr(fileSrc.lastIndexOf('_')+1,3) == 'off'){
					imgToSwap[i].src = (image_path+newSrc + 'n.jpg');
			}
			//imgToSwap[i].src = (image_path+newSrc + 'n.jpg');
		}
	}
}

function switchOff(){
	var imgToSwap = this.childNodes;
	for(var i=0; i<imgToSwap.length; i++){
		if(imgToSwap[i].nodeType == 1){
			var source 		= imgToSwap[i].src.lastIndexOf('/') + 1;
			var image_path 	= imgToSwap[i].src.substring(0,source);
			var fileSrc 	= imgToSwap[i].src.substring(source);
			var spot 		= (fileSrc.length - 5);
			
			var newSrc  	= fileSrc.substring(0,spot);
			if(fileSrc.substr(fileSrc.lastIndexOf('_')+1,2) == 'on'){
					imgToSwap[i].src = (image_path+newSrc + 'ff.jpg');
			}
			//imgToSwap[i].src = (image_path+newSrc + 'ff.jpg');
			
		}
	}
}

addOnLoadEvent(setRollovers);
addOnLoadEvent(setLinks);
addOnLoadEvent(cacheImgs);
