
//              Code copyright nakedWeb 2007. All rights reserved                           //

var Xml={useActiveX:(typeof ActiveXObject!="undefined"),useXmlHttp:(typeof XMLHttpRequest!="undefined")};Xml.ARR_XMLHTTP_VERS=["MSXML2.XmlHttp.5.0","MSXML2.XmlHttp.4.0","MSXML2.XmlHttp.3.0","MSXML2.XmlHttp","Microsoft.XmlHttp"];;function XmlHttp(){}XmlHttp.create=function(){if(Xml.useXmlHttp){return new XMLHttpRequest();}else if(Xml.useActiveX){if(!Xml.XMLHTTP_VER){for(var i=0;i<Xml.ARR_XMLHTTP_VERS.length;i++){try{new ActiveXObject(Xml.ARR_XMLHTTP_VERS[i]);Xml.XMLHTTP_VER=Xml.ARR_XMLHTTP_VERS[i];break;}catch(oError){;}}}if(Xml.XMLHTTP_VER){return new ActiveXObject(Xml.XMLHTTP_VER);}else{throw new Error("Could not create XML HTTP Request.");}}else{throw new Error("Your browser doesn't support an XML HTTP Request.");}};XmlHttp.isSupported=function(){return Xml.useXmlHttp||Xml.useActiveX;};
var ie, _imageWidth, imageQ, slideshowQ, xpos, offset, _slider, stopPos, _html, _pics, _holder, timeLapse, d=document, f, g, i, x, isSlideshow = false;
var g = new Array(),f = new Array(),_slider = new Array(),xpos = new Array(),stopPos = new Array(),imageQ = new Array(),preLoad = new Array();
ie = ((navigator.userAgent.indexOf("5.5") > 0 || navigator.userAgent.indexOf("6.") > 0 || navigator.userAgent.indexOf("7.") > 0) && document.all);


function fInitSlideshows(){

	timeLapse= 1500;
	_imageWidth = 235;
	(ie)?offset=10:offset=12;
	
	//(ie)?offset=5:offset=10;
	_pics = new Array();
	_holder = new Array();
	
	if(xmlHttp&&xmlHttp.readyState!=0){
		xmlHttp.abort();
	}
	var xmlHttp = XmlHttp.create();
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
			var _responseText = xmlHttp.responseText;
			if(_responseText.substring(0,2) == 'OK'){
			
				_responseText = _responseText.split('|');
				_responseText.shift();
				slideshowQ = _responseText.length
				
				for (x = 0; x < slideshowQ; x++){
			
					_pics[x] = _responseText[x].split(',');_html='';
				
					if((d.getElementById('SlideshowHolder' + (x+1)))&&(_pics[x].length>1)){
						
						_holder[x] = d.getElementById('SlideshowHolder' + (x+1));
						//_pics[x] = _pics[x].sort();
						imageQ[x] = _pics[x].length;
						
						for (i = 0; i < _pics[x].length; i++){
							//preLoad[i] = new Image();//preLoad[i].src = 'Images/Slideshow/' + (x+1) + '/' + _pics[x][i];
							_html += '<img src=\'images/Slideshow/' + (x+1) + '/' + _pics[x][i] + '\' alt=\'\' width=\'235\' height=\'280\' />';
						}
						_holder[x].innerHTML = '<div id="Slideshow' + (x+1) + '">' + _html + '<\/div>';
						//fInitSlides(x);
					}
				}
				fInitSlides();
			}
		}
	}
	
	xmlHttp.open("GET",'Scripts/slideshowGenerator.asp',true);
	//xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlHttp.send(null)
}

function fInitSlides(){
	for (x = 0; x < slideshowQ; x++){
		if(_pics[x].length>1){
			xpos[x] = -_imageWidth*(imageQ[x]-1);
			stopPos[x]  = -_imageWidth*(imageQ[x]-2);
			
			_slider[x] = d.getElementById('Slideshow' + (x+1));
			_slider[x].style.width = (imageQ[x] * _imageWidth) + 'px';
			_slider[x].style.position = 'absolute';
			_slider[x].style.left = xpos[x] + 'px';
		}
		g[x] = setTimeout('fSlideDiv(' + x + ')',timeLapse);
	}
}

function fSlideDiv(_which){
var thisTimelapse;
	//offset=10;
		
		
	xpos[_which]=xpos[_which]+offset;

	if(xpos[_which] >= stopPos[_which]){
		
		_slider[_which].style.left = stopPos[_which] + 'px';
		stopPos[_which] = stopPos[_which] + _imageWidth;
		thisTimelapse = 0
		
		if(stopPos[_which] >= 1 ){
			
			
			xpos[_which] = -_imageWidth*(imageQ[_which]-1);
			stopPos[_which]  = -_imageWidth*(imageQ[_which]-2);
			_slider[_which].style.left = xpos[_which] + 'px';
			
		//}else{
		//	thisTimelapse = 15
		}
		
		g[_which] = setTimeout('fSlideDiv(' + _which + ')',timeLapse+thisTimelapse);
		
	}else{
		_slider[_which].style.left = xpos[_which] + 'px';
		f[_which] = setTimeout('fSlideDiv(' + _which + ')',40);
	}
}

window.onload = function(){
	fInitSlideshows();
}
