
var AMvBanner = new Object({
	'data':new Array(),
//'preload': new Array(),
	'createBanner': function (id, banners_, timeout, start_index, onchange, align) {
	//start_index = 0;// Temporary
	//AMv.clearElement(id);
	if(!align)
		align = 'center top';
	var next = start_index+1;
	
	var bg = document.getElementById(id).style.backgroundImage;
	//var bg_ = bg.substr(4, bg.length-5);
	var w = document.getElementById(id).offsetWidth;
	var h = document.getElementById(id).offsetHeight;
	//alert(w)
	var top_img = document.createElement('DIV');
	var mask = document.createElement('DIV');
	this.data[id] = new Object({
		'banners': banners_,
		'timeout': timeout,
		'w':w,
		'h':h,
		//'link': '?'+((w_or_h=='h')?'h='+h:'w='+w)+'&c=',
		'current_index': start_index,
		'current_opacity': 1,
		'top_img': top_img,
		'mask': mask,
		'preload': new Array(),
		'preload_data': new Array(),
		'onChange': onchange,
		'align': align
	});
	/*if(next == banners_.length)
	*         next = 0;*/
	//alert(bg);
	mask.style.backgroundImage = bg;
	mask.style.width = w+'px';
	mask.style.height = h+'px';
	mask.style.position = 'relative';
	mask.style.marginTop = '-'+h+'px';
	mask.style.backgroundRepeat = 'no-repeat';
	mask.style.backgroundPosition = align;
	top_img.style.width = w+'px';
	top_img.style.height = h+'px';
	top_img.style.backgroundRepeat = 'no-repeat';
	top_img.style.backgroundPosition = align;
	document.getElementById(id).appendChild(top_img);
	document.getElementById(id).appendChild(mask);
	document.getElementById(id).style.backgroundImage = 'url('+this.data[id].banners[start_index][0]+')';
	document.getElementById(id).style.backgroundRepeat = 'no-repeat';
	document.getElementById(id).style.backgroundPosition = align;
	this.data[id].preload[start_index] = true;
	this.data[id].onChange();
	//setTimeout('AMvBanner.changeBannerStart("'+id+'")', timeout);
	this.startNextTimeout(id, true);
	//var imgs = new Array();
	/*for(var i = 0; i < this.data[id].banners.length; i++) {
	*         this.data[id].preload_data[i] = new Image(w,h);
	*         this.data[id].preload_data[i].amvid = id;
	*         this.data[id].preload_data[i].amvindex = i;
	*         this.data[id].preload_data[i].onload = function () {
	*             AMvBanner.data[this.amvid].preload[this.amvindex] = true;
	*             //alert(this.amvindex);
	}
	this.data[id].preload[i] = false;
	this.data[id].preload_data[i].src='/images/banner_'+this.data[id].banners[i][0]+'.'+this.data[id].banners[i][2]+this.data[id].link+this.data[id].banners[i][1];
	//alert(p.amvid);
	}*/
	},
	'startNextTimeout': function (id, doPreload) {
		if(doPreload) {
			var next = this.getNextIndex(id);
			this.data[id].preload_data[next] = new Image(this.data[id].w, this.data[id].h);
			this.data[id].preload_data[next].amvid = id;
			this.data[id].preload_data[next].amvindex = next;
			this.data[id].preload[next] = false;
			this.data[id].preload_data[next].onload = function () {
				AMvBanner.data[this.amvid].preload[this.amvindex] = true;
				//alert(this.amvindex);
			}
			this.data[id].preload_data[next].src = this.data[id].banners[next][0];
		}
		setTimeout('AMvBanner.changeBannerStart("'+id+'")', this.data[id].timeout);
	},
	'getNextIndex': function (id) {
		var next = this.data[id].current_index+1;
		if(next >= this.data[id].banners.length) {
			next = 0;
		}
		return next;
	},
	'changeBannerStart': function (id) {
		var d = this.data[id];
		var next = this.getNextIndex(id);/*d.current_index+1;
		if(next >= d.banners.length) {
			next = 0;
		}*/
		if(this.data[id].preload[next]) {
			//document.getElementById(id).style.backgroundImage = 'url(/images/banner_'+d.banners[next][0]+'.'+d.banners[next][2]+d.link+d.banners[next][1]+')';
			
			d.current_index = next;
			d.current_opacity = 0;
			//alert(d.current_opacity)
			//alert(1);
			d.top_img.style.backgroundImage = 'url('+d.banners[next][0]+')';
			d.top_img.style.backgroundPosition = d.align;
			d.top_img.style.backgroundColor = '#FFF';
			//d.top_img.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
			//d.top_img.style.filter = 'alpha(opacity=20)';
			//d.top_img.filters.alpha.opacity = 20;
			//alert('url(/images/banner_'+d.banners[next][0]+'.'+d.banners[next][2]+d.link+d.banners[next][1]+')')
			this.changingBanner(id);
			this.data[id].onChange();
		} else {
			this.startNextTimeout(id, false);
			//setTimeout('AMvBanner.changeBannerStart("'+id+'")', this.data[id].timeout);
		}
		},
		'changingBanner': function (id) {
			var d = this.data[id];
			var delta = 0.05;
			d.current_opacity+=delta;
			if(d.current_opacity > 1) {
				document.getElementById(id).style.backgroundImage = d.top_img.style.backgroundImage;
				//setTimeout('AMvBanner.changeBannerStart("'+id+'")', d.timeout);
				this.startNextTimeout(id, true);
			} else {
				
				//d.top_img.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=40)';
				//alert(d.top_img.style.filter);
				d.top_img.style.opacity = d.current_opacity;
				d.top_img.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+(Math.round(100*d.current_opacity))+')';
				
				//d.top_img.style.filter = 'alpha(opacity='+(Math.round(100*d.current_opacity))+')';
				//d.top_img.style.filter = 'filter:progid:DXImageTransform.Microsoft.Alpha(opacity='+(Math.round(100*d.current_opacity))+')';
				
				//document.write(d.top_img.style.filter);
				//setTimeout('AMvBanner.changeBannerStart("'+id+'")', d.timeout);
				setTimeout('AMvBanner.changingBanner("'+id+'")', 30);
			}
		},
		'onChange': function(id, func) {
			this.data[id].onChange = func;
		}
	});
