/* UBUNTU-RU / Dmitry(a)Agafonov.pp.ru, 2007 */

var $ = function(o) {
	if (typeof o == 'string') {
		o = document.getElementById(o);
	}
	return o;
}
var	Animator = {
			timer : null,	
			queue : new Array(),
			fps : 50,	
			profile : function (val,type) {
				if (val<0) {val=0;}
				if (val>1) {val=1;}
				switch (type) {
					case "plain": return val;
					case "soft": return val+0.18*Math.sin(6.28318*val-3.14159);
					case "softin": return val*val*val*val;
					case "softout": a=1-val; return 1-a*a*a*a;
					case "funcy": return val+0.7*Math.sin(6.28318*val-3.14159);
					case "funcyin": a=-3; return val+a*val*(1-val);
					case "funcyout": a=3; return val+a*val*(1-val);
				}
				return val;
			},
			add : function(task) {
				if (typeof(task['time'])!='undefined') {
					task['steps']=task['time']*this.fps/1000;
				}
				if (typeof(task['profile'])=='undefined') {
					task['profile']='plain';
				}
				if (typeof(task['unit'])=='undefined') {
					task['unit']='';
				}
				if (typeof(task['wait'])=='undefined') {
					task['wait']=false;
				}
				if (task['prop']=='height' || task['prop']=='width') {
					task['obj'].style.overflow='hidden';
				}
				task['step']=0;
				this.queue.push(task);
				if (this.queue.length==1) {
					this.cycle();
				}
			},
			cycle : function() {
				if (Animator.queue.length>0) {
					var waiting=0;
					var ie = true && /MSIE/.test(navigator.userAgent);
					var N;
					var q;
					var obj;
					var eas;
					var val;
					for (N=0; N<Animator.queue.length; N++) {
						q=Animator.queue[N];
						if (q['wait']) { waiting++; }
						if (!q['wait'] || waiting<2) {
						obj=q['obj'];
						q['step']++;
						eas=Animator.profile(q['step']/q['steps'],q['profile']);
						val=Math.round((q['begval']+(q['endval']-q['begval'])*eas)*100)/100+q['unit'];
						switch (q['prop']) {
							case "top": obj.style.top=val; break;
							case "left": obj.style.left=val; break;
							case "width": obj.style.width=val; break;
							case "height": obj.style.height=val; break;
							case "right": obj.style.right=val; break;
							case "bottom": obj.style.bottom=val; break;
							case "opacity": if(ie) {obj.style.filter='alpha(opacity='+val*100+')'} else {obj.style.opacity=val}; break;
						}
						if (q['step']==q['steps']) {
							if (typeof q['oncomplete'] != 'undefined') {
								eval(q['oncomplete']);
							}
							Animator.queue.splice(N,1);
						}
						}
					}
					if (Animator.queue.length>0) {
						window.setTimeout(Animator.cycle,1000/Animator.fps);
					}
				}
			}	
};

var FX = {
		Hide : function(o) {
			$(o).style.display = 'none';
		},
		Show : function(o) {
			$(o).style.display = 'block';
		},
		Fade : function(o) {
			Animator.add({'obj':$(o),'prop':'opacity','begval':1,'endval':0,'time':100,'oncomplete':'hdMenu()'});
		},
		Appear : function(o) {
			Animator.add({'obj':$(o),'prop':'opacity','begval':0,'endval':1,'time':100});
		}
};

var cur=0;
var nw=1;

function shMenu(n) {
	if (n==cur) return false;
	nw=n;
	FX.Fade('SubMenu'+cur);
	$('Menu'+cur).className="Closed";
	return false;
}
function hdMenu() {
	if (nw==cur || nw==0) return;
	if (cur!=0) FX.Hide('SubMenu'+cur);
	FX.Appear('SubMenu'+nw);
	$('Menu'+nw).className="Open";
	FX.Show('SubMenu'+nw);
	cur=nw;
	return;
}
function insch(f) {
	if (f.value=="Поиск") f.value="";
}
function outsch(f) {
	if (f.value=="") f.value="Поиск";
}

if (location.href.substr(-3,2)=='SM') { /* XXX fix IE substr !!!*/
	nw = parseInt(location.href.substr(-1,1));
	if (nw<1 || nw>5) nw=1;
}
//FX.Fade('SubMenu1');
//FX.Fade('SubMenu2');
//FX.Fade('SubMenu3');
//FX.Fade('SubMenu4');
//FX.Fade('SubMenu5');
//setTimeout('hdMenu('+nw+')',500);

