$(document).ready(function()
{
	var templateChanged = true;
	var copy_layer = $('#copy_layer');
	copy_layer.hide();
	copy_layer.css('marginLeft', (copy_layer.parent().innerWidth()/2) - (copy_layer.width()/2) + 'px');

	$('.miniaturka').click(function()
	{
		$('#copycheckbox').attr('checked', false);
		templateChanged = true;
	});

	$('#copy_button').hover(function()
	{
		copy_layer.slideDown('fast');

		var val = $('#hTemplate').attr('value');

		if((parseInt(val)) > 1)
		{
			if(templateChanged)
				$.get('ajax.php?id=' + val, function(data)
				{
					copy_layer.html(data);
					$('.copy_checkbox_test').hide();
					$('.copy_checkbox_test').click(function()
					{
						$('#copycheckbox').attr('checked', true);
					});

					$('.copy_checkbox').click(function()
					{
						$('#copycheckbox').attr('checked', true);
					});

					$('.copy_li').hover(function()
					{
						templateChanged = false;
						$('.copy_checkbox_test', this).show();
					}, function()
					{
						$('.copy_checkbox_test').each(function()
						{
							if($('input', this).attr('checked') != true)
							{
								$(this).hide();
							}
						});
					});
			});
		}
		else
		{
			copy_layer.html('Wybierz poprawny szablon po lewej.');
		}
	},
	function()
	{
		copy_layer.slideUp('fast');
	});

});

