var field1 = new Array('images/prdct_pic1.jpg','images/prdct_pic2.jpg','images/prdct_pic3.jpg','images/prdct_pic4.jpg','images/prdct_pic5.jpg','images/prdct_pic6.jpg','images/prdct_pic7.jpg','images/prdct_pic8.jpg','images/prdct_pic9.jpg','images/prdct_pic10.jpg');

ie = document.all ? 1:0;

function slideshow(name, targetDiv, slideWidth, slideHeight, slideArray, transTime, viewTime) {
	this.name = name;
	this.div = targetDiv;
	this.w = slideWidth;
	this.h = slideHeight;
	this.imgs = slideArray;
	this.transition = transTime;
	this.viewtime = viewTime;
	this.innerdiv = '';
	this.alpha = 0;
	this.index = 0;
	this.nextIndex = 1;
	this.timer = '';
	
	this.init = function() {
		this.innerdiv = 's'+this.name;
		document.getElementById(this.div).innerHTML = '<div id="s'+this.name+'" style="width: '+this.w+'px;height: '+this.h+'px;background: url('+this.imgs[0]+') no-repeat center center; opacity: 1; filter: Alpha(Opacity=100)"></div>';
		document.getElementById(this.div).style.background = 'url('+this.imgs[1]+') no-repeat center center';
		window.setTimeout("switchImg('"+this.name+"')", this.viewtime);
	}
	
	this.preload = function() {
		for (i=0;i<this.imgs.length;i++) {
			document.getElementById('midcontain').innerHTML += '<img src="'+this.imgs[i]+'" style="display: none">';
		}
	}
}

function switchImg(obj) {
	theObj = eval(obj);
	if (theObj.index == theObj.imgs.length) {
			theObj.index = 0;
		}
	theObj.nextIndex = theObj.index +1;
	if ((theObj.index +1) >= theObj.imgs.length) {
		theObj.nextIndex = 0;
	}
	document.getElementById(theObj.innerdiv).style.background = 'url('+theObj.imgs[theObj.index]+') no-repeat center center';
	document.getElementById(theObj.div).style.background = 'url('+theObj.imgs[theObj.nextIndex]+') no-repeat center center';
	theObj.index++;
	theObj.alpha = 100;
	setAlpha(obj, 100);
	fadeOut(theObj.name);
}

function fadeOut(obj) {
	theObj = eval(obj);
	theObj.alpha = getAlpha(theObj.name);
	if (theObj.alpha > 0) {
		theObj.alpha = theObj.alpha -5;
		setAlpha(theObj.name, theObj.alpha);
		theObj.timer = window.setTimeout("fadeOut('"+theObj.name+"')", theObj.transition);
	}
	else {
		window.setTimeout("switchImg('"+theObj.name+"')", theObj.viewtime);
	}
}

function setAlpha(obj, alpha) {
	theObj = eval(obj);
	if (ie) {
		document.getElementById(theObj.innerdiv).style.filter = 'Alpha (Opacity='+theObj.alpha+')';
	}
	else {
		document.getElementById(theObj.innerdiv).style.opacity = theObj.alpha / 100;
	}
}

function getAlpha(obj) {
	theObj = eval(obj);
	if (ie) {
		currAlpha = document.getElementById(theObj.innerdiv).filters.alpha.opacity;
	}
	else {
		currAlpha = document.getElementById(theObj.innerdiv).style.opacity * 100;
	}
	theObj.alpha = currAlpha;
	return currAlpha;
}

window.onload = function() {
	slide1 = new slideshow('slide1','img1',214,152,field1,50,3000);
	slide1.preload();
	slide1.init();
}