function RotatE(){
	this.imagePoz = 0;
	this.pocet = 0;
	this.rotator = 0;
	this.rotatorN = 0;
	this.description = false;
	this.rozmer;
}

RotatE.prototype.rotateInit = function(divA, time, instance, firstId, manual, cycle){
	this.doba = time * 1000;
	this.instance = instance;
	this.firstId = firstId;
	this.manual = typeof(manual) != 'undefined' ? manual : false;
	this.cycle = typeof(cycle) != 'undefined' ? cycle : true;

	var divA = document.getElementById(divA);
	this.obr = new Array();
	this.title = new Array();
	this.start = true;

	var allIMG = divA.getElementsByTagName('IMG');
	var limit = allIMG.length;
	for(var i = 0; i < limit; i++)
	{
		if (allIMG[i].className.match(/attachmentImage/))
		{
			this.obr[this.imagePoz]= new Image();
			this.obr[this.imagePoz].src = allIMG[i].src;
			this.title[this.imagePoz] = allIMG[i].title;
			if(this.imagePoz == 0)
				allIMG[i].id = this.firstId;
			this.imagePoz++;
		}
	}
	var allDIV = divA.getElementsByTagName('DIV');
	var firstNo = false;
	for(var i = 0; i < allDIV.length; i++)
	{
		if (allDIV[i].className.match(/attachment/)) {
			if(firstNo)	allDIV[i].style.display = "none";
			else {
				allDIV[i].id = this.firstId+"Div";
				firstNo = true;
				var childNodeC = document.getElementById(this.firstId+"Div");
				var createDiv = document.createElement("div");
				createDiv.id = this.firstId+"Img";
				if(childNodeC.getElementsByTagName("DIV")[0] !== undefined){
					if(childNodeC.getElementsByTagName("DIV")[0].className.match(/description/))
					this.description = true;
				}
				if(childNodeC.getElementsByTagName("A")[0] !== undefined){
					var nodeC = childNodeC.getElementsByTagName("A")[0];
					nodeC.parentNode.replaceChild(createDiv, nodeC);
					createDiv.appendChild(nodeC);
				}
				else if(childNodeC.getElementsByTagName("IMG")[0] !== undefined){
					var nodeC = childNodeC.getElementsByTagName("IMG")[0];
					nodeC.parentNode.replaceChild(createDiv, nodeC);
					createDiv.appendChild(nodeC);
				}
			}
		}
	}
	this.pocet = this.obr.length;
	if(!this.manual)
	 this.rotate_rot();
	else
	 this.rotate_man();
}

RotatE.prototype.rotate_rot = function(){
  	   if (this.rotator == this.pocet)
  		    {this.rotator=0;}
  	   if (!this.start)
  		    this.rotatorN = this.rotatorN + 1;
  	   if (this.rotatorN == this.pocet)
  		  {this.rotatorN=0;}

	if (this.start){
		this.opacity(0);
		this.oldImgO(0);
	}
	else {
	  this.opacity(3000);
		this.oldImgO(0);
	}
	window.setTimeout(this.instance+'.rotate_rot();', this.doba);
	if(this.description){
		if(document.getElementById(this.firstId).parentNode.tagName.match(/(?=A)/))
			document.getElementById(this.firstId).parentNode.parentNode.nextSibling.firstChild.nodeValue = this.title[this.rotatorN];
		else
			document.getElementById(this.firstId).parentNode.nextSibling.firstChild.nodeValue = this.title[this.rotatorN];
	}
	document.getElementById(this.firstId).src = this.obr[this.rotator].src;
	document.getElementById(this.firstId).title = this.title[this.rotatorN];
  document.getElementById(this.firstId+"Img").style.backgroundImage = "url(" + this.obr[this.rotatorN].src + ")";
  document.getElementById(this.firstId+"Img").style.backgroundRepeat = 'no-repeat';
	if (this.start){
		this.start = false;
	}
	else {
		this.rotator = this.rotator + 1;
  }
}

RotatE.prototype.opacity = function(millisec){
	//speed for each frame
	var speed = Math.round(millisec / 100);

	for(var i = 0; i <= 100; i++) {
		window.setTimeout(this.instance+'.changeOpac(' + i + ')',(i * speed));
	}
}

RotatE.prototype.changeOpac = function(opacity){
	//this.newImgO(opacity);
	this.oldImgO(opacity);
}

RotatE.prototype.newImgO = function(opacity){
	var newImg = document.getElementById(this.firstId+"Img").style;
	newImg.opacity = (opacity / 100);
	newImg.MozOpacity = (opacity / 100);
	newImg.KhtmlOpacity = (opacity / 100);
	newImg.filter = "alpha(opacity=" + opacity + ")";
}
RotatE.prototype.oldImgO = function(opacity){
	var oldImg = document.getElementById(this.firstId).style;
	oldImg.opacity = (1-(opacity / 100));
	oldImg.MozOpacity = (1-(opacity / 100));
	oldImg.KhtmlOpacity = (1-(opacity / 100));
	oldImg.filter = "alpha(opacity=" + (100-opacity) + ")";
}

RotatE.prototype.rotate_man = function(){
  if (this.start){
		this.start = false;
		this.rotator = 0;
		if (this.pocet == 1)
	     document.getElementById('attachRotateNavNext').style.visibility  = 'hidden';
	  if ((this.pocet == 1  && this.cycle) || !this.cycle)
       document.getElementById('attachRotateNavPrev').style.visibility  = 'hidden';
	}
	document.getElementById(this.firstId).src = this.obr[this.rotator].src;
}

RotatE.prototype.nextImg = function(){

  this.rotator = this.rotator + 1;
  if (this.rotator == this.pocet - 1 && !this.cycle)
      document.getElementById('attachRotateNavNext').style.visibility  = 'hidden';
  if (this.rotator == this.pocet)
      this.rotator = 0;
  document.getElementById('attachRotateNavPrev').style.visibility  = 'visible';
  this.rotate_man();
}

RotatE.prototype.prevImg = function(){
  this.rotator = this.rotator - 1;
  if (this.rotator == 0 && !this.cycle)
      document.getElementById('attachRotateNavPrev').style.visibility  = 'hidden';
  if (this.rotator == -1)
      this.rotator = this.pocet -1;
  document.getElementById('attachRotateNavNext').style.visibility  = 'visible';
  this.rotate_man();
}