/*copyright©2000Itide.aps*/

/*
the name attribute in the html img-tag has to start width "ImgBtn" + a unik name of the image,
for this script to function probely
It is only functional for mouseOver and mouseOut.


 two variables to hold the path and ---
-----RollPostFix-----
The imagefiles has to be named according to this rule:
fx:
Original Image: image.gif
RollOver Image: image_over.gif  

The "_over" is here: RollPostFix

call "changeImages(imgName)" in the eventHanddler
 
 the Init function has to include the following functions;
 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 see new Init-function at bottom (initImageScripts())
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

	getImageNameArray();
	getImageSrcArray();
	createRollImg();
	getImagesProps();
	PreloadImages();

 */

ImagePath ="" //"Files/Nav/"
RollPostFix = "_over"

preloadFlag = false;
rollstate = false;

var ImageNameArray = new Array();
var ImageSrcArray = new Array();
var ImageRollArray = new Array();
var ObjectArray = new Array();
var PreloadArray = new Array();

function changeImages(imgName) {
	var count;
	
	for (i=0;i<ObjectArray.length;i++){
		if(ObjectArray[i].name == imgName){
			count = i;
		}
	
	}
	if (document.images && preloadFlag) {
			
			tempStr = document.images[imgName].src
			myPath = tempStr.substr(0,tempStr.lastIndexOf("/")+1)
			  			
			if(!rollstate){
				document.images[imgName].src = myPath + ObjectArray[count].rollsrc;
				rollstate = true;
			}
			else{
				document.images[imgName].src = myPath + ObjectArray[count].src;
				rollstate = false;
			}
		
	}
}




function getImageNameArray(){
	var j =0;
	for(i=0;i<document.images.length;i++){
	
	//find the images there starts with "ImgBtn" and has a name
	
		if(document.images[i].name!="" && document.images[i].name.indexOf("ImgBtn")!= -1){
			ImageNameArray[j]=document.images[i].name;
		//alert(ImageNameArray[j])
			j++;
			
			}
	
	}
}
function getImageSrcArray(){
	var j =0;
	for(i=0;i<document.images.length;i++){
	
	//find the images there starts with "ImgBtn" and has a name
	
		if(document.images[i].name!="" && document.images[i].name.indexOf("ImgBtn")!= -1){		
			tempStr =document.images[i].src;			
			strfrom = tempStr.lastIndexOf("/");
			strTo = document.images[i].name.length
			strSrc = tempStr.substr((strfrom+1),document.images[i].src.length)
  			ImageSrcArray[j] = strSrc;
  			ImagePath = tempStr.substr(0,tempStr.lastIndexOf("/")+1)
			j++;
			}
	}
}

function createRollImg(){

	for(i=0;i<ImageSrcArray.length;i++){
		tempstr = ImageSrcArray[i];
		imgType = tempstr.substring(ImageSrcArray[i].length-4);
		tempstr = tempstr.substring(0,(ImageSrcArray[i].length - 4));
		tempstr = tempstr + RollPostFix
		tempstr += imgType;
		ImageRollArray[i] = tempstr;	
	}
}


function ImagesProps(name,src,rollsrc){
	this.name = name;
	this.src = src;
	this.rollsrc = rollsrc;
	return this;
	}


function getImagesProps(){
	
	for(i=0;i<ImageNameArray.length;i++){
		tempObj= "Obj" + ImageNameArray[i].toString();
		tempObj = new ImagesProps();
		tempObj.name = ImageNameArray[i];
		tempObj.src = ImageSrcArray[i];
		tempObj.rollsrc = ImageRollArray[i];
		ObjectArray[i] = tempObj;
		}
		return ObjectArray
}

function PreloadImages(){
	var tempPre;
		for (i=0;i<ObjectArray.length;i++){
			tempPre = 'pre'+ObjectArray[i].name;
			tempPre = new Image();
			tempPre.src = ObjectArray[i].rollsrc;
		}
	preloadFlag = true;
}

function initImageScripts(){
	getImageNameArray();
	getImageSrcArray();
	createRollImg();
	getImagesProps();
	PreloadImages();
}