/**************************************************************************************************************************
* MultiFrame Image Slideshow script- ?Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
**************************************************************************************************************************/

function bannerSlide(bannerlist) {
	var _this 					= this;
	var imgArr 					= bannerlist;

	var innerDIV 				= 'banner';
	var imgDelay 				= 7000;					// Set pause between each image display (2000=2 second)
	var imgToShow 			= 1;						// Set how many images to show at once (must be less than total # of images above)
	var separater 			= "";						// Specify code to insert between each slide (ie: "<br>" to insert a line break and create a vertical layout), "" for none (or horizontal)
	var targetLink	 		= "_blank";			// Set optional link target to be added to all images with a link
	var borderWidth 		= 0;						// Set image border width
	var opacity 				= [1,1];				// Set opacity value of each image when it's "dimmed", and when it's not, respectively (1=100% opaque/normal).
																			// Change 0.2 to 0 to completely hide image when it's dimmed
	
	/*****************************************************************************************************************/
	
	var curValue = new Array();
	curValue['slide'] = 1;									// var to track current slide (total: slidestoreveal)
	curValue['index'] = 0;									// var to track current image (total: seqslides.length)
	curValue['first'] = 1;									// boolean to indicate whether this is the first cycle
	
	/*****************************************************************************************************************/
	
	this.getImg = function(img) {
		return iif(img['link'],'<a href="' + img['link'] + '" target="' + targetLink + '">','') + '<img src="' + img['img'] + '" border="' + borderWidth + '" style="filter:alpha(opacity=' + (opacity[0]*100) + ');-moz-opacity:' + opacity[0] + '">' + iif(img['link'],'</a>','');
	}
	
	this.illuminateSlide = function(idx, amt) {
		var obj = $id("seqslide_"+innerDIV+"_"+idx).getElementsByTagName("IMG")[0];
		try {
			if (obj.filters) obj.filters.alpha.opacity = (amt*100);
			else if (obj.style.MozOpacity) obj.style.MozOpacity = amt;
		} catch(e) {}
	}

	this.showImg = function() {
		if (curValue.slide < imgToShow) {
			if (!curValue.first) _this.changeImage(curValue.slide);
			_this.illuminateSlide(curValue.slide, opacity[1]);
			curValue.slide++;
		} else {
			curValue.first = 0;
			for (i=0;i<imgToShow;i++) _this.illuminateSlide(i, opacity[0]);
			_this.changeImage(0);
			_this.illuminateSlide(0, opacity[1]);
			curValue.slide=1;
		}
	}

	this.changeImage = function(idx) {
		if(!isEmpty(imgArr[curValue.index])) {
			$id("seqslide_"+innerDIV+"_"+idx).innerHTML = _this.getImg(imgArr[curValue.index]);
			curValue.index++;
			if (curValue.index >= sizeof(imgArr)) curValue.index = 0;
		}
	}

	this.show = function(div) {
		if (document.getElementById){
			if(!isEmpty(imgArr)) {
				innerDIV = div;
				// alert(innerDIV);
				for (var i=0;i<imgToShow;i++) $id(innerDIV).innerHTML = '<span id="seqslide_'+innerDIV+'_'+i+'" class="seqslidestyle">'+_this.getImg(imgArr[i])+'</span>'+separater;
				curValue.index = imgToShow;
				_this.illuminateSlide(0,opacity[1]);
				setInterval(_this.showImg,imgDelay);
			}
		}
	}
}