$(document).ready(function(){
	$("#recapitulationDelivery").wrap("<div id='recapitulationDeliveryTop'></div>").wrap("<div id='recapitulationDeliveryBottom'></div>");
	$("table.itemList").wrap("<div class='itemListTop'></div>").wrap("<div class='itemListBottom'></div>");
	$("table.itemList tbody tr:nth-child(odd)").addClass('odd');
	$("table.itemList tbody tr:nth-child(even)").addClass('even');
	
	$('form.mailform').ajaxForm({ 
		dataType	: 'json', 
		success		: mailformProcessJson,
		data		: {json : 1} 
    });
	
	$('form.mailform table tr').each(function(i){
		$('td:first', $(this)).addClass('label');
	});	
	$('form.mailform table tr td.label').hjustify();
	$('form.mailform table tr td.label').css('width', $('form.mailform table tr td.label:first').width()+10+'px');
	$('form.mailform input[type=text]').addClass('inputText');
	$('form.mailform textarea').addClass('inputText');
	$('form.mailform input[type=submit]').addClass('inputSubmit');
	
	$("div.photos ul a").addClass("thickbox");
	$("div.photos ul a").attr("rel", "gall");
	$("div.photos ul li:odd").addClass("odd");
	$("div.photos ul li:even").addClass("even");
	TB_init();	

	$('#znackyVypis li span.nazev').vjustify();
});

function mailformProcessJson(data) { 
	$('form.mailform div.messageBox').remove();
	$('form.mailform').prepend('<div class="messageBox"></div>');
	var messageBox = $('form.mailform div.messageBox');

    if(data.errorMessage && data.errorMessage.length > 0)	{
    	messageBox.addClass('error');
    	mailformProcessMessages('error', messageBox, data.errorMessage);    	
    } else {
    	messageBox.addClass('ok');
		mailformProcessMessages('ok', messageBox, data.okMessage);
    }
    
    var bgrColor = messageBox.css('background-color');
    messageBox.animate({backgroundColor: '#ffff88'}, 50).animate({backgroundColor: bgrColor}, 3000);
}

function mailformProcessMessages(style, box, messages) {
	box.append('<ul></ul>');
	jQuery.each(messages, function() {
		$('ul', box).append('<li>' + this + '</li>');
	});

	if(style == 'ok')	{
		$('form.mailform').resetForm();
	}
}