var imageCounter = 0;
var running = false;
var timer;
var firstDone = false;
function runListingSlideShow(imageNumber) {
	if (imageNumber>=0) {
		imageCounter = imageNumber;
	} else {
		if (running) {
			if (imageCounter > 0 ){firstDone = true};
			imageCounter = ((imageCounter + 1) % imagesTotal);
		}
		if (imageCounter == 0 && firstDone == true ){
			onFin();
		}
	}
	if (document.all){
		document.images.ListingImage.style.filter="blendTrans(duration=2)";
		document.images.ListingImage.filters.blendTrans.Apply();
	}
	document.images.ListingImage.src = ListingImages[imageCounter].src;
	if (document.getElementById('ListingLink')){
		document.getElementById('ListingLink').href = ListingLinks[imageCounter];
	}
	if (document.images.ListingImage.alt){
		document.images.ListingImage.alt = ListingAlts[imageCounter];
	}
	if (document.getElementById('ListingDesc')){
		document.getElementById('ListingDesc').innerHTML = ListingDescs[imageCounter];
	}
	
	if (document.all){
		document.images.ListingImage.filters.blendTrans.Play();
	}
	if (running) {
		timer = setTimeout('runListingSlideShow(-1);', 6000);
	}
}
function controlSlideShow(command) {
	if (command=='pause') {
		if (running==true) {
			running=false;
			clearTimeout(timer);
		}
	}
	else if (command=='play') {
	 	if (running==false) {
			running=true;
			timer = setTimeout('runListingSlideShow(-1);', 1000);
	 	}
	}
	else if (command=='back') {
		clearTimeout(timer);
		if (imageCounter>0){
			runListingSlideShow((imageCounter - 1) % imagesTotal);
		}else{
			runListingSlideShow(imagesTotal-1);
		}
	}
	 else if (command=='forward') {
	 	clearTimeout(timer);
	 	runListingSlideShow((imageCounter + 1) % imagesTotal);
	}
}
function select_P(span){
	document.getElementById(span).onclick='';
	ajaxHTML('/Config/Actions.asp?Action=P', span ,'', '');
}



var xhr = new Array(); // ARRAY OF XML-HTTP REQUESTS
var xi = new Array(0); // ARRAY OF XML-HTTP REQUEST INDEXES
xi[0] = 1; // FIRST INDEX SET TO 1 MAKING IT AVAILABLE
function xhrRequest(type) {
	if (!type) {
		type = 'html';
	}
	// xhrsend IS THE xi POSITION THAT GETS PASSED BACK
	// INITIALIZED TO THE LENGTH OF THE ARRAY(LAST POSITION + 1)
	// IN CASE A FREE RESOURCE ISN'T FOUND IN THE LOOP
	var xhrsend = xi.length; 
	
	// GO THROUGH AVAILABLE xi VALUES
	for (var i=0; i<xi.length; i++) {
		// IF IT'S 1 (AVAILABLE), ALLOCATE IT FOR USE AND BREAK
		if (xi[i] == 1) {
			xi[i] = 0;
			xhrsend = i;
			break;
		}
	}
	// SET TO 0 SINCE IT'S NOW ALLOCATED FOR USE
	xi[xhrsend] = 0;
	// SET UP THE REQUEST
	if (window.ActiveXObject) {
		try {
			xhr[xhrsend] = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xhr[xhrsend] = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	} else if (window.XMLHttpRequest) {
		xhr[xhrsend] = new XMLHttpRequest();
		if (xhr[xhrsend].overrideMimeType) {
			xhr[xhrsend].overrideMimeType('text/' + type);
		}
	}
	return (xhrsend);
}
function ajaxHTML(url, span, loading, alCargar) {
	if (loading){
		document.getElementById(span).innerHTML = loading;
	}
	var xhri = xhrRequest('html');			
	xhr[xhri].open('GET', url, true);
	xhr[xhri].onreadystatechange = function() {
		//if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
		if (xhr[xhri].readyState == 4) {
			document.getElementById(span).innerHTML = xhr[xhri].responseText;
			//alert(xhr[xhri].responseText);
			xi[xhri] = 1;
			xhr[xhri] = null;
			if (alCargar){
				setTimeout(alCargar, 0);
			}
		}
	};
	xhr[xhri].send(null);
}





