//Плавное появление/затухание объектов
//Версия 1.001
//Дата 17.05.2009~
// .Show(ID объекта, [правило]) - появление
// .Hide(ID объекта) - затухание
// .addRule(Имя, размер шага, время шага, min, max) - добавление правила показа
// .getProperties() - Устанавливает служебные параметры (служебная)
// .Set(ID объекта, значение прозрачности(0-100)) - Устанавливает значение прозрачности конкретному объекту
// .Step(ID объекта, напвление) - Шаг показа (служебная)

Clarity = {
	stepSize: 10, //max 100 - по умолчанию
	stepTime: 10, // - по умолчанию
	Objects: [],
	Rules: [],
	Property: null,
	MaxV: null,


	addRule: function(Name,stepSize,stepTime,startV,stopV){
		this.Rules[Name] = {
				stepSize:stepSize,
				stepTime:stepTime,
				startV:startV,
				stopV:stopV
			};
	},

	getProperties: function(){
		p = false;
		if(typeof document.body.style.opacity == 'string') p = 'opacity';
		else if(document.body.filters) p = 'filter';
		this.Property =  p;
		this.MaxV = (p == 'filter'?100:1);
	},
	
	Set: function(ObjId,Value){
		if(!this.Property)this.getProperties();
		Obj = document.getElementById(ObjId);	
		alpha = this.Property == 'filter'?(Obj.filters['alpha'] || Obj.style.alpha):Obj.style;
		
		Opacity = Value/100*this.MaxV;

		if(alpha)alpha.opacity = Opacity;
		else Obj.style.filter += "alpha(opacity="+Opacity+")";
	},


	Step: function(ObjId,Direction){
		with(this.Objects[ObjId]){
			Alpha.opacity = Number(Alpha.opacity) + (Direction*Rule.stepSize/100*this.MaxV);
			if((Direction > 0 && Alpha.opacity >= this.MaxV) || (Direction < 0 && Alpha.opacity <= 0))clearInterval(IntervalId);
			if(Direction < 0 && Alpha.opacity <= 0) Obj.style.display = 'none';
		}
	},
	
	Show: function(ObjId,RuleName){
		RuleName = (!RuleName)?'st':RuleName;
		if(!this.Objects[ObjId]){
			Obj = document.getElementById(ObjId);
			if(!this.Property)this.getProperties();
	
			alpha = (this.Property == 'filter'?(Obj.filters['alpha'] || Obj.style.alpha):Obj.style);
			if(alpha)alpha.opacity = 0;
			else Obj.style.filter += "alpha(opacity=0)";
		
		
			Obj.style.display = 'block';
	
			this.Objects[ObjId] = {
				Obj:Obj,
				Alpha:(this.Property == 'filter'?(Obj.filters['alpha'] || Obj.style.alpha):Obj.style),
				IntervalId: setInterval('Clarity.Step("'+ObjId+'",1);',this.Rules[RuleName].stepTime),
				Rule:this.Rules[RuleName]
			};	
		}else{
			with(this.Objects[ObjId]){
				Obj.style.display = 'block';
				Alpha.opacity = 0;
				clearInterval(IntervalId);	
				IntervalId = setInterval('Clarity.Step("'+ObjId+'",1);',Rule.stepTime);
			}
		}
	},
	
	Hide: function(ObjId){
		with(this.Objects[ObjId]){
			if(IntervalId) clearInterval(IntervalId);
			IntervalId = setInterval('Clarity.Step("'+ObjId+'",-1);',this.stepTime);
		}
	}
}

Clarity.addRule('st',10,10,0,100);
