
$(document).ready(function() {	
	var cookie = $.cookie("agecontrol");
	
	//VYMAŽE COOKIES
	// $.cookie("agecontrol", null, { expires: 1 });
	
	if(cookie != "true"){
		$("#agecontrol").show();
	}
	
	$('input#searchsubmit').val('');
	
	$('.next, .prev').each(function(){
		var text = $(this).text().replace('»', '').replace('«','');
		$(this).text(text);
	})
	
	
	// AGECONTROLL
	$('input.ldaInputField').each(function(){
		var val = $(this).val();
		
		$(this)
			.focus(function(){
				$(this).val('')
			})
			.blur(function(){
				if($(this).val() == '') $(this).val(val);
			})
	})

	controlAge();
	keypressSwitch();
});

Cufon.DOM.ready(function() {
	Cufon.replace('.fishmonger, h1, h2, h3, h4, ul#menu-absolut a,#menu-absolut-1 a, #site-title, #site-info a, .ldaHeader, .ldaFormHeader, .ldaSubmit', { 
		fontFamily: 'Futura XBlkCn AT'
	})
})

function controlAge(){
	$('a.ldaSubmit').click(function(){
		var year = parseInt($('#txtDate2').val());
		var month = parseInt($('#txtDate1').val());
		var day = parseInt($('#txtDate0').val());
	
		var today = new Date();
		var min = new Date(today.getFullYear() - 18, today.getMonth() + 1, today.getDate());
		var bornDate = new Date(year,month,day,0,0,0,0);
		var diff = today.getFullYear() - bornDate.getFullYear();
		
		if(isNaN(year) == false && isNaN(month) == false && isNaN(day) == false){
			if(min < bornDate){
				$('#ldaValidation').text('Je nám líto, ale ještě jste nedosáhl(a) plnoletosti.');
			}else{
				$('#agecontrol').fadeOut();
				$.cookie("agecontrol", "true", { path: '/', expires: 7 });
			}
		} else {
			$('#ldaValidation').text('Prosím, napiště platné datum.')
		}
		return false;
	})
	
}

jQuery.extend(jQuery.expr[':'], {
  focus: "a == document.activeElement"
});
function keypressSwitch(){
	$(document).keypress(function(event){
		var code = event.keyCode;
		if(code == 37){
			if($('.ldaInputBox input:focus').is(':first-child') == false)
				$('.ldaInputBox input:focus').trigger('blur').prev('input').trigger('focus');
		}else if(code == 39){
			if($('.ldaInputBox input:focus').is(':last-child') == false)
				$('.ldaInputBox input:focus').trigger('blur').next('input').trigger('focus');
		}
	})
}

