/*
=====================================================
 Limkokwing University of Creative Technology
-----------------------------------------------------
 http://www.limkokwing.net/
=====================================================
 Template: javascripts/slider
-----------------------------------------------------
 Purpose: Accordion slider in News - Media Centre
=====================================================

*/

var slider=function(){
	var array=[];
	var speed=5;
	var timer=10;
	return{
		init:function(t,c){
			var s,ds,l,i;
			s=document.getElementById(t); ds=s.getElementsByTagName('div'); l=ds.length; i=0;
			if(s){
				for(i=0;i<l;i++){
					var d,did; d=ds[i]; did=d.id;
					if(did.indexOf("header")!=-1){
						d.onclick=new Function("slider.process(this)");
					}else if(did.indexOf("content")!=-1){
						array.push(did.replace('content-',''));
						d.maxh=d.offsetHeight;
						if(c==1&&i==1){
							d.style.display='block';
						}else{
							d.style.height='0px';
							d.style.display='none';
						}
					} 
				}
			}
		},
		process:function(d){
			var cl,i; cl=array.length; i=0;
			for(i;i<cl;i++){
				var s,h,c,cd;
				s=array[i]; h=document.getElementById('header-'+s);
				c='content-'+s; cd=document.getElementById(c);
                                h = $(h);
				clearInterval(cd.timer);
				h.removeClassName("active");
				if(h==d&&cd.style.display=='none'){
					cd.style.display='block';
					this.islide(c,1);
					h.addClassName("active");
				}else if(cd.style.display=='block'){this.islide(c,-1);}
			}
		},
		islide:function(i,d){
			var c,m; c=document.getElementById(i); m=c.maxh; c.direction=d;
			c.timer=setInterval("slider.slide('" +i +"')",timer);
		},
		slide:function(i){
			var c,m,h,dist; c=document.getElementById(i); m=c.maxh; h=c.offsetHeight;
			dist=(c.direction==1)?Math.round((m-h)/speed):Math.round(h/speed);
			if(dist<=1){dist=1}
			c.style.height=h+(dist*c.direction)+'px';
			if(h<2&&c.direction!=1){
				c.style.display='none';
				clearInterval(c.timer);
			}else if(h>(m-2)&&c.direction==1){clearInterval(c.timer)}
		}
	};
}();