var vz9_img = new Array();
var vz9_i;
var vz9_first = -1;
var vz9_last = -1;
var vz9_speed_ms = 5;
var vz9_speed_px = 11;
var vz9_width_max = 200;
var vz9_width_min = 90;
var vz9_padding_top = 0;
var vz9_padding_left = 0; 
var vz9_vertical = 1;
var vz9_onload = null;

function nameByWidth(name, width)
{
	if (!(slash = name.lastIndexOf("/") + 1)) return name;
	dir = name.substr(0, slash);
	file = name.substr(slash);
	s = file.split(".");
	return dir + s[0] + '.' + width + 'x' + width + '.' + s[s.length - 1];
}

var vz9_image_change = function (image_i) {
	var image = vz9_img[image_i];
	var width = parseInt(image.style.width) + image.speed;
	var top = parseInt(image.style.top) + image.top;
	var left = parseInt(image.style.left) + image.left;

	if (width < vz9_width_min) {
		image.setAttribute('src', nameByWidth(image.src, vz9_width_min));
		image.parentNode.parentNode.style.position = 'static';
		image.style.position = 'static';
		clearInterval(image.interval);
	} else if (width > vz9_width_max) {
		clearInterval(image.interval);
	} else {
		image.parentNode.parentNode.style.zIndex = width >= vz9_width_max / 2 ? 18000 : 1;
		
		image.style.width = width + 'px';
		image.style.height = width + 'px';
		image.style.top = top + 'px';
		image.style.left = left + 'px';
	}
}
vz9_onload = window.onload;

window.onload = function() {

	if (null !=  vz9_onload)

		vz9_onload();
	vz9_img = document.getElementsByTagName('img');
	for (vz9_i = 0; vz9_i < vz9_img.length; vz9_i++) {
		if (vz9_img[vz9_i].className == 'adv220x90') {
			vz9_img[vz9_i].onmouseover = function () {
				vz9_setOpacity(this, 1.0);
				};
			vz9_img[vz9_i].onmouseout = function () {
				vz9_setOpacity(this, 0.4);
				};				
		}
		if (vz9_img[vz9_i].parentNode.className == 'adv90') {
			if (vz9_vertical) {
				if (vz9_first == -1 && vz9_img[vz9_i].offsetTop < vz9_width_max/2 + 10) vz9_first = vz9_i;
				if (vz9_last == -1 && vz9_img[vz9_i].offsetTop + vz9_width_max > document.height + 10) vz9_last = vz9_i;
			}
			
			vz9_first = -1;
			vz9_last = -1;
			
			vz9_img[vz9_i].style.width = vz9_width_min + 'px';
			vz9_img[vz9_i].style.height = vz9_width_min + 'px';
			vz9_img[vz9_i].parentNode.parentNode.style.top = 0 + 'px';
			vz9_img[vz9_i].parentNode.parentNode.style.left = 0 + 'px';
			vz9_img[vz9_i].style.top = vz9_padding_top + 'px';
			vz9_img[vz9_i].style.left = vz9_padding_left + 'px';
			vz9_img[vz9_i].xi = vz9_i;
			vz9_setOpacity(vz9_img[vz9_i], 0.4);

			//big = new Image();
			//big.src = nameByWidth(vz9_img[vz9_i].src, vz9_width_max);
			vz9_img[vz9_i].onmouseover = function () {
				vz9_setOpacity(this, 1.0);
				this.qqq = 1;
				this.speed = vz9_speed_px;
				this.parentNode.parentNode.style.position = 'relative';
				this.style.position = 'absolute';
				this.className = 'on-top';
				vz9_first = -1;
				vz9_last = -1;
			    var node = this;
				while (node != null)
				{
					if (node.className == "adv_wrap")
					{
						var d = this.parentNode.parentNode;
						var gap = d.offsetTop - node.offsetTop;
						if (gap < (vz9_width_max/2 + 10)) vz9_first = this.xi;
						if ((d.offsetTop + d.offsetHeight + (vz9_width_max-d.offsetHeight)/2) > (node.offsetTop + node.offsetHeight)) vz9_last = this.xi;

					}
						
					node =  node.parentNode;
				}
				
				
				
				if (this.xi == vz9_first) this.top = -1;
				else if (this.xi == vz9_last) this.top = -(vz9_speed_px - 1);
				else this.top = -Math.round(vz9_speed_px/2);

				if (vz9_vertical) this.left = 1; //Math.round(vz9_speed_px/8);
				else this.left = -Math.round(vz9_speed_px/2);

				if (this.interval) clearInterval(this.interval);
				this.src = nameByWidth(this.src, vz9_width_max);
				this.interval = setInterval("vz9_image_change("+this.xi+")", vz9_speed_ms);
				
			};
			vz9_img[vz9_i].onmouseout = function () {
				this.qqq = 0;
				this.speed = -vz9_speed_px;
				if (this.xi == vz9_first) this.top = 1;
				else if (this.xi == vz9_last) this.top = (vz9_speed_px - 1);
				else this.top = Math.round(vz9_speed_px/2);

				if (vz9_vertical) this.left = -1;//Math.round(vz9_speed_px/8);
				else this.left = Math.round(vz9_speed_px/2);
				
				if (this.interval) clearInterval(this.interval);
				this.interval = setInterval("vz9_image_change("+this.xi+")", vz9_speed_ms);
				vz9_setOpacity(this, 0.4);
			};
		}
	}
}

function vz9_setOpacity(element, value)
{
	var opType = vz9_getOpacityType();
	if (typeof element == 'string')
	{
		element = document.getElementById(element);
	}
	if (!element || !opType)
	{
		return false;
	}
	if (opType == 'filter')
	{
		value *= 100;
		var alpha = element.filters['DXImageTransform.Microsoft.alpha'] || element.filters.alpha;
		if (alpha)
		{
			alpha.opacity = value;
		}
		else
		{
			element.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity=" + value + ")";
		}
	}
	else
	{
		element.style[opType] = value;
	}
	return true;
}

function vz9_getOpacityType()
{
	if (typeof document.body.style.opacity == 'string')
	{
		return 'opacity';
	}
	else if (typeof document.body.style.MozOpacity == 'string')
	{
		return 'MozOpacity';
	}
	else if (typeof document.body.style.KhtmlOpacity == 'string')
	{
		return 'KhtmlOpacity';
	}
	else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1] >= 5.5)
	{
		return 'filter';
	}
	return false;
}

