var _a_link = false;
function initTabs()
{
	initSlideShow();
	initSlideShow2();
	var _topbox = document.getElementById('top_box');
	if (_topbox)
	{
		_divs = _topbox.getElementsByTagName('div');
		for (var i=0; i<_divs.length; i++){
			if (_divs[i].className.indexOf('block')!=-1){
				_divs[i].style.display = 'none';
			}
		}
	}
	var _tabbox = document.getElementById('tab1');
	var sets = document.getElementsByTagName("div");
	if (_topbox && _tabbox && sets.length){
		_tabbox.style.display = "block";
		for (var i = 0; i < sets.length; i++)
		{
			if (sets[i].className.indexOf("block-content") != -1)
			{
				var tabs = [];
				var links = sets[i].getElementsByTagName("a");
				for (var j = 0; j < links.length; j++)
				{
					if (links[j].className.indexOf("tab") != -1)
					{
						tabs.push(links[j]);
						links[j].tabs = tabs;
						var c = document.getElementById(links[j].rel.substr(links[j].rel.indexOf("#") + 1));
						//reset all tabs on start
						if (c)
						{
						if (links[j].className.indexOf("active") != -1)
						{
							c.style.display = "block";
							_a_link = links[j];
						}
						else c.style.display = "none";
						}
						links[j].onmouseover = function ()
						{
							var c = document.getElementById(this.rel.substr(this.rel.indexOf("#") + 1));
							if (c)
							{
								//reset all tabs before change
								for (var i = 0; i < this.tabs.length; i++)
								{
									var tab = document.getElementById(this.tabs[i].rel.substr(this.tabs[i].rel.indexOf("#") + 1));
									if (tab)
									{
										tab.style.display = "none";
									}
								}
								_tabbox.style.display = "none";
								c.style.display = "block";
							}
						}
						links[j].onmouseout = function ()
						{
							_tabbox.style.display = "block";
						}
					}
				}
			}
		}
	}
	initFAQ();
	if(window.attachEvent && !window.opera && _a_link)
	{
		_a_link.onmouseover();
		_a_link.onmouseout();
	}
}

function initFAQ()
{
	var _el = document.getElementById('faq-list');
	if(_el)
	{
		var _hs = _el.getElementsByTagName('h4');
		for(var i = 0; i < _hs.length; i++)
		{
			_hs[i].onclick = function()
			{
				if(this.parentNode.className.indexOf("active") != -1)
				{
					this.parentNode.className = this.parentNode.className.replace("active","");
				}
				else
				{
					this.parentNode.className += " active";
				}
			}
		}
	}
}
var as = [];
var curr_index = 0;
var as2 = [];
var curr_index2 = 0;
var duration = 1500;
var stop_duration = 4000;
var start_o = 0;
var end_o = 1;
var _slideshowTimeout = false;
var _slideshowTimeout2 = false;
var _mediumA = false
var pas = [];
var scrollTimeout = false;
var scrollTimeout2 = false;

function initSlideShow(){	
	as = [];
	curr_index = 0;	
	var _box = document.getElementById('slide_img_holder');
	if(_box)
	{	
		var _as = _box.getElementsByTagName('img');
		var cnt = 0;
		var total_cnt = 0;
		for(i = 0; i < _as.length; i++)
		{
			total_cnt++;
		}		
		for(i = 0; i < _as.length; i++)
		{
				as[cnt] = _as[i];
				as[cnt]._index = cnt;
                        
				if(cnt == 0)
				{
					as[cnt].style.display = 'block';
				}
				else
				{
					as[cnt].style.display = 'none';					
				}
				cnt++;
		}
		curr_index = 0;		
		_switch(true);		
	}
}
function _switch(_start,_next_index){
	clearTimeout(_slideshowTimeout);
	var as_cnt = as.length;
	if(as_cnt > 1)
	{
		if(!_start)
		{
			var next_index = curr_index + 1;
			if(typeof(_next_index) != 'undefined')
			{
				var next_index = _next_index;
			}
			if(next_index >= as_cnt)
			{
				next_index = 0;
			}
			else if(next_index < 0)
			{
				next_index = as_cnt - 1;
			}
                        if(next_index != curr_index)
                        {
                                    var _opacity1 = new Fx.Tween( as[curr_index], {duration: duration,
                                                onStart: function(){
                                                      this.element.style.display = 'block';
                                                },
                                                onComplete: function(){this.element.style.display = 'none';}	
                                          
                                    });
                                    _opacity1.start('opacity', end_o, start_o);
                                    var _opacity2 = new Fx.Tween( as[next_index], {duration: duration,		
                                                onStart: function(){
                                                      this.element.style.display = 'block';
                                                },
                                                onComplete: function(){this.element.style.display = 'block';}		
                                          
                                    });
                                    _opacity2.set('opacity', start_o);
                                    _opacity2.start('opacity', start_o, end_o);
                                    curr_index = next_index;
                        }
		}
		_slideshowTimeout = setTimeout('_switch(false)',duration + stop_duration);
	}
}
function initSlideShow2(){	
	as2 = [];
	curr_index2 = 0;	
	var _box = document.getElementById('slide_title');
	if(_box)
	{	
		var _as = _box.getElementsByTagName('h2');
		var cnt = 0;
		var total_cnt = 0;
		for(i = 0; i < _as.length; i++)
		{
			total_cnt++;
		}		
		for(i = 0; i < _as.length; i++)
		{
				as2[cnt] = _as[i];
				as2[cnt]._index = cnt;
                        
				if(cnt == 0)
				{
					as2[cnt].style.display = 'block';
				}
				else
				{
					as2[cnt].style.display = 'none';					
				}
				cnt++;
		}
		curr_index = 0;		
		_switch2(true);		
	}
}
function _switch2(_start,_next_index){
	clearTimeout(_slideshowTimeout2);
	var as_cnt = as2.length;
	if(as_cnt > 1)
	{
		if(!_start)
		{
			var next_index2 = curr_index2 + 1;
			if(typeof(_next_index2) != 'undefined')
			{
				var next_index = _next_index;
			}
			if(next_index2 >= as_cnt)
			{
				next_index2 = 0;
			}
			else if(next_index2 < 0)
			{
				next_index2 = as_cnt - 1;
			}
                        if(next_index2 != curr_index2)
                        {
                                    var _opacity1 = new Fx.Tween( as2[curr_index2], {duration: duration,
                                                onStart: function(){
                                                      this.element.style.display = 'block';
                                                },
                                                onComplete: function(){this.element.style.display = 'none';}	
                                          
                                    });
                                    _opacity1.start('opacity', end_o, start_o);
                                    var _opacity2 = new Fx.Tween( as2[next_index2], {duration: duration,		
                                                onStart: function(){
                                                      this.element.style.display = 'block';
                                                },
                                                onComplete: function(){this.element.style.display = 'block';}		
                                          
                                    });
                                    _opacity2.set('opacity', start_o);
                                    _opacity2.start('opacity', start_o, end_o);
                                    curr_index2 = next_index2;
                        }
		}
		_slideshowTimeout2 = setTimeout('_switch2(false)',duration + stop_duration);
	}
}
function togglePopup( popup_id )
{
	var f = document.getElementById( popup_id );

	if (f)
	{
		if (f.style.display == "block")
			f.style.display = "none";
		else
		{
			f.style.display = "block";
			if ( popup_id == "acceptable-use-policy" ) document.getElementById('privacy-policy').style.display = "none"
			else document.getElementById('acceptable-use-policy').style.display = "none";
		}
	}
}

if (window.addEventListener)
	window.addEventListener("load", initTabs, false);
else if (window.attachEvent)
	window.attachEvent("onload", initTabs);
