$(document).ready(function(){
	_fontResize();
	initTabs();
	initFadeGallery("div.gallery li", ".dots");
	$('div.slider').galleryScroll({
		circleSlide:true
	});
});

var slides;
var buttons;
var current = 0;
var duration = 6000;/*4 sec*/
function initFadeGallery(images, buttons)
{
	slides = $(images);
	buttons = $(buttons);
	$(this).text($(".dots").html("<ul>"));
	$(slides).each(function(i, el)
	{
		$(".dots ul").append("<li><a href='javascript:;'><span>" + parseInt(i+1) + "</span></a></li>");
	});
	$(buttons).find("a").eq(0).addClass("active");
	$(slides).css({"opacity": 0}).eq(0).css({"opacity": 1});

	$(buttons).find("a").each(function(i, el)
	{
		$(el).click(function()
		{
			if(current != i)
			{
				$(buttons).find("a").removeClass("active");
				$(slides).eq(current).animate({"opacity": 0 })
				$(slides).eq(i).animate({"opacity": 1});
				current = i;
				$(this).addClass("active");
			}
		});
	});
	setTimeout("rotate(" + 0 +")", duration);
}

function rotate(_index)
{
	_index = current;
	$(slides).eq(_index).fadeTo("slow", 0);
	if(_index == $(slides).length - 1)
		_index = -1;
	$(slides).eq(++_index).fadeTo("slow", 1);
	$("div.dots").find("a").removeClass("active").eq(_index).addClass("active");
	current = _index;
	setTimeout("rotate(" + current + ")", duration);
}

function _fontResize()
{
	var _element = document.body;
	_default = 64;
	_curent = _default;
	_max = 76;
	_min = 52;
	_element.style.fontSize = _default + '%';
	var _step = 4;
	var _aaa = document.getElementById('aaa');
	var _btn = _aaa.getElementsByTagName('a');
	for (var j = 0; j < _btn.length; j++)
	{
		_btn[j].onclick = function()
		{
			if(this.className == 'zoom_in')
			{
				_curent += _step;
				if(_curent > _max)
				_curent = _max;
				_element.style.fontSize = _curent + '%';
			}
			else if(this.className == 'zoom_out')
			{
				_curent -= _step;
				if(_curent < _min)
				_curent = _min;
				_element.style.fontSize = _curent + '%';
			}
			else 
			{
				_element.style.fontSize = _default + '%';
				_curent = _default;
			}
		}
	}
}

function initTabs() {
	$('.tabset').each(function() {
		var _a = 0;
		var _btn = $(this).find('a.tab');
		_btn.each(function(_ind, _el) {
			_el.box = $('#' + _el.href.substr(_el.href.indexOf("#") + 1));
			if($(_el).hasClass('active')) {
				if(_el.box.length) _el.box.show();
				_a = _ind;
			}
			else {
				if(_el.box.length) _el.box.hide();
			}
			_el.onclick = function() {
				tabChange(_ind);
				return false;
			}
		});
		function tabChange(_i) {
			if(_i != _a) {
				_btn.get(_a).box.hide();
				_btn.eq(_a).removeClass('active');
				_btn.get(_i).box.show();
				_btn.eq(_i).addClass('active');
				_a = _i;
			}
		}
	});
}
