


var homeTabs = {

	current: null,

	init: function() {
		homeTabs.current = $('kariera-tab');
		$$('#zalozky-links a').each(function(tab) {
			tab.onclick = function() {
				this.blur();
				$$('#zalozka-wrap .zalozka-body').each(function(body) {
					$(body).style.visibility = 'visible';
				});
				var targetId = this.getAttribute('rel'), link = this;
				new Effect.InnerHorizontalScroll($('zalozka-wrap'), $(targetId), {
					afterFinish: function() {
						homeTabs.current.className = homeTabs.current.className.replace(/active_[^\s+]/, '');
						Element.addClassName(link, 'active_' + link.getAttribute('rel').replace('body-', ''));
						homeTabs.current = link;
						$$('#zalozka-wrap .zalozka-body').each(function(body) {
							if ($(body) != $(targetId)) {
								// aby se neslo dotabovat k linkum ve skrytych castech
								$(body).style.visibility = 'hidden';
							}
						});
					},
					duration: .3
				});

				return false;
			}
		});
	}

}

homeTabs.init();

var ozTabs = {

	current: null,

	init: function() {
		var links = $$('#oz-tabs-links a');
		if (links.length == 0) {
			return;
		}
		ozTabs.current = links[0]
		links.each(function(tab) {
			tab.onclick = function() {
				this.blur();
				$$('#zalozka2-wrap .zalozka-body').each(function(body) {
					$(body).style.visibility = 'visible';
				});
				var targetId = this.getAttribute('rel'), link = this;
				//console.log(targetId, $(targetId), $('oz-tab-wrap'));
				new Effect.InnerHorizontalScroll($('zalozka2-wrap'), $(targetId), {
					afterFinish: function() {
						ozTabs.current.className = ozTabs.current.className.replace(/active_[^\s+]/, '');
						Element.addClassName(link, 'active_' + link.getAttribute('rel').match(/[a-z]+$/)[0]);
						ozTabs.current = link;
						$$('#zalozka2-wrap .zalozka-body').each(function(body) {
							if ($(body) != $(targetId)) {
								// aby se neslo dotabovat k linkum ve skrytych castech
								$(body).style.visibility = 'hidden';
							}
						});
					},
					duration: .2
				});

				return false;
			}
		});
	}

}
ozTabs.init();

Effect.InnerHorizontalScroll = function(scrollingElement, targetElement, options) {
	var options = options || { },
	from = $(scrollingElement).scrollLeft,
	to = $(targetElement).cumulativeOffset().left  - $(scrollingElement).cumulativeOffset().left;
	if (options.offset) {
		to += options.offset;
	}
	return new Effect.Tween(null, from, to, options,
		function(to) {
			$(scrollingElement).scrollLeft = to.round();
		}
	);
};

// zjisteni aktivni zalozky
var current_ref_tab = 1;
var current_tab_arr = $$('.zalozkaOn');
if (current_tab_arr.length == 1) {
	if(current_tab_arr[0].id == 'zalozkaReference1') {
		current_ref_tab = 1;
	} else {
		current_ref_tab = 2;
	}
}

function reference_toggle(id) {
	if (id == current_ref_tab) {
		return;
	}
	
	current_ref_tab = id;
	
	if (id == 1) {
		new Effect.Move($('referenceZalozky'), { x: 260, duration: 0.5 });
		$('zalozkaReference1').addClassName('zalozkaOn');
		$('zalozkaReference2').removeClassName('zalozkaOn');
	}

	if (id == 2) {
		new Effect.Move($('referenceZalozky'), { x: -260, duration: 0.5 });
		$('zalozkaReference2').addClassName('zalozkaOn');
		$('zalozkaReference1').removeClassName('zalozkaOn');
	}
}
