var gLoadingQueueArr = new Array();

// --------------------------------------------------------------------------
	// getXmlHttpObj
	// returns HttpXMLRequest object
	// --------------------------------------------------------------------------
	function getXmlHttpObj() {
		try {
			// Mozilla, Safari
			httpXmlObj = new XMLHttpRequest();
		}
		catch(err) {
			try {
				// IE6+
				httpXmlObj = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(err) {
				try {
					// IE5.5
					httpXmlObj = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(err) {
					httpXmlObj = false;
					alert ("We are sorry, your browser doesn't support AJAX");
				}
			}
		}
		return httpXmlObj;
	}
	
	
	// --------------------------------------------------------------------------
	// loadFileInto
	// loads file into a specified html object (like div)
	// --------------------------------------------------------------------------
	function loadFileInto(aFileName, aHtmlObjId, aContentType) {
		alert(aFileName);
		xmlHttpObj = getXmlHttpObj();
		
		// this test doesn't work in IE6
		//try {
			//if (xmlHttpObj == false) {
				//return (false);
			//}
		//catch(err)
			// nothing
		//}
		
		// check if an html object to put content into exists
		htmlObj = document.getElementById(aHtmlObjId);
		if (htmlObj == false) { return (false); }
		
		// show preloader
		//htmlObj.innerHTML = htmlObj.innerHTML + '<img class="preloader" src="/_imgs/preloader.gif">'
		
		// pack operation data into an array
		operationArr = [];
		operationArr["xmlHttpObj"] 	= xmlHttpObj;
		operationArr["contentId"] 	= aContentType;
		operationArr["htmlObjId"] 	= aHtmlObjId;
		operationArr["operationId"] = aContentType;
		operationId = aContentType;
		
		// check if operation with the same contentID already exists in the queue (if so cancel the first operation and queue the new one)
		// :TO DO
		for (operationNo in gLoadingQueueArr) {
			operationId = gLoadingQueueArr[operationNo];
			if (operationId == aContentType) {
				gLoadingQueueArr.splice(operationNo, 1, operationArr);
			}
		}
		
		// queue the operation
		gLoadingQueueArr.push(operationArr);

		// send request for content with XMLHttpRequest object
		xmlHttpObj.onreadystatechange = function() { contentLoaded(operationId); };
		xmlHttpObj.open("GET", aFileName, true);
		//xmlHttpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttpObj.send(null);
	}


	// --------------------------------------------------------------------------
	// contentLoaded
	// executed on xmlHttpObj.status change (if status = 4 -> content is loaded)
	// --------------------------------------------------------------------------
	function contentLoaded(aOperationId) {

		// get data of the queued operation
		operationFoundFlag = false;
		for (operationNo in gLoadingQueueArr) {
			operationArr					= gLoadingQueueArr[operationNo];
			operationId 					= operationArr["operationId"];
			if (operationId == aOperationId) {
				xmlHttpObj 					= operationArr["xmlHttpObj"];
				contentId		 				= operationArr["contentId"];
				htmlObjId 					= operationArr["htmlObjId"];
				operationFoundFlag 	= true;
				operationPosInArr		= operationNo;
				break;
			}
		}

		// check if content loaded successfuly		
		if (xmlHttpObj.readyState != 4) { return (false); }
		if (xmlHttpObj.status != 200) {
				alert("There was a problem with the request");
				return (false);
		}
		
		// leave if operation not found
		if (operationFoundFlag == false) {
			return false;
		}
		
		// delete finished operation from the queue
		gLoadingQueueArr.splice(operationPosInArr, 1);

		// show content inside html object
		htmlObj = myDocument.getElementById(htmlObjId);
		htmlObj.innerHTML = xmlHttpObj.responseText;

		// content type specific actions
		switch (contentId) {
			case "bigImage":
				break;			
			default:
				// no support for this type of content
				break;
		}
	}
