/////////////////////////////////////////////////////

function SetOpacity(object,opacityPct)
{
  // IE.
  object.style.filter = 'alpha(opacity=' + opacityPct + ')';
  // Old mozilla and firefox
  object.style.MozOpacity = opacityPct/100;
  // Everything else.
  object.style.opacity = opacityPct/100;
}

function ChangeOpacity(id,msDuration,msStart,fromO,toO)
{
  var element=document.getElementById(id);
  var opacity = element.style.opacity * 100;
  var msNow = (new Date()).getTime();
  opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
  if (opacity<0) 
    SetOpacity(element,0)
  else if (opacity>100)
    SetOpacity(element,100)
  else
  {
    SetOpacity(element,opacity);
    element.timer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")",1);
  }
}

function FadeIn(id)
{
  var element=document.getElementById(id);
  if (element.timer) window.clearTimeout(element.timer); 
  var startMS = (new Date()).getTime();
  element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",0,100)",1);
}

function FadeOut(id)
{
  var element=document.getElementById(id);
  if (element.timer) window.clearTimeout(element.timer); 
  var startMS = (new Date()).getTime();
  element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",100,0)",1);
}
/*
function FadeInImage(foregroundID,newImage,backgroundID)
{
  var foreground=document.getElementById(foregroundID);
  if (backgroundID)
  {
    var background=document.getElementById(backgroundID);
    if (background)
    {
      background.style.backgroundImage = 'url(' + foreground.src + ')';
      background.style.backgroundRepeat = 'no-repeat';
    }
  }
  SetOpacity(foreground,0);
  foreground.src = newImage[0];
  if (foreground.timer) window.clearTimeout(foreground.timer); 
  var startMS = (new Date()).getTime();
  foreground.timer = window.setTimeout("ChangeOpacity('" + foregroundID + "',1000," + startMS + ",0,100)",10);
}
*/
///////////////////////////////////////////////

function servicebanner(id,objname) {
	this.list = [];
	this.objname = objname;
	this.current = 0;
	this.imgid = id+'_img';
	this.divid = id+"_bg";
	this.linkid = id+"_link";
	this.timeoutID = 0;
	this.current_banner = [];	
}

servicebanner.prototype.fadeInImage = function() {
	var link = document.getElementById(this.linkid);
	var foreground=document.getElementById(this.imgid);
  	if (this.divid)
    {
    	var background=document.getElementById(this.divid);
    	if (background)
    	{
      		background.style.backgroundImage = 'url(' + foreground.src + ')';
      		background.style.backgroundRepeat = 'no-repeat';
    	}
  	}
  	SetOpacity(foreground,0);
  	foreground.src = this.current_banner[0];
	foreground.alt = this.current_banner[2];
	if (link) {
		link.href = this.current_banner[1];
		link.title = this.current_banner[2];
	}
  	if (foreground.timer) window.clearTimeout(foreground.timer); 
  	var startMS = (new Date()).getTime();
  	foreground.timer = window.setTimeout("ChangeOpacity('" + this.imgid + "',1000," + startMS + ",0,100)",10);
}
servicebanner.prototype.shift = function() {
	if(this.current == (this.count-1)) { this.current = 0; }
	else { this.current++; }
	this.current_banner = this.list[this.current];
}
servicebanner.prototype.add = function(val) {
	this.current = this.list.push(val);
	this.count = this.current;
	this.current = 0;
}
servicebanner.prototype.current_img = function() {
	return this.current_banner;
}
servicebanner.prototype.rotate = function() {
	this.shift();
	this.fadeInImage();
	//FadeInImage(this.imgid,this.current_img(),this.divid);
	this.timeoutID = setInterval(this.objname+".iteration()",6000);
}
servicebanner.prototype.iteration = function() {
	this.shift();
	this.fadeInImage();
//	FadeInImage(this.imgid,this.current_img(),this.divid);
}

///////////////////////////////////////////////

var banners_left = new servicebanner("leftbanner","banners_left");
banners_left.add(["http://www.host.ru/img/banner-hosting.gif","http://www.host.ru/prices/hosting/","виртуальный хостинг"]);
banners_left.add(["http://www.host.ru/img/banner-vmware.gif","http://www.hq.zenon.net/prices/vmware/","VMware серверы"]);

var banners_middle = new servicebanner("middlebanner","banners_middle");
banners_middle.add(["http://www.host.ru/img/banner-vps.gif","http://www.host.ru/prices/vps/","VPS серверы"]);
banners_middle.add(["http://www.host.ru/img/banner-service.gif","http://ok.ru/","сервисные услуги"]);

var banners_right = new servicebanner("rightbanner","banners_right");
banners_right.add(["http://www.host.ru/img/banner-colo.gif","http://www.host.ru/prices/collocation/","colocation и dedicated"]);
banners_right.add(["http://www.host.ru/img/banner-win.gif","http://www.hq.zenon.net/prices/winhosting/","Windows хостинг"]);


function startBannerRotation() {
//	var div = document.getElementById("leftbanner_bg");
	banners_left.timeoutID = setTimeout("banners_left.rotate()", 1000);
	banners_middle.timeoutID = setTimeout("banners_middle.rotate()", 2000);
	banners_right.timeoutID = setTimeout("banners_right.rotate()", 3000);
}

