
function preloadctrl(im){
	if (typeof im=='string'){
	var imo=new Image();
	imo.src=im;
	}
}

if(document.images&&typeof preload_ctrl_images!='undefined'&&preload_ctrl_images){
	var ctrlimgs=[previmg, stopimg, playimg, nextimg]
	for (var i_tem = 0; i_tem < ctrlimgs.length; i_tem++)
	if (ctrlimgs[i_tem])
	preloadctrl(ctrlimgs[i_tem])
}

var iss=[]; //array to cache inter_slide instances
var preload_ctrl_images=true;
var previmg='items/back.gif';
var stopimg='items/stop.gif';
var playimg='items/play.gif';
var nextimg='items/next.gif';
//settings
var set_counter=0;
var set_controls=1;	//Use for top controls
var set_use_alt=0;	//Use descriptions as the images' alt attributes
var set_use_title=0;	//Use descriptions as the images' title attributes
var set_use_prefix='';	//String prefix for image descriptions display'

var set_width='850';	//Ue to set width of widest image if dimensions vary, may also be set in the call as the 2nd parameter
var set_height='';	//Use to set height of tallest image if dimensions vary, may also be set in the call as the 3rd parameter
var set_auto=0;	//Use to make show completely user operated (no play button, starts in stopped mode)
var set_fade=1;	//Use for no fade-in, fade-out effect for this show
var set_descriptions=0;	//Use for no descriptions displayed for this slide show
var set_pause=0;	//Use for pause onmouseover
var set_image_controls=1;	//Use images for controls instead of the default buttons
var set_button_highlight='#cccccc'	//onmouseover background-color for image buttons (string) (requires image_controls=1) - use color name or hex value with # prefix
var set_specs='width=300, height=250, top=150, left=200, scrollbars, resizable, location'	//Set new window specifications for a slide group, will be overridden by array_name[#][4], if present
var set_random=0	//Set a random slide sequence on each page load
var set_fadecolor='#000'//	Set fading images' background color, defaults to white (string) - use color name or hex value with # prefix
var set_delay=3000;	//Set miliseconds delay between slider for a given show, may also be set in the call as the last parameter
var set_jumpto=0;	//Use for added controls to jump to a particular image by its number
var set_lightbox=0;

var set_border=0;	//Set border width for images (number of pixels)
var set_border_color='white';	//Set border color for images (string) - use color name or hex value with # prefix
var set_border_style='ridge';	//Set border style for for images (string) - requires border_color be set

function inter_slide(){
	if(!document.images||arguments.length==0)
	return;
	var imgs=arguments[0];
	var width=null, height=null, delay=null;
	if(arguments.length==2)
		delay=arguments[1];
	else if(arguments.length==3||arguments.length==4)
		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=set_delay? set_delay : delay? delay : 3000+iss.length*750;
	this.nextimgidx=0;
	iss[this.issid=iss.length]=this;
	this.imgs=imgs;
	if (set_random)
	this.imgs.sort(function() {return 0.5 - Math.random();}) //thanks to Mike (aka Mwinter) :)
	this.imgborder=set_border? parseInt(imgs_border) : 0;
	
	if (!this.dom){
		this.postimgs=new Array() //preload imgs
		for (p=0;p<imageSrc.length;p++){
			this.postimgs[p]=new Image()
			this.post[p].src=this.imgs[p][0]
		}
	}
	
	if (this.dom){ //if modern browsers (ie: Firefox, IE5+)
		
		if(set_fade) this.degree=10; //initial opacity degree (10%)
		
		this.faded=0;
		this.loadimgidx=[];

		this.pausecheck=set_pause;
		this.mouseovercheck=0
		this.curcanvas="canvas_0";
		this.descriptions=!set_descriptions;
		this.auto=set_auto;
		this.fade=set_fade;
		this.counter=set_counter;
		this.ics=set_image_controls;
		this.jumpto=set_jumpto;
		this.set_controls=set_controls;
		this.ualt=set_use_alt;
		this.set_lightbox=set_lightbox
		this.utit=set_use_title;
		this.fadecolor=set_fadecolor;
		this.set_use_prefix= set_use_prefix;
		this.imbcolor=set_border_color;
		this.imbstyle=set_border_style;
		this.width=set_width? set_width : width? width : null
		this.width=this.width? this.width+this.imgborder*2 : null;
		this.height=set_height? set_height : height? height : null
		this.height=this.height? this.height+this.imgborder*2 : null;
		
		var ief='';
		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;';

		document.write('<table id="lightboxtable" align="left" cellpadding="0" cellspacing="0" border=0>');
		document.write('<tr height="400"><td>');
if(this.set_lightbox)document.write('<div id="lightboxbody">');		
	document.write('<div id="lightbox"> ');
		document.write('<div id="imageContainer">');		
			document.write('<div id="canvas_0" style="'+ief+'"><\/div>');
			document.write('<div id="canvas_1" style="'+ief+'"><\/div>');
			document.write('<div id="hoverNav">');
				document.write('<a href="#" id="prevLink" onclick="iss['+this.issid+'].changeimg(false, \'nav\'); changebutton(prev);"></a>');
				document.write('<a href="#" id="nextLink" onclick="iss['+this.issid+'].changeimg(true, \'nav\');" onmouseover="document.getElementByName(nextimage).style.background-color=#ccc;"></a>');
			document.write('<\/div>');
			//document.write('<div id="loading">');
			//document.write('<a href="#" id="loadingLink"><img src="items/loading.gif"></a>');
			//document.write('<\/div>');
		document.write('<\/div>');
	document.write('<\/div>');
document.write('<\/div>');

	//document.write('<div id="imageDataContainer">');
		//document.write('<div id="imageData">');
			//document.write('<div id="imageDetails">');
				//document.write('<span id="caption"></span>');
				//document.write('<span id="numberDisplay"></span>');
			//document.write('<\/div>');
	//document.write('<div id="bottomNav"><a href="#" id="bottomNavClose"><img src="items/close.gif" height=15></a></div>');
	//document.write('<\/div>');
	//document.write('<\/div>');
	//document.write('<\/div>');

if(this.set_lightbox)document.write('<\/div>');

		document.write('<\/td><\/tr>');
		document.write('<tr><td>');
		document.write('<table align="left" cellpadding="0" cellspacing="0" border=0>');
		document.write('<tr height=25 valign=middle>');
		
		if (this.set_controls){
				document.write('<td>');
				if(!this.ics && this.set_controls)
					document.write('<input id="prev'+this.issid+'" disabled type="button" value=" << " onclick="iss['+this.issid+'].changeimg(false, \'nav\');">\n'+(!this.auto? '&nbsp;&nbsp;&nbsp;' : ' <input id="gostp'+this.issid+'" type="button" value=" Stop " onclick="iss['+this.issid+'].gostop(this);">\n')+' <input id="next'+this.issid+'" disabled type="button" value=" >> " onclick="iss['+this.issid+'].changeimg(true, \'nav\');">');
				
				else if(this.ics && this.set_controls){
					var op=document.body.filters? ' style="filter:alpha(opacity=100);"' : ' style="opacity:'+(!this.auto? 0.99 : 0.45)+';"';
					document.write('<table align="left" cellpadding="0" cellspacing="0" width=50 border=0>');
					document.write('<tr valign="middle">');
					document.write('<td align="left" id=previmage><input'+op+' type="image" title="Previous" name="previmage" id="prev'+this.issid+'" src="'+previmg+'" onclick="iss['+this.issid+'].changeimg(false, \'nav\');"><\/td>');
					document.write('<td align="center">'+(!this.auto? '&nbsp;' : '<input title="Stop" type="image" id="gostp'+this.issid+'" src="'+(this.g_fPlayMode? playimg : stopimg)+'" onclick="iss['+this.issid+'].gostop(this);"><\/td>')+'');
					document.write('<td align="right"><input'+op+'  type="image" name="nextimage" title="Next" id="next'+this.issid+'" src="'+nextimg+'" onclick="iss['+this.issid+'].changeimg(true, \'nav\');"><\/td>');
					document.write('<\/tr><\/table>');		
				}
				else{
					this.set_controls=1;
				}
				document.write('</td>\n');
		}
		if(this.descriptions){
			document.write('<td align="left">'+this.set_use_prefix+'&nbsp;&nbsp;&nbsp;<span id="imgdsc'+this.issid+'">&nbsp;<\/span></td>\n');
		}
		if(this.counter){
			this.cpad=this.imgs.length.toString().length;
			document.write('<td align="left">Viewing Image: <b><span id="thecnt'+this.issid+'"><\/span><\/b> of<span>&nbsp;</span>&nbsp;<b>'+this.imgs.length+'<\/b><\/td>');
		}	
	}
	else{
		document.write('<td align="left"><img name="defaultslide'+this.issid+'" src="'+this.postimgs[0].src+'"><\/td>')
		}
		if (this.dom) //if modern browsers such as Firefox, IE5+
			this.startit()
		else{
			this.nextimgidx++
			setInterval("iss["+this.issid+"].rotateimg()", this.delay)
		}


//this.innerHTML = \'<div><b >'+(i+1)+'</b>\';"
	document.write('<\/tr><\/table><\/td><\/tr>');	
	document.write('<tr><td><table id=navi><tr><td>');
		for (var i=0;i< imageSrc.length -1; i++){
			if(i==0)document.write('<a href="#" onclick="iss['+this.issid+'].changeimg('+(i) +', \'go\');"   '+(this.set_lightbox? 'rel="lightbox"':'') + ' ><span id=icons_'+i+' style="color:#666666;">'+(i+1)+'<\/a></span>&nbsp;&nbsp;');
			else document.write('<a href="#" onclick="iss['+this.issid+'].changeimg('+(i) +', \'go\');"  '+(this.set_lightbox? 'rel="lightbox"':'') + ' ><span id=icons_'+i+'>'+(i+1)+'<\/a></span>&nbsp;&nbsp;');

			if(i==24)document.write('<br>');
			if(i<9)document.write('&nbsp;');
		}	
	document.write('<\/td><\/tr><\/table>');
	document.write('<\/td><\/tr><\/table>');
}

inter_slide.prototype.jumper=function(e){
	var key;
	if(typeof e=='object')
	key=e.keyCode? e.keyCode : e.which? e.which : 1;
	if(key&&key!==13)
	return;
	var num=typeof e=='number'? e : parseInt(this.go('goto'+this.issid).value);
	if(num<=this.imgs.length&&num>0){
	this.nextimgidx=num-2;
	this.changeimg(true, 'jump');
	}
}


function unmark (num) {
	for (var i = 0; i < imageSrc.length; i++) {
		if(i==num)document.getElementById('icons_'+num).style.color = '#666666';  	
		else document.getElementById('icons_'+i).style.color = '';
	}
}

function changebutton (num) {
	document.getElementById('previmage').style.border='1px solid gray';
}

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=="canvas_0")? "canvas_0" : "canvas_1"
		this.tempobj=this.go(this.nextcanvas)
		if(this.playing)
		this.changeimg()
	}
}

inter_slide.prototype.populateslide=function(picobj, picidx){
	
	if(document.getElementsByTagName){
		if(picobj.getElementsByTagName('a')[0] && picobj.getElementsByTagName('a')[0].onclick)
			picobj.getElementsByTagName('a')[0].onclick=null;
		if(picobj.getElementsByTagName('img')[0] && picobj.getElementsByTagName('img')[0].onload)
			picobj.getElementsByTagName('img')[0].onload=null;
	}
	picobj.style.backgroundColor=this.fadecolor? this.imgs.fadecolor : this.fadecolor? this.fadecolor : 'white';
	var slideHTML='';
	// slideHTML+='<div id="hoverNav">';
	//slideHTML+='<a href="#" id="prevLink" onclick="iss['+this.issid+'].changeimg(false, \'nav\');"></a>';
	//slideHTML+='<a href="#" id="nextLink" onclick="iss['+this.issid+'].changeimg(true, \'nav\');"></a>';
	//slideHTML+='<\/div>';
	//var slideHTML='<table cellpadding="0" cellspacing="0" width="850px" border="1"><tr>';
	//slideHTML+='<td align="left" valign="middle" style="background:transparent none;">';
	if (this.imgs[picidx][2]) slideHTML+=' <a href="" onclick="" '+(this.lightbox? 'rel="lightbox' : '')+'>'
	slideHTML+='<img id="theimg'+picidx+'_'+this.issid+'" src="'+(this.loadimgidx[picidx]&&typeof this.loadimgidx[picidx].complete=='boolean'&&this.loadimgidx[picidx].complete? this.loadimgidx[picidx].src : this.imgs[picidx][0])+'" alt="'+(this.ualt? imageName[picidx] : 'Slide Show Image')+'" title="'+(this.utit? this.imgs[picidx][1] : '')+'" '+(this.imbcolor&&!this.imgs[picidx].noborder? 'style="border:'+this.imgborder+'px '+(this.imbstyle? this.imbstyle : 'solid')+' '+this.imbcolor+';"' : 'border="'+(this.imgs[picidx].noborder? '0' : this.imgborder)+'"')+(!this.width||!this.height? ' onload="iss['+this.issid+'].imgload(this);"' : '')+'>'
	if (this.imgs[picidx][2]) slideHTML+='<\/a>'
	//slideHTML+='<\/td><\/tr><\/table>'
	picobj.innerHTML=slideHTML;

}

inter_slide.prototype.buttons=function(bool){
	if(this.set_controls)
	return;
	var next=this.go('next'+this.issid), prev=this.go('prev'+this.issid);
	next.disabled=prev.disabled=!bool;
	next.title=bool? 'next' : '';
	prev.title=bool? 'previous' : '';
	if(this.jumpto&&!this.ics)
	this.go('go'+this.issid).disabled=this.go('goto'+this.issid).disabled=!bool;
	if(this.ics){
	if(this.auto){
		var go=this.go('gostp'+this.issid)
		go.title=bool? 'Play' : 'Stop';
		go.src=bool? playimg : stopimg;
	}
	if(prev.filters && prev.parentNode)
		prev.parentNode.style.filter=next.parentNode.style.filter='alpha(opacity='+(bool? 100 : 45)+')';
	else if(prev.style.opacity && !prev.filters)
		prev.style.opacity=next.style.opacity=bool? 0.99 : 0.45;
	}
}

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('imageContainer').style;
	var c0=this.go('canvas_0').style;
	var c1=this.go('canvas_1').style;
	if(!this.width){
		this.width=el.width+this.imgborder*2;
		m.width = c0.width = c1.width = this.width+'px';
	}
	if(!this.height){
		this.height=el.height+this.imgborder*2;
		m.height = c0.height = c1.height = this.height+'px';
	}
	

}

inter_slide.prototype.changeimg=function(bool,nav){

	if(nav && nav=='go'){
		this.nextimgidx=bool;
		this.populateslide(this.tempobj, this.nextimgidx)
		this.rotateimg();
	}
	else{
	
		if(this.playing){
			this.buttons(false)
			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();
		}		
	}
		unmark(this.nextimgidx);	
}

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.mouseovercheck==1){
			var cacheobj=this
			clearTimeout(this.mousep)
			this.mousep=setTimeout(function(){cacheobj.rotateimg()}, 100)
			return;
		}
		if(this.fade)
			this.resetit()
		var crossobj=this.tempobj=this.go(this.curcanvas)
		crossobj.style.zIndex++
		var othercanvas=this.curcanvas=="canvas_0"? this.go("canvas_1") : this.go("canvas_0");
		othercanvas.style.zIndex=0;
		if(this.descriptions)
		this.go('imgdsc'+this.issid).innerHTML = this.imgs[this.keeptrack()][1];
		if(this.counter){
		var padit='';
		for (var p=0; p<this.cpad-(this.nextimgidx+1).toString().length; p++)
			padit+='<span style="visibility:hidden;">0</span>';
		this.go('thecnt'+this.issid).innerHTML = padit+(this.keeptrack()<this.imgs.length? this.keeptrack()+1 : 1);
		}
		if (this.jumpto)
		this.go('goto'+this.issid).value=this.keeptrack()<this.imgs.length? this.keeptrack()+1 : 1;
		this.jumperidx=this.keeptrack()<this.imgs.length? this.keeptrack()+1 : 1;
		var fadeobj=this
		clearInterval(this.fadeclear)
		this.fadeclear=setInterval(function(){fadeobj.fadepic()},50)
		this.curcanvas=(this.curcanvas=="canvas_0")? "canvas_1" : "canvas_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)
	if (this.pausecheck){ //if slideshow should pause onmouseover
		var cacheobj=this
		var crossobjcontainer=this.go("imageContainer")
		crossobjcontainer.onmouseover=function(){cacheobj.mouseovercheck=1}
		crossobjcontainer.onmouseout=function(){cacheobj.mouseovercheck=0}
	}
	this.rotateimg()
	if(this.auto)
		this.gostop();
	else if(!this.auto)
		this.gostop(this.go('gostp'+this.issid));
	else if(this.ics && document.body.filters){ //kludge for IE5.5 bug
		this.buttons(false);
	}
}

inter_slide.prototype.gostop=function(el){
	if(el)
	el.value=el.value==' Stop '? ' Play ' : ' Stop ';
	if(this.inprocess&&this.playing){
	clearTimeout(this.inprocess);
	this.nextimgidx-=this.faded;
	}
	this.playing=!this.playing;
	if(this.playing){
		clearInterval(this.fadeclear)
		this.faded=1
		this.changeimg(true);
	}
	else{
	var loadidx=(this.keeptrack()<this.imgs.length-1)? this.keeptrack()+1 : 0
	this.loadimgidx[loadidx]=new Image();
	this.loadimgidx[loadidx].src=this.imgs[loadidx][0];
	this.jumper(this.jumperidx? this.jumperidx : 0)
	this.buttons(true);
	}
}

inter_slide.prototype.keeptrack=function(){
	if(!document.getElementsByTagName)
	return this.nextimgidx;
	var canvases=[this.go('canvas_0'), this.go('canvas_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;
}