/*-- Chalet Panel Function --*/

Tabs =
{
	select : function(tab)
	{
		location.hash = tab.parentNode.getAttribute('var');
		var lis = tab.parentNode.parentNode.getElementsByTagName('li');
		for(var i=0;i<lis.length;i++)
		{
			lis[i].className = '';
			$(lis[i].getAttribute('var')).style.display='none';
		}
		tab.parentNode.className = 'selected';
		$(tab.parentNode.getAttribute('var')).style.display='block';
	},
	
	setup : function(t,tt)
	{
		var h = document.getElementById(t);
		var hh = document.getElementById(tt);
		
		if (h)
		{
			var h5s = h.getElementsByTagName('h4');
			var tabs = '<ul class="tabs">';
			for(var i=0;i<h5s.length;i++)
			{
				var next = (h5s[i].nextSibling.nodeName == 'DIV' ? h5s[i].nextSibling : h5s[i].nextSibling.nextSibling);
				tabs+='<li var="'+next.id+'" '+((location.hash=='' && i==0)||(location.hash=='#'+next.id)?'class="selected"':'')+'><span onclick="Tabs.select(this)">'+h5s[i].innerHTML+'</span></li>';
				h5s[i].style.display='none';
				if ((location.hash=='' && i==0)||(location.hash=='#'+next.id))
					next.style.display = 'block';
				else
					next.style.display = 'none';
			}
			tabs+='</ul>';
			
			if (hh)
			{
				hh.innerHTML = tabs;
				h.innerHTML = h.innerHTML;
			}
			else
			{
				hh = h;
				h.innerHTML = tabs + h.innerHTML;
			}
		}
		
		/*if (location.hash)
		{
			var lis = hh.getElementsByTagName('li');
			for(var i=0;i<lis.length;i++)
			{
				if ('#'+lis[i].getAttribute('var') == location.hash)
				{
					//alert(location.hash);
					Tabs.select(lis[i]);
				}
			}
			
		}*/
	}
}


Frontrow = 
{
	setSlide : function(theSlide)
	{
		Frontrow.pause();
		var maxzindex = 0;
		//for(var i=0;i<Frontrow.links.length;i++)
			//Frontrow.links[i].className="";
		for(var i=0;i<Frontrow.slides.length;i++)
			maxzindex = (Frontrow.slides[i].style.zIndex>maxzindex ? Frontrow.slides[i].style.zIndex : maxzindex);
		Frontrow.slides[theSlide].style.zIndex = (maxzindex * 1) + 1;
		Frontrow.slides[theSlide].style.opacity = 1.0;
		//Frontrow.links[theSlide].className="active";
	},
	
	//start : function(eid,links)
	start : function(eid)
	{
		Frontrow.slides = document.getElementById(eid).getElementsByTagName('div');
		//Frontrow.links = document.getElementById(links).getElementsByTagName('div');
		Frontrow.setSlide(0);
		Frontrow.play();
	},
	
	pause : function()
	{
		if (Frontrow.loop)
			clearInterval(Frontrow.loop);
	},
	
	play : function()
	{
		if (Frontrow.loop)
			clearInterval(Frontrow.loop);
		Frontrow.loop = setInterval(Frontrow.advance,4000);
	},

	advance : function()
	{
		if (Frontrow.slides.length > 0)
		{
			var s = 0;
			for(var i=0;i<Frontrow.slides.length;i++)
				if (Frontrow.slides[i].style.zIndex * 1> Frontrow.slides[s].style.zIndex * 1)
					s = i;
			var n = s+1;
			if (n==Frontrow.slides.length)
				n = 0;	
				
			//for(var i=0;i<Frontrow.links.length;i++)
				//Frontrow.links[i].className="";
	
			//Frontrow.links[n].className="active";
			Frontrow.slides[n].style.opacity = 0.0;
			Frontrow.slides[n].style.zIndex= (Frontrow.slides[s].style.zIndex * 1) + 1;
			Frontrow.appear(Frontrow.slides[n]);
		}
	},
	
	appear : function(e)
	{
		Frontrow.ani = setInterval(function() 
		{
			e.style.opacity= (e.style.opacity * 1) + 0.1;
			if (e.style.opacity >= 1)
			{
				e.style.opacity = 1.0;
				clearInterval(Frontrow.ani);
			}
		}	
		,50);
	}
	
}

