//2008 ANBER
function Menu(head,child,dir,speed,init_state,ext_on,ext_off)
{
	this.head = document.getElementById(head);
	this.body = document.getElementById(child);
	this.direction = dir;
	this.speed = speed;
	this.ext_on = ext_on;
	this.ext_off = ext_off;
	this.init_state = init_state;
	this.a = 10;

	this._interval = false;
	this._last_state = false;
	this._size = false;
	this._temp = false;
	this._js = false;
	this._div = false;
	this._parent = false;
	this._parent_control = false;
	var self = this;
	var temp = new Array(null,null);

	this.click = function(e)
	{
		if (self._parent_control)
		{
			self._parent._control(self);
			return false;
		}
		else
		{
			Interval.clear(self._interval);
			if (self._last_state == false)
			{
				self._on();
				return false;
			}
			else
			{
				self._off();
				return false;
			}
		}
	}
	
	this.init = function()
	{
		this.head.onclick = this.click;
		this.head.onkeypress = function(e)
		{
			e||(e=window.event);
			if (!(e.keyCode ==32 || e.keyCode == 0))return;
			self.click();
		}
		for(var i=0;i<this.body.childNodes.length;i++)
		{
			if (this.body.childNodes[i].nodeType==1)
			{
				this._div=this.body.childNodes[i];
				break;
			}
		}
		if (parseInt(this.body.style.height))
		{
			this._size = parseInt(this.body.style.height);
		}
		else
		{
			this._size = this._div.offsetHeight;
		}
		switch (this.init_state)
		{
			case true:
				if (this.body.style.display == 'none')
				{
					//this._last_state = false;
					this._on();
				}
				else
				{
					this._last_state = true;
				}
				break;
			default:
				if (this.body.style.display !='none')
				{
					this._last_state = true;
					this._off();
				}
				break;
		}
	}
	this._on = function()
	{
		if (self._last_state == false)
		{
			self._last_state = true;
			self.body.style.display="";
			temp[1] = self.a?2*parseInt(Math.sqrt(self.a*self._size))+1:self._size/5;
			if (isNaN(parseInt(self.body.style.height)))self.body.style.height="100px";
			if (self.ext_on)
			{
				self.ext_on(self.head,self.body)
			}
			self._interval = Interval.set(self._action_on,speed);
		}
		
	}

	this._off = function()
	{
		if (self._last_state == true)
		{
			self._last_state = false;
		
	
				temp[0]=self.a?2*parseInt(Math.sqrt(self.a*self._size))+1:self._size/5;;

			if(isNaN(parseInt(self.body.style.height)))self.body.style.height = self._size+'px';
			if (self.ext_off)
			{
				self.ext_off(self.head,self.body)
			}
			self._interval = Interval.set(self._action_off,this.speed);
		}
	}

	this._action_on = function()
	{
		if (parseInt(self.body.style.height)+temp[1]>self._size)
		{
			self.body.style.height = 'auto';
			Interval.clear(self._interval);
		}
		else
		{
		self.body.style.height = parseInt(self.body.style.height)+temp[1]+'px';
		temp[1] +=self.a;
		}
	}
	this._action_off = function()
	{
		if(parseInt(self.body.style.height)-temp[0]<0)
		{
			Interval.clear(self._interval);
			self.body.style.display = "none";
		}
		else
		{
			self.body.style.height = parseInt(self.body.style.height)-temp[0]+'px';
			temp[0]-=self.a;
		}
	}
}

Interval=
{
	length:20,
	_action : new Array(length),
	_stack : new Array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19),
	_interval : Array(length),
	_timeout: new Array(length),

	set:function(action_function,speed,time_out)
	{
		time_out = time_out?time_out:15000;
 		var p = Interval._stack.pop();
		if(p)
		{
			Interval._action[p] = action_function;
			Interval._interval[p]=setInterval('if(Interval._action['+p+'])Interval._action['+p+']();',speed);
			Interval._timeout[p] = setTimeout('Interval.clear('+p+')',time_out);
			return p;
		}
	},
	clear:function(p)
	{
		if (Interval._action[p])
		{
			clearInterval(Interval._interval[p]);
			clearTimeout(Interval._timeout[p]);
			Interval._action[p] = "";
			Interval._stack.push(p);
		}
	}
}



var currslid = 0;
var slidint;
function setfoc(id){
	document.getElementById("focpic").src = picarry[id];
	document.getElementById("foclnk").href = lnkarry[id];
		currslid = id;
	for(i=0;i<4;i++){
		document.getElementById("tmb"+i).className = "thubpic";
	};
	document.getElementById("tmb"+id).className ="thubpiccur";
	focpic.style.visibility = "hidden";
	focpic.filters[0].Apply();
	if (focpic.style.visibility == "visible") {
		focpic.style.visibility = "hidden";
		focpic.filters.revealTrans.transition=23;
	}
	else {
		focpic.style.visibility = "visible";
		focpic.filters[0].transition=23;
	}
	focpic.filters[0].Play();
	stopit();
}

function playnext(){
	if(currslid==3){
		currslid = 0;
	}
	else{
		currslid++;
	};
	setfoc(currslid);
	playit();
}
function playit(){
	slidint = setTimeout(playnext,4500);
}
function stopit(){
	clearTimeout(slidint);
	}
window.onload = function(){
	playit();
}

