var slides=[];
slides[0] = ["./latest/latest_1.jpg"];
slides[1] = ["./latest/latest_2.jpg"];
slides[2] = ["./latest/latest_3.jpg"];

var iss=[]; //array to cache inter_slide instances

function inter_slide() {
	var imgs=arguments[0];
	var width=null, height=null, delay=null;
	width=arguments[1], height=arguments[2], delay=arguments[3]? arguments[3] : null;

	this.dom=(document.getElementById) //modern dom browsers
	this.da=document.all
	this.delay=imgs.delay? imgs.delay : delay? delay : 6000+iss.length*750;
	this.nextimgidx=0;
	iss[this.issid=iss.length]=this;
	this.imgs=imgs;
	this.faded=0;
	this.loadimgidx=[];
	this.fade=!imgs.nofade;
	if(this.fade)
	this.degree=10 //initial opacity degree (10%)
	this.canvasbase="canvas"+this.issid
	this.curcanvas=this.canvasbase+"_0"
	this.width=imgs.width? imgs.width : width? width : null
	this.height=imgs.height? imgs.height : height? height : null
	var ief='', dims='';
	if(this.width||this.height)
	dims=this.width&&this.height? 'width:'+this.width+'px;height:340px;' : this.width? 'width:'+this.width+'px;' : 'height:380px;';
	if(this.fade&&document.body&&document.body.style)
	ief=document.body.filters? 'filter:progid:DXImageTransform.Microsoft.alpha(opacity=0);' : typeof document.body.style.opacity=='string'? 'opacity:0;' : 'opacity:0.10;-moz-opacity:0.10;-khtml-opacity:0.10;';
	var brs='<br />';
	document.write('<div align="center" style="border: none;">');
	document.write('<div id="master'+this.issid+'" style="position:relative; overflow:hidden;margin: 0; border: none;">');
	document.write('<div id="'+this.canvasbase+'_0" style="position:absolute;'+dims+' border: none; top: 0; left: 0; '+ief+'background-color: black;"><\/div>');
	document.write('<div id="'+this.canvasbase+'_1" style="position:absolute;'+dims+' border: none; top: 0; left: 0;'+ief+'background-color: black">');
	document.write('<\/div><\/div><\/div>');
	this.startit()
}

inter_slide.prototype.fadepic=function()
{
	if (this.fade&&this.degree<100)
	{
		this.faded=0
		this.degree+=10
		if (this.tempobj.filters&&this.tempobj.filters[0])
		{
			if (typeof this.tempobj.filters[0].opacity=="number") /*if IE6+*/ this.tempobj.filters[0].opacity=this.degree
			else /*else if IE5.5-*/ this.tempobj.style.filter="alpha(opacity="+this.degree+")"
		}
		else if (this.tempobj.style.MozOpacity) 	this.tempobj.style.MozOpacity=this.degree/101
		else if (this.tempobj.style.KhtmlOpacity) 	this.tempobj.style.KhtmlOpacity=this.degree/100
		else if (this.tempobj.style.opacity&&!this.tempobj.filters) 	this.tempobj.style.opacity=this.degree/101
	}
	else
	{
		this.faded=1
		clearInterval(this.fadeclear)
		this.nextcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_0" : this.canvasbase+"_1"
		this.tempobj=this.go(this.nextcanvas)
		if(this.playing) this.changeimg()
	}
}

inter_slide.prototype.populateslide=function(picobj, picidx)
{
	picobj.innerHTML='<a href="./portfolio.php" title="go to the portfolio page"><img id="theimg'+picidx+'_'+this.issid+'" width="260px" height="340px" src="'+(this.loadimgidx[picidx]&&typeof this.loadimgidx[picidx].complete=='boolean'&&this.loadimgidx[picidx].complete? this.loadimgidx[picidx].src : this.imgs[picidx][0])+'" '+(!this.width||!this.height? ' onload="iss['+this.issid+'].imgload(this);"' : '')+' border=0></a>'
}

inter_slide.prototype.imgload=function(el) {
	if(!el&&!this.imgel) return;
	var el=el? el : this.imgel;
	if(el.width==0||el.height==0) {
		this.imgel=el;
		var cacheobj=this;
		clearTimeout(this.getdim)
		this.getdim=setTimeout(function(){cacheobj.imgload()}, 300)
		return;
	}
	var m=this.go('master'+this.issid).style, c0=this.go(this.canvasbase+'_0').style, c1=this.go(this.canvasbase+'_1').style;
	if(!this.width) {
		this.width=el.width;
		m.width = c0.width = c1.width = this.width+'px';
	}
	if(!this.height) {
		this.height=el.height;
		m.height = c0.height = c1.height = this.height+'px';
	}
}

inter_slide.prototype.changeimg=function(bool,nav) {
	if(this.playing) {
		this.nextimgidx=(this.keeptrack()<this.imgs.length-1)? this.keeptrack()+1 : 0
		this.populateslide(this.tempobj, this.nextimgidx)
		if(bool)
			this.rotateimg()
		else {
			clearTimeout(this.inprocess)
			this.inprocess=setTimeout("iss["+this.issid+"].rotateimg()", this.delay)
		}
	}
	else {
		if(!this.faded) {
			if(nav&&nav=='nav')
				return;
			this.nextimgidx=this.keeptrack()+(bool? 1 : -1)
			this.nextimgidx=(this.nextimgidx<this.imgs.length)? this.nextimgidx : this.nextimgidx-this.imgs.length
			this.nextimgidx=(this.nextimgidx>-1)? this.nextimgidx : this.imgs.length+this.nextimgidx
			return;
		}
		if(this.fadeclear) clearInterval(this.fadeclear);
		if(bool) {
			var loadidx=this.nextimgidx+2
			loadidx=(loadidx<this.imgs.length)? loadidx : loadidx-this.imgs.length;
			loadidx=(loadidx>-1)? loadidx : this.imgs.length+loadidx;
			this.loadimgidx[loadidx]=new Image();
			this.loadimgidx[loadidx].src=this.imgs[loadidx][0];
		}
		else {
			var loadidx=this.nextimgidx-2
			loadidx=(loadidx<this.imgs.length)? loadidx : loadidx-this.imgs.length
			loadidx=(loadidx>-1)? loadidx : this.imgs.length+loadidx
			this.loadimgidx[loadidx]=new Image();
			this.loadimgidx[loadidx].src=this.imgs[loadidx][0];
		}
		if(nav&&nav=='jump') this.nextimgidx++;
		else this.nextimgidx=this.keeptrack()+(bool? 1 : -1)
		this.nextimgidx=(this.nextimgidx<this.imgs.length)? this.nextimgidx : this.nextimgidx-this.imgs.length
		this.nextimgidx=(this.nextimgidx>-1)? this.nextimgidx : this.imgs.length+this.nextimgidx
		this.populateslide(this.tempobj, this.nextimgidx)
		this.rotateimg()
	}
}

inter_slide.prototype.go=function(id){
return this.da? this.da[id] : document.getElementById(id);
}

inter_slide.prototype.rotateimg=function() {
	if(this.dom) {
		var cimg=this.go('theimg'+this.nextimgidx+'_'+this.issid)? this.go('theimg'+this.nextimgidx+'_'+this.issid) : null;
		if(cimg&&typeof cimg.complete=='boolean'&&!cimg.complete) {
			var cacheobj=this
			clearTimeout(this.loading)
			this.loading=setTimeout(function(){cacheobj.rotateimg()}, 300)
			return;
		}
		if(this.fade) this.resetit()
		var crossobj=this.tempobj=this.go(this.curcanvas)
		crossobj.style.zIndex++
		var othercanvas=this.curcanvas==this.canvasbase+"_0"? this.go(this.canvasbase+"_1") : this.go(this.canvasbase+"_0");
		othercanvas.style.zIndex=0;
		this.jumperidx=this.keeptrack()<this.imgs.length? this.keeptrack()+1 : 1;
		var fadeobj=this
		clearInterval(this.fadeclear)
		this.fadeclear=setInterval(function(){fadeobj.fadepic()},100)
		this.curcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_1" : this.canvasbase+"_0"
	}
	else {
		var v4imgobj=document.images['defaultslide'+this.issid]
		v4imgobj.src=this.postimgs[this.nextimgidx].src
		this.nextimgidx=(this.nextimgidx<this.imgs.length-1)? this.nextimgidx+1 : 0
	}
}

inter_slide.prototype.resetit=function() {
	this.degree=10
	var crossobj=this.go(this.curcanvas)
	if (crossobj.filters&&crossobj.filters[0]) {
		if (typeof crossobj.filters[0].opacity=="number") /*if IE6+*/ crossobj.filters(0).opacity=this.degree
		else /*else if IE5.5-*/ crossobj.style.filter="alpha(opacity="+this.degree+")"
	}
	else if (crossobj.style.MozOpacity) crossobj.style.MozOpacity=this.degree/101
	else if (crossobj.style.KhtmlOpacity) crossobj.style.KhtmlOpacity=this.degree/100
	else if (crossobj.style.opacity&&!crossobj.filters) crossobj.style.opacity=this.degree/101
}

inter_slide.prototype.startit=function() {
	this.playing=1
	var crossobj=this.go(this.curcanvas)
	this.populateslide(crossobj, this.nextimgidx)
	this.rotateimg()
}

inter_slide.prototype.keeptrack=function() {
	if(!document.getElementsByTagName) 	return this.nextimgidx;
	var canvases=[this.go('canvas'+this.issid+'_0'), this.go('canvas'+this.issid+'_1')]
	if(canvases[0].style.zIndex>canvases[1].style.zIndex&&canvases[0].getElementsByTagName("img")[0]) return parseInt(canvases[0].getElementsByTagName('img')[0].id.replace(/theimg/, ''))
	else if(canvases[1].getElementsByTagName("img")[0]) 	return parseInt(canvases[1].getElementsByTagName('img')[0].id.replace(/theimg/, ''))
	else return this.nextimgidx;
}
