$(document).ready(function() {
	fitMenuItems('#menuMain');
	initGuidepost();
	// callback ext
	$("#callbackInputText").focusin(function() {
		if ($(this).val() == "tel. číslo") $(this).val('');
	});
});

/** Main menu exact fit **/
function fitMenuItems(selector) {
	
	var menu = $(selector);
	var menuWidth = menu.width();
	var li = menu.find('li');
	
	li.first().addClass('first-child');
	li.last().addClass('last-child');
	
	var liWidth = 0;
	li.each(function () {
		liWidth += $(this).outerWidth();
	});
	
	var plusWidth = Math.floor((menuWidth - liWidth)/li.size())
	var restWidth = (menuWidth-liWidth) % li.size();

	li.children('a').each(function () {
		$(this).width($(this).width()+plusWidth);	
		if(restWidth>0) {
			$(this).width($(this).width()+1);		
			restWidth--;
		}			
	});
}

/** Guidepost **/
function initGuidepost() {
	var guidepost = $('#guidepost');
	if(guidepost.length==0) return;
	
	var box = guidepost.children('.box');
	var animDuratin = 250;
	
	//hide elements
	box.find('.text, .link').hide();
		
	//box hover	
	box.hover(function() {							 
		$(this).children('.content').stop(true, true).animate({top: 13}, animDuratin);
		$(this).find('.content .text').show();
	}, function() {
		$(this)
			.children('.content')
			.stop(true, true)
			.animate(
				{top: 77}, 
				animDuratin * 0.65, 
				function () {
					$(this).children('.text').hide();						
				}
			);
									 
	});
	
	// click
	box.click(function() {
		location.href = $(this).find('.link').attr('href');
	});
}
