// "getElementsByClassName" РЅРµ РѕРїСЂРµРґРµР»РµРЅ IE, 
// С‚Р°Рє С‡С‚Рѕ СЌС‚РѕС‚ РјРµС‚РѕРґ РјРѕР¶РЅРѕ СЂРµР°Р»РёР·РѕРІР°С‚СЊ РІ JavaScript 
function findByClass(str, node) {
 
    node || (node = document);
 
    if (node.getElementsByClassName) {
        return node.getElementsByClassName(str);
    } else {
        var nodeList = node.getElementsByTagName('*'),
            nodeListIndex = 0,
            classList = (' '+str.split(/\s+/).join(' ; ')+' ').split(';'),
            classListIndex,
            result = [],
            className,
            index;
 
        while (node = nodeList[nodeListIndex++]) {
            index = 0;
            classListIndex = 0;
            while (className = classList[classListIndex++]) {
                if ((' ' + node.className + ' ').indexOf(className) >= 0) {
                    index++;
                }
            }
            if (index == classList.length) {
                result.push(node);
            }
        }
        return result;
    }
}

    function getElementHeight(e){
        return Math.max(
            e.offsetHeight,
            e.clientHeight
        );

    };


var TINY={};

function T$(i){return document.getElementById(i)}
function T$$(e,p){return p.getElementsByTagName(e)}
function T$$$(e,p){return findByClass(e,p)}

TINY.accordion=function(){
	
	function slider(n){this.n=n; this.a=[]}
	slider.prototype.init=function(t,e,m,o,k,elem_class){
		var a=T$(t), i=s=0, n=a.childNodes, l=n.length; this.s=k||0; this.m=m||0;
		for(i;i<l;i++){
			var v=n[i];
			if(v.nodeType!=3){
				this.a[s]={}; this.a[s].h=h=T$$(e,v)[0]; this.a[s].c=c=T$$$(elem_class,v)[0]; h.onmouseover=new Function(this.n+'.pr(0,'+s+')');
				if(o==s){h.className='selected'; c.style.height='auto'; c.d=1}else{c.style.height=0; c.d=-1} s++
			}
		}
		this.l=s;
		a.style.height = getElementHeight(a)+'px';
	};
	
	slider.prototype.pr=function(f,d){
		// Select what close, what open
		var close_i = -1, open_i = -1, i =0;
		var h, c, k;
		for(i=0;i<this.l;i++)
		{
			h=this.a[i].h;
			c=this.a[i].c;
			k=c.style.height;
			k=k=='auto'?1:parseInt(k);
			if((k!=1&&c.d==-1)&&(f==1||i==d))
			{
				open_i = i;
			}
			else if(k>0&&(f==-1||this.m||i==d))
			{
				close_i = i;
			}
		}
		
		if( close_i != open_i && open_i >= 0 )
		{
			for(i=0;i<this.l;i++)
			{
				h=this.a[i].h;
				c=this.a[i].c;
				k=c.style.height;
				k=k=='auto'?1:parseInt(k);
				clearInterval(c.t);
				if( i == open_i )
				{
					// alert('РѕС‚РєСЂС‹С‚Р°СЏ');
					c.style.height=''; c.m=c.offsetHeight; c.style.height=k+'px'; c.d=1; h.className='selected'; su(c,1)
				}
				else //if(i == close_i)
				{
					// alert('Р·Р°РєСЂС‹С‚Р°СЏ');
					c.d=-1; h.className=''; su(c,-1)
				}
			}
		}
		
	};
	function su(c){c.t=setInterval(function(){sl(c)},20)};
	function sl(c){
		var h=c.offsetHeight, d=c.d==1?c.m-h:h; c.style.height=h+(Math.ceil(d/5)*c.d)+'px';
		c.style.opacity=h/c.m; c.style.filter='alpha(opacity='+h*100/c.m+')';
		if((c.d==1&&h>=c.m)||(c.d!=1&&h==1)){if(c.d==1){c.style.height='auto'} clearInterval(c.t)}
	};
	return{slider:slider}
}();


TINY.slider=function(){
	function slide(n,p){this.n=n; this.init(p)}
	slide.prototype.init=function(p){
		var s=this.x=T$(p.id), u=this.u=T$$('ul',s)[0], c=this.m=T$$('li',u), l=c.length, i=this.l=this.c=0; this.b=1;
		if(p.navid&&p.activeclass){this.g=T$$('li',T$(p.navid)); this.s=p.activeclass}
		this.a=p.auto||0; this.p=p.resume||0; this.r=p.rewind||0; this.e=p.elastic||false; this.v=p.vertical||0; s.style.overflow='hidden';
		for(i;i<l;i++){if(c[i].parentNode==u){this.l++}}
		if( p.mod ){this.mod = p.mod;}else{this.mod=this.l;}		
		if(this.v){;
			u.style.top=0; this.h=p.height||c[0].offsetHeight; u.style.height=(this.l*this.h)+'px'
		}else{
			u.style.left=0; this.w=p.width||c[0].offsetWidth; u.style.width=(this.l*this.w)+'px'
		}
		this.nav(p.position||0);
		if(p.position){this.pos(p.position||0,this.a?1:0,1)}else if(this.a){this.auto()}
		if(p.left){this.sel(p.left)}
		if(p.right){this.sel(p.right)}
	},
	slide.prototype.auto=function(){
		this.x.ai=setInterval(new Function(this.n+'.move(1,1,1)'),this.a*1000)
	},
	slide.prototype.move=function(d,a){
		var n=this.c+d;
		if(this.r){n=d==1?n==this.l?0:n:n<0?this.l-1:n}
		this.pos(n,a,1)
	},
	slide.prototype.pos=function(p,a,m){
		var v=p; clearInterval(this.x.ai); clearInterval(this.x.si);
		if(!this.r){
			if(m){
				
				if(p==-1||(p!=0&&Math.abs(p)%this.mod==0)){
					this.b++;
					for(var i=0;i<this.l;i++){this.u.appendChild(this.m[i].cloneNode(1))}
					this.v?this.u.style.height=(this.l*this.h*this.b)+'px':this.u.style.width=(this.l*this.w*this.b)+'px';
				}
				if(p==-1||(p<0&&Math.abs(p)%this.l==0)){
					this.v?this.u.style.top=(this.l*this.h*-1)+'px':this.u.style.left=(this.l*this.w*-1)+'px'; v=this.l-1
				}
			}else if(this.c>this.l&&this.b>1){
				v=(this.l*(this.b-1))+p; p=v
			}
		}
		var t=this.v?v*this.h*-1:v*this.w*-1, d=p<this.c?-1:1; this.c=v; var n=this.c%this.l; this.nav(n);
		if(this.e){t=t-(8*d)}
		this.x.si=setInterval(new Function(this.n+'.slide('+t+','+d+',1,'+a+')'),10)
	},
	slide.prototype.nav=function(n){
		if(this.g){for(var i=0;i<this.l;i++){this.g[i].className=i==n?this.s:''}}
	},
	slide.prototype.slide=function(t,d,i,a){
		var o=this.v?parseInt(this.u.style.top):parseInt(this.u.style.left);
		if(o==t){
			clearInterval(this.x.si);
			if(this.e&&i<3){
				this.x.si=setInterval(new Function(this.n+'.slide('+(i==1?t+(12*d):t+(4*d))+','+(i==1?(-1*d):(-1*d))+','+(i==1?2:3)+','+a+')'),10)
			}else{
				if(a||(this.a&&this.p)){this.auto()}
				if(this.b>1&&this.c%this.l==0){this.clear()}
			}
		}else{
			var v=o-Math.ceil(Math.abs(t-o)*.1)*d+'px';
			this.v?this.u.style.top=v:this.u.style.left=v
		}
	},
	slide.prototype.clear=function(){
		var c=T$$('li',this.u), t=i=c.length; this.v?this.u.style.top=0:this.u.style.left=0; this.b=1; this.c=0;
		for(i;i>0;i--){
			var e=c[i-1];
			if(t>this.l&&e.parentNode==this.u){this.u.removeChild(e); t--}
		}
	},
	slide.prototype.sel=function(i){
		var e=T$(i); e.onselectstart=e.onmousedown=function(){return false}
	}
	return{slide:slide}
}();
