var ObjInd=0;
var Objs=new Array();

function readXML(file, id, delay, width, way){
	var xhr; 
	var delay=delay;
	var width=width;
	var way=way;
    try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
    catch (e) 
    {
        try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
        catch (e2) 
        {
          try {  xhr = new XMLHttpRequest();     }
          catch (e3) {  xhr = false;   }
        }
     }
  
    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200){
            	 var xml=xhr.responseXML;
            	 var max=xml.getElementsByTagName("item").length;
            	 var SlideObj=new slideObj(id, delay, xml, max, ObjInd, width);
            	 Objs[ObjInd]=SlideObj;
            	 SlideObj.init_images(way);
            	 ObjInd++;
              }
              else 
            	  return null;
         }
    }; 
	xhr.open("GET", file,  true); 
	xhr.send(null);
}
function initJavaxSlide(id, delay, file, width, way){
	readXML(file, id, delay, width, way);
}
function slideObj(id, delay, XMLResp, max, ObjInd, width){
	this.ObjInd=ObjInd;
	this.width=width;
	this.max=max;
	this.id=id;
	this.xind=0;
	this.IntID=0;
	this.side='left';
	this.imgObj1=window.document.getElementById(this.id+'1');
	this.imgObj2=window.document.getElementById(this.id+'2');
	this.Cont=window.document.getElementById(this.id+'cont');
	this.delay=delay;
	this.dataxml=XMLResp;
	this.ind=0;
	this.slidefnc=slidefnc;
	this.load_image=load_image;
	this.init_move=init_move;
	this.init_images=init_images;
}
function move(imgOb, way){
	if(way=='h'){
		if(imgOb.side=='left'){
			if(-imgOb.xind<=(imgOb.width)){
				dist=(-imgOb.xind)-imgOb.width;
				dist=-(Math.ceil(dist/3));
				if(dist==0){
					dist=1;
				}
				imgOb.Cont.style.left=imgOb.xind+'px';
				imgOb.xind=imgOb.xind-dist;
			}else{
				clearInterval(imgOb.IntID);
				imgOb.load_image(way);
				imgOb.side='right';
			}
		}else{
			if(imgOb.xind<0){
				imgOb.Cont.style.left=imgOb.xind+'px';
				dist=(-imgOb.xind);
				dist=(Math.ceil(dist/3));
				if(dist==0){
					dist=1;
				}
				imgOb.xind=imgOb.xind+dist;
			}else{
				clearInterval(imgOb.IntID);
				imgOb.xind=0;
				imgOb.load_image(way);
				imgOb.side='left';
			}
		}
	}else{
		if(imgOb.side=='left'){
			if(-imgOb.xind<=(imgOb.width)){
				dist=(-imgOb.xind)-imgOb.width;
				dist=-(Math.ceil(dist/3));
				if(dist==0){
					dist=1;
				}
				imgOb.Cont.style.top=imgOb.xind+'px';
				imgOb.xind=imgOb.xind-dist;
			}else{
				clearInterval(imgOb.IntID);
				imgOb.load_image(way);
				imgOb.side='right';
			}
		}else{
			if(imgOb.xind<0){
				imgOb.Cont.style.top=imgOb.xind+'px';
				dist=(-imgOb.xind);
				dist=(Math.ceil(dist/3));
				if(dist==0){
					dist=1;
				}
				imgOb.xind=imgOb.xind+dist;
			}else{
				clearInterval(imgOb.IntID);
				imgOb.xind=0;
				imgOb.load_image(way);
				imgOb.side='left';
			}
		}
	}
}
function  init_move(way){
	this.IntID=setInterval('move(Objs['+this.ObjInd+'], "'+way+'")', 10);
}
function  init_images(way){
	setTimeout('Objs['+this.ObjInd+'].init_move("'+way+'")', this.delay);
	this.imgObj1.innerHTML=this.dataxml.getElementsByTagName("descr")[this.ind].firstChild.nodeValue;
	this.ind++;
	if(this.ind==this.max){
		this.ind=0;
	}
	this.imgObj2.innerHTML=this.dataxml.getElementsByTagName("descr")[this.ind].firstChild.nodeValue;
	this.ind++;
	if(this.ind==this.max){
		this.ind=0;
	}
}
function load_image(way){
	setTimeout('Objs['+this.ObjInd+'].init_move("'+way+'")', this.delay);
	if(this.side=='left'){
		this.imgObj1.innerHTML=this.dataxml.getElementsByTagName("descr")[this.ind].firstChild.nodeValue;
		this.ind++;
		if(this.ind==this.max){
			this.ind=0;
		}
	}else{
		this.imgObj2.innerHTML=this.dataxml.getElementsByTagName("descr")[this.ind].firstChild.nodeValue;
		this.ind++;
		if(this.ind==this.max){
			this.ind=0;
		}
	}
}
function slidefnc(){
	this.load_image();
}
