﻿// JScript File

function placeImagesInMemory(){
	this.over = new Array();
	this.src = new Array();
	this.store = store;
  
	function store(src, over){
		var AL = this.src.length;
		this.src[AL] = new Image();
		this.src[AL].src = src;
		this.over[AL] = new Image();
		this.over[AL].src = over;
	}
}

var imageInMemory = new placeImagesInMemory();
var mouseisdown = 0;

function preloadImages(whatTag){
	for(i=0; i<whatTag.length; i++){
		if(whatTag[i].getAttribute('hsrc')){
			storeimages(whatTag[i]);
			var valImgAttributes = '';
			valImgAttributes = (whatTag[i].getAttribute('hsrc')) ? valImgAttributes + 'A' : valImgAttributes + '';

			mouseover(whatTag[i]);
			mouseout(whatTag[i]);

			if(whatTag[i].src){
				whatTag[i].setAttribute("oldsrc", whatTag[i].src);
			}
		}
	}
}

function mouseover(t){
	var newmouseover;
	if(t.onmouseover){
		t.oldmouseover=t.onmouseover;
		newmouseover= function(){
			this.src = this.getAttribute("hsrc");
			this.oldmouseover();
		}
	}
	else{
		newmouseover = function(){
			this.src = this.getAttribute("hsrc");
		}
	}
	t.onmouseover = newmouseover;
}

function mouseout(t){
	var newmouseout;
	if(t.onmouseout){
		t.oldmouseout=t.onmouseout;
		newmouseout = function(){
			this.src = this.getAttribute("oldsrc");
			this.oldmouseout();
		}
	}
	else{
		newmouseout = function(){
			this.src = this.getAttribute("oldsrc");
		}
	}
	t.onmouseout = newmouseout;
}

function storeimages(t){
	var s = (t.getAttribute('src'))?t.getAttribute('src'):'';
	var o = (t.getAttribute('hsrc'))?t.getAttribute('hsrc'):'';
	imageInMemory.store(s,o);
}

function preloadimgsrc(){
	if(!document.getElementById) return;
	var imgTag = document.getElementsByTagName('IMG');
	var inputTag = document.getElementsByTagName('INPUT');
	preloadImages(imgTag);
	preloadImages(inputTag);
}

if(window.addEventListener){
	window.addEventListener("load", preloadimgsrc, false);
} 
else{
	if(window.attachEvent){
		window.attachEvent("onload", preloadimgsrc);
	}
	else{
		if(document.getElementById){
			window.onload = preloadimgsrc;
		}
	}
}