function initTabs()
{
	var sets = document.getElementsByTagName("ul");
	for (var i = 0; i < sets.length; i++)
	{
		if (sets[i].className.indexOf("tabset") != -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].href.substr(links[j].href.indexOf("#") + 1));

					//reset all tabs on start
					if (c) if (links[j].className.indexOf("active") != -1) c.style.display = "block";
					else c.style.display = "none";

					links[j].onclick = function ()
					{
						var c = document.getElementById(this.href.substr(this.href.indexOf("#") + 1));
						if (c)
						{
							//reset all tabs before change
							for (var i = 0; i < this.tabs.length; i++)
							{
								document.getElementById(this.tabs[i].href.substr(this.tabs[i].href.indexOf("#") + 1)).style.display = "none";
								this.tabs[i].className = this.tabs[i].className.replace("active", "");
							}
							this.className += " active";
							c.style.display = "block";

							// refresh cufon
							Cufon.refresh('ul.tabset a');
							return false;
						}
					}
				}
			}
		}
	}
}

function initSlideshow(){
	$('div.gallery').slideShow({
		numElementLink:'div.gallery-nav li a',
		slideEl:'div.gallery-content li',
		autoSlideShow:false,
		duration:500,
		autoSlideShow:true,
		switchTime:12000
	});
}

function initFooterOpenClose(){
	var _holder = $("#footer");
	var _link = _holder.find(".open-close-links");
	var _heightBlock = _holder.find(".footer-content");
	var _activeClass = "footer-open-block";
	var _dur=700;
	var _height = _heightBlock.innerHeight(true);
	
	if (!_holder.hasClass(_activeClass)) {
		_heightBlock.css({
			height: "90px"
		});
	};
	_link.click(function(){
		if (!_holder.hasClass(_activeClass)) {
			_heightBlock.animate({height: _height},{queue: false, duration: _dur, complete: function(){_holder.addClass(_activeClass);}});
		} else {
			_heightBlock.animate({height: "90px"},{queue: false, duration: _dur, complete: function(){_holder.removeClass(_activeClass);}});
		};
		return false;
	});
}


$(document).ready(function(){
	initTabs();
	initSlideshow();
	initFooterOpenClose();
});
