/********************************************************************************
* Global js functions for IPC Media ipcmedia.com
*
* notes:
*	-	use _init() as replacement for onload event in pages
*	-	tested WIN ie 5.0,5.5,6, moz 1.8 MAC ie 5.02
********************************************************************************/
var d =document;

window.onload = function() {
	
	if( typeof window._init == "function" ) window._init();
	
}


imswp = imageSwapper.prototype;
var ao = new Array();

function imageSwapper( im, tr, it ) {
	
	this.images 	= im;
	this.itarget	= d.getElementById(tr);
	this.interval 	= it || 1000;
	this._currPos	= 0;

	this.preload();

	ao[tr] = this; //copy for swapPic
	
	this.f= function() { swapPic( tr ) };
	
	this.tmrhnd = 
	window.setInterval( this.f, this.interval );
	
	return this;

}

/*
* preload objects images for caching
*/
imswp.preload = function() {
	
	for( n in this.images ){
		i = new Image();
		i.src = this.images[n];
	}
	
}

/*
* change img src to next in array
*/
swapPic = function(tr) {

	o = ao[tr];

	if( (o._currPos+1) < o.images.length ) {
		o.itarget.src = o.images[o._currPos+1];
		o._currPos++;
	} else {
		o.itarget.src = o.images[0];
		o._currPos = 0;
	}


}

