
function ImageLoader(imgArray) {
var isMinimize = false;
var xOffset = 0;
var yOffset = 0;
var xPos = 0;
var yPos = 0;
var percent = 0;
var dragable = false;
var pics = null;
var imgObjs = null;
var total = 0;
var loaded = 0;
var bodyTag = null;
var compatible = false;
var dragFunc = null;


///////////////
// SET X POS //
///////////////
function setX(value) {
xPos = value;
mainDiv.style.left = xPos +"px";
}

///////////////
// SET Y POS //
///////////////
function setY(value) {
yPos = value;
mainDiv.style.top = yPos +"px";
}

///////////////
// GET X POS //
///////////////
function getX() {
return xPos;
}

///////////////
// GET Y POS //
///////////////
function getY() {
return yPos;
}


/////////////////////////////////////////
// DETERMINE IF LOADING IS IN PROGRESS //
/////////////////////////////////////////
function isLoading() {
}


////////////////////////////////
// GET TOTAL NUMBER OF IMAGES //
////////////////////////////////
function getTotal() {
return total;
}

///////////////////////////////
// GET NUMBER OF IMAGES LEFT //
///////////////////////////////
function getImagesLeft() {
return total - loaded;
}


/////////////////////////////////
// GET NUMBER OF IMAGES LOADED //
/////////////////////////////////
function getImagesLoaded() {
return loaded;
}



//////////////////
// IMAGE LOADED //
//////////////////
function imgLoaded(imgObj) {
loaded++;
percent = Math.ceil(loaded/total*100);
//loadingInfo.data = "Loaded \"" +getFileName(this.src)+ "\" (" +loaded+ "/" +total+ ")";
updateStats();
}

////////////////////////
// IMAGE FAIL TO LOAD //
////////////////////////
function imgFailed(imgObj) {
loaded++;
percent = Math.ceil(loaded/total*100);
loadingInfo.data = "Failed \"" +getFileName(this.src)+ "\" (" +loaded+ "/" +total+ ")";
alert("Image \"" +this.src+ "\" failed to load, likely a broken link.  Skipping image.  Please contact the webmaster about this.");
updateStats();
}

/////////////////////////
// UPDATE PROGRESS BAR //
/////////////////////////
function updateStats() {
progressBar.setAttribute("height", (percent*2)+"");
percentTextNode.data = percent +"%";
if (loaded == total)
{
//a=1;
//finish();
destroyIt();
}
}


////////////////////
// FINISH LOADING //
////////////////////
/*
function finish() {

if (isMinimize)
	minimize();

var buttonLayout = document.createElement("CENTER");
buttonLayout.appendChild(doneForm);
loadingDiv.appendChild(buttonLayout);

}*/


///////////////////
// DESTROY LAYER //
///////////////////
function destroyIt() {
//bodyTag.removeChild(mainDiv);
//mainDiv.style.visibility="hidden";
bodyTag.removeChild(mainDiv);
}


///////////////////
// GET FILE NAME //
///////////////////
function getFileName(s) {
return s.substr(s.lastIndexOf("/")+1);
}


////////////////////
// SET TITLE TEXT //
////////////////////
function setTitleText(value) {
titleLayoutTitleTextNode.data = value;
}

////////////////////
// SET TITLE TEXT //
////////////////////
function setInfoText(value) {
infoText.data = value;
}


//////////////////////
// HIDE LOADING BOX //
//////////////////////
function hideIt() {
mainDiv.style.visibility = "hidden";
}


//////////////////////
// SHOW LOADING BOX //
//////////////////////
function showIt() {
mainDiv.style.visibility = "visible";
setY(5);
}


//////////////////////////////////////
// SET ARRAY OF IMAGE FILES TO LOAD //
//////////////////////////////////////
function setLoadArray(ar) {
pics = ar;
imgObjs = new Array(pics.length);
total = pics.length;
for (i=0; i<pics.length; i++)
	{
	imgObjs[i] = new Image();
	imgObjs[i].onload = imgLoaded;
	imgObjs[i].onerror = imgFailed;
	imgObjs[i].src = pics[i];
	}
showIt();
}


/////////////////////////////
// CHECK FOR COMPATIBILITY //
///////////////////////////// 

if (typeof(document.createElement) != "undefined" && typeof(document.createTextNode) != "undefined" && typeof(document.getElementsByTagName) != "undefined")
	{
	bodyTag = document.getElementsByTagName("body").item(0);
	compatible = true;
	}

// ANDREY BULD GUI2

var mainDiv = document.createElement("DIV");
mainDiv.setAttribute("style","");
mainDiv.style.position = "absolute";
mainDiv.style.left = xPos +"px";
mainDiv.style.top = yPos +"px";
mainDiv.style.visibility = "hidden";
mainDiv.style.width = "500px";
//mainDiv.style.borderLeft = "1px";mainDiv.style.borderTop = "1px";mainDiv.style.borderBottom = "1px";mainDiv.style.borderRight = "2px";mainDiv.style.borderStyle = "solid";mainDiv.style.borderColor = "#000000";
mainDiv.style.cursor = "move";
//mainDiv.style.backgroundColor = "#BFBFBF";

var msgDiv = document.createElement("DIV");
msgDiv.setAttribute("style","");
msgDiv.style.position = "absolute";
msgDiv.style.left =  xPos+20+"px";
msgDiv.style.top = yPos+"px";
mainDiv.style.visibility = "hidden";
msgDiv.style.width = "100px";

var percentDiv = document.createElement("DIV");
percentDiv.setAttribute("style","");
percentDiv.style.position = "absolute";
percentDiv.style.left =  xPos+35+"px";
percentDiv.style.top = yPos+235+"px";
percentDiv.style.width = "200px";

var progressBarLayout = document.createElement("DIV");
progressBarLayout.setAttribute("style", "");
progressBarLayout.style.backgroundColor = "#FFFFFF";
progressBarLayout.style.position = "absolute";
progressBarLayout.style.left =  xPos+40+"px";
progressBarLayout.style.top = yPos+25+"px";
progressBarLayout.style.width = "20px";
progressBarLayout.style.height = "200px";
progressBarLayout.style.borderLeft = "2px";
progressBarLayout.style.borderRight = "1px";
progressBarLayout.style.borderTop = "2px";
progressBarLayout.style.borderBottom = "1px";
progressBarLayout.style.borderStyle = "solid";
progressBarLayout.style.borderColor = "#000000";

var progressBar = document.createElement("IMG");
progressBar.setAttribute("src", "../pic/grey.gif");
progressBar.setAttribute("border", "0");
progressBar.setAttribute("width", "20");
progressBar.setAttribute("height", "100");

progressBarLayout.appendChild(progressBar);

//var loadingInfo = document.createTextNode("Loading... " +loaded+ "/" +total);
var loadingInfo = document.createTextNode("Loading... ");
var loadingTextFont = document.createElement("FONT");
// var loadingTextBold = document.createElement("B");
loadingTextFont.setAttribute("size","3");
loadingTextFont.setAttribute("face","Times New Roman");
loadingTextFont.setAttribute("color","white");
// loadingTextBold.appendChild(loadingInfo);
// loadingTextFont.appendChild(loadingTextBold);
loadingTextFont.appendChild(loadingInfo);

msgDiv.appendChild(loadingTextFont);


//percentTextFont.setAttribute("color", "#FFFFFF");



//var percentTextBold = document.createElement("B");
var percentTextNode = document.createTextNode("0%");
var percentTextFont = document.createElement("FONT");

percentTextFont.setAttribute("face", "Times New Roman");
percentTextFont.setAttribute("color","white");
percentTextFont.setAttribute("size", "2");

//percentTextBold.appendChild(percentTextNode);
//percentTextFont.appendChild(percentTextBold);
percentTextFont.appendChild(percentTextNode);


percentDiv.appendChild(percentTextFont);

mainDiv.appendChild(msgDiv);
mainDiv.appendChild(progressBarLayout);
mainDiv.appendChild(percentDiv);
bodyTag.appendChild(mainDiv);

//////////////////////
// START PRELOADING //
//////////////////////
if (compatible)
	{
	if (typeof imgArray != "undefined")
		{
		setLoadArray(imgArray);
		}
	}
//enableDrag();



//////////////////////////
// SET PUBLIC VARIABLES //
//////////////////////////
this.destroyIt = destroyIt;
this.setX = setX;
this.setY = setY;
this.setTitleText = setTitleText;
this.setInfoText = setInfoText;
this.setLoadArray = setLoadArray;
this.hideIt = hideIt;
this.showIt = showIt;
this.getX = getX;
this.getY = getY;
this.isLoading = isLoading;
this.getTotal = getTotal;
this.getImagesLeft = getImagesLeft;
this.getImagesLoaded = getImagesLoaded;
}


