var imageViewer = {

	dynimages: $A(),
	preloadimg: true,
	main_photo_index: 0,
	optlinktarget: '',
	imgborderwidth: 0,
	filterstring: "progid:DXImageTransform.Microsoft.GradientWipe(GradientSize=1.0 Duration=1.0)",
	
	secs: 0,
	timerID: null,
	timerRunning: false,
	delay: 4000,
	ph_id: 1,
	
	main_element: 'photo',
	
	init: function() {
		if (this.preloadimg) {
			for (x=0; x<this.dynimages.length; x++){
				var myimage=new Image();
				myimage.src=this.dynimages[x][0];
			}
		}
//		console.log($$('div'));
//		$$('.thumbLink').each(function(el){
//			Event.observe(el,'mouseover',function(){
//				console.log(el.key);
//				imageViewer.modifyimage(el.key);
//				imageViewer.StopTheClock();
//			});
//			Event.observe(el,'mouseout',function(){imageViewer.resumeTimer()});
//		});
	},
	
	returnimgcode: function(theimg) {
		var imghtml=""
		if (theimg[1]!="")
			imghtml='<a href="'+theimg[1]+'" target="'+this.optlinktarget+'">';
			imghtml+='<img src="'+theimg[0]+'" border="'+this.imgborderwidth+'">';
			if (theimg[1]!="")
				imghtml+='</a>';
			return imghtml;
	},
	
	modifyimage: function(imgindex){
		this.main_photo_index = imgindex;
			var imgobj=$(this.main_element);
			if (imgobj.filters && window.createPopup){
				imgobj.style.filter=this.filterstring;
				imgobj.filters[0].Apply();
			}
			imgobj.update(this.returnimgcode(this.dynimages[imgindex]));
			if (imgobj.filters && window.createPopup)
				imgobj.filters[0].Play();
			return false;
	},
	
	InitializeTimer: function() {
		this.StopTheClock();
		this.StartTheTimer();
	},
		
	StopTheClock: function() {
		if(this.timerRunning)
			clearTimeout(this.timerID);
		this.timerRunning = false;
	},
		
	StartTheTimer: function() {
		this.timerRunning = true;
		this.timerID = self.setTimeout("imageViewer.call_image_swap()", this.delay);
	},
	resumeTimer: function() {
		this.ph_id = this.main_photo_index;
		this.StartTheTimer();
	},
	call_image_swap: function(){
		id = this.ph_id%this.dynimages.length;
		this.modifyimage(id);
		this.ph_id = this.ph_id + 1;
		if (this.timerRunning)
			this.timerID = self.setTimeout("imageViewer.call_image_swap()", this.delay);
	}
};
