/** nav menu hover function */
var menu=function(){
	var t=15,z=50,s=6,a;
	function dd(n){this.n=n; this.h=[]; this.c=[]}
	dd.prototype.init=function(p,c){
		a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		}
	}
	dd.prototype.st=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible'}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
	}
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		c.style.height=h+(d*f)+'px'
	}
	return{dd:dd}
}();

var menuSide=function(){
	var t=15,z=50,s=6,b;
	function ee(n){this.n=n; this.h=[]; this.c=[]}
	ee.prototype.init=function(p,c){
		b=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.sa('+i+',true)');
			h.onmouseout=new Function(this.n+'.sa('+i+')');
		}
	}
	ee.prototype.sa=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+b;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible';c.style.filter='';}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{p.className=p.className.replace(b,''); c.t=setInterval(function(){sl(c,-1)},t)}
	}
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		// if(console){ console.log(d,o); }
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		/* if(o>0.99){alert('debugging: '+o);} */
		c.style.height=h+(d*f)+'px';
	}
	return{ee:ee}
}();

/* webnetwork functions */
var d = 10; // number of seconds from page load to delay starting slideshow
var t = 10; // number of seconds between slides
var	s = 1800; //speed of transition in milliseconds
var stagger = 3; //number of seconds to stagger slideshow starts
var i = 0; //number of slideshows started  

var timer0, timer1, timer2, timer3;

function slideshowStart()
{
	//each() means that setTimeout and subsequent runs in the context of the individual div
	$('.slideshow').each(function(){
		if($(this).children('a').length > 1) // check that we have more than one slide
		{
			
			$(this).addClass('active'); 
			$(this).children('a').last().prevAll().fadeOut(1); //hide all but top slide, remember display in reverse order rendered
			var pass = this;
			setTimeout(function(){ //trigger once
				setInterval(function(){
					changeSlide(pass);
				},t*1000) // interval
			},d+stagger*1000*i); //timeout	
			i++;
		}//if
	});//each
	
}

function changeSlide(ref)
{
	//get list of slides in order, which rotates each time, 
	//then reference current and next slides so we don't lose them in delay()s
	// remember last rendered appears on top
	slides = $(ref).children('a');
	c = $(slides).last(); //current
	n = $(c).prev(); //next
	l = $(slides).first(); //in case of only two slides == n
	
	// fade out the current slide
	$(c).fadeOut(s); 
	
	//halfway through fade out start fading in the next slide
	$(n).delay(s/2).fadeIn(s);
	
	//after fade out move top slide to the bottom
	$(c).delay(s).insertBefore(l);
	
	//setTimeout(changeSlide(ref,no),(s*1.5 + t*1000)); // set next transition to occur t seconds after fade-in complete
}

