


function ImageTicker(minLeftToHide,maxLeftToHide){
	//static singleton instance (there can be only one)
	ImageTicker.instance=this;
	this.interval=null;	//the interval id of the SetInterval() function
	//the max pixel nr for the left property of an image
	//if the pixel nr is bigger than this the image is thrown at the begining
	this.maxLeftToHide=775+maxLeftToHide;
	//the min pixel nr for the left property of an image
	//if the pixel nr is lower than this the image is thrown at the end
	this.minLeftToHide=minLeftToHide;
	//the x coordinate of the mouse that decide whether the direction to move is left or right
	this.changeDirectionAt=500;
	//last direction to move (optimisation)
	this.lastDirection='';
	//nr of pixel beetween pictures left property 
	this.distanceFromNextPhoto=85;
	//the array of photos
	this.photos=Array();
	
	//gets the max nr of pixels  from the left property of all images
	this.getMaxLeft=function(){
		var maxLeft=0;
		for (var i=0;i<this.photos.length;i++){
			var left=this.photos[i].style.left;
			left=parseInt(left.substr(0,left.length-2));
			if(left>maxLeft){
				maxLeft=left;
			}
		}
		return maxLeft;
	}
	
	//gets the min nr of pixels  from the left property of all images
	this.getMinLeft=function(){
		var minLeft=0;
		for (var i=0;i<this.photos.length;i++){
			var left=this.photos[i].style.left;
			left=parseInt(left.substr(0,left.length-2));
			if(left<minLeft){
				minLeft=left;
			}
		}
		return minLeft;
	}
	
	//moves the images 1 pixel in the required direction
	this.move=function(direction){
		
		var elem=document.getElementById('content');
		var index=0;
		if(this.photos.length<=0){
			for(var i=0;i<elem.childNodes.length;i++){
				if(elem.childNodes[i].tagName=='IMG'){
					this.photos[index]=elem.childNodes[i];
					index++;	
				}
			}
			
		}
		for (var i=0;i<this.photos.length;i++){
			var curentLeft=this.photos[i].style.left;
			curentLeft=parseInt(curentLeft.substr(0,curentLeft.length-2));
			switch(direction){
				case 'left':
					if(curentLeft<this.minLeftToHide){
						curentLeft=this.getMaxLeft()+this.distanceFromNextPhoto;
					}
					if((curentLeft<this.maxLeftToHide)&&(this.photos[i].style.display=='none')){
						this.photos[i].style.display='inline';
					}
					if((curentLeft>this.maxLeftToHide)&&(this.photos[i].style.display!='none')){
						this.photos[i].style.display='none';
					}
					this.photos[i].style.left=(curentLeft-1)+"px";
					break;
				case 'right':
					if(curentLeft>this.maxLeftToHide){
						curentLeft=this.getMinLeft()-this.distanceFromNextPhoto;
						if((curentLeft<this.minLeftToHide)&&(this.photos[i].style.display!='none')){
							this.photos[i].style.display='none';
						}
					}
					if((curentLeft>this.minLeftToHide)&&(this.photos[i].style.display=='none')){
							this.photos[i].style.display='inline';
						}
					if((curentLeft>this.maxLeftToHide)&&(this.photos[i].style.display='inline')){
						this.photos[i].style.display='none';
					}
					//alert('cl='+curentLeft+" left="+this.photos[i].style.left);
					this.photos[i].style.left=(curentLeft+1)+'px';
					break;
			}
			
		}
	}
	
	this.start=function(e) {
		
		emod = (window.event) ? "IE4+" : (e) ? (e.eventPhase) ? "W3C" : "NN4" : "unknown"; 
		var x;
		switch (emod) {
    		case "IE4+": e=window.event; x=e.clientX;break;
			default : e = e; x=e.pageX; break;
		}
		var direction=null;
		if(x<=ImageTicker.instance.changeDirectionAt){
			direction='left';
		}
		else{
			direction='right';
		}	
		if(direction==ImageTicker.instance.lastDirection){
			return true;
		}
		if(ImageTicker.instance.interval!=null){
			clearInterval(ImageTicker.instance.interval);
		}
		
		ImageTicker.instance.lastDirection=direction;		
		ImageTicker.instance.interval=window.setInterval('ImageTicker.instance.move("'+direction+'")', 1);
		
	}
}

//++++++++++++example to use this object+++++++++++++++
/*
<script language="JavaScript">
	window.onload = function() {
		var IT=new ImageTicker();
		document.getElementById('your content layer id').onmousemove = IT.start;
	};
</script>
*/	

function getAbsTop(o) {
	oTop = o.offsetTop
	while(o.offsetParent!=null) {
		oParent = o.offsetParent
		oTop += oParent.offsetTop
		o = oParent
	}
	return oTop
}

function getAbsLeft(o) {
	oLeft = o.offsetLeft
	while(o.offsetParent!=null) {
		oParent = o.offsetParent
		oLeft += oParent.offsetLeft
		o = oParent
	}
	return oLeft
}

function setLeftDim(a,b){
	var ImageOffsetLeft=document.getElementById(a).offsetLeft;
	var ImageLeft=document.getElementById(a).style.left;
	var layerOffsetLeft=getAbsLeft(document.getElementById(b));
	//alert("clientLeft="+document.getElementById(b).clientLeft)
	//alert("absLeft="+getAbsLeft(document.getElementById(b)));
	//alert(document.getElementById(b).id+" offsetLeft="+layerOffsetLeft+" ||||| "+document.getElementById(a).id+" ImageOffsetLeft="+ImageOffsetLeft);
	document.getElementById(a).style.left=parseInt(ImageLeft)+parseInt(layerOffsetLeft)+'px';
}