$(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');
	$('#eshopItemDetailImgThumbs a').bind('click', eshopShowDetailImage);
	// pridat check, at se to dela jen pro IE 6
	$('#eshopItemsList div.item img').click(function(){$(this).parent().parent().click();});
	
	var bgrColor = $('#eshopCart').css('background-color');	
	$('#eshopCart.updated').animate({backgroundColor: '#ffff88'}, 50).animate({backgroundColor: bgrColor}, 3000);

	$('form.mailform').ajaxForm({ 
		dataType	: 'json', 
		success		: mailformProcessJson,
		data		: {json : 1}  
    });
	$('#eshopKatsIndex li').vjustify();
	
	// Eshop menu
	$('#leftMenuEshop ul li a.mainKat').prepend('<span class="treeToggle" title="Zobrazit podkategorie">&nbsp;</span>');
	$('#leftMenuEshop ul li.open span.treeToggle').attr('title', 'Skrýt podkategorie');
	$('ul.submenu li.actual').parent().parent().addClass('open');
	$('#leftMenuEshop ul li span.treeToggle').bind('click', function (){
		var parentLi = $(this).parent().parent();
		if(parentLi.hasClass('open')) {
			parentLi.removeClass('open');
			$(this).attr('title', 'Zobrazit podkategorie');
		} else {
			parentLi.addClass('open');
			$(this).attr('title', 'Skrýt podkategorie');
		}
		return false;
	});
});

	$(document).ready(function(){
		$("div.photos ul a").addClass("thickbox");
		$("div.photos ul a").attr("rel", "gall");
		//$('#eshopItemDetail div.itemImg a').addClass("thickbox");
		TB_init();
		//$('#eshopItemsList div.eshopItem').vjustify();						
	});

function eshopShowDetailImage()
{
	//alert($(this));
	$('#eshopItemDetailImg img').attr({src : $(this).attr('href')});
	return false;
}

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();
	}
}