<?php
include("include/css.inc.php");

$imagem = $_REQUEST['campo'];
$img_name = substr($imagem, 0, -4);
$ext = substr($imagem, -4);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//PT">
<html>

<link rel="STYLESHEET" type="text/css" href="layout/standard.css">
<link rel="STYLESHEET" type="text/css" class="cssfile">

<link rel="stylesheet" type="text/css" href="js/jquery.pixasticEditor.css"/>
<link rel="stylesheet" type="text/css" href="js/jquery.dragToSelect.css"/>
<link rel="stylesheet" type="text/css" media="screen" href="js/superfish.css" /> 

<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/excanvas.js"></script>
<script type="text/javascript" src="js/jquery.form.js"></script>
<script type="text/javascript" src="js/jquery.dragToSelect.js"></script>
<script type="text/javascript" src="js/jquery.pixasticEditor.js"></script>  

<script type="text/javascript" src="js/pixastic.custom.js"></script>
<script type="text/javascript" src="js/superfish.js"></script> 
<?
//<!--<link rel="stylesheet" type="text/css" href="js/jquery-ui.css"/>-->
//<!--<script type="text/javascript" src="js/jquery-ui.js"></script>-->
//<script type="text/javascript" src="js/jquery.pixasticEditor.js"></script>  
//<script type="text/javascript" src="js/jquery.pixasticEditor.pack.js"></script>
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Imagens</title>

<script type="text/javascript">
var img;
var obj;
$(document).ready(function(){
	cssfile = "css/" + "<?=$css?>" + ".css";
	$(".cssfile").attr("href", cssfile);
	
	img = $('#jquery-pixastic-editor-example').find('img')[0]; 
	if (img.complete) {
		obj = $('#jquery-pixastic-editor-example').pixasticEditor();
	}
	else {
		img.onload = function () {
			obj =$('#jquery-pixastic-editor-example').pixasticEditor();
		};
	}

	$('#botao_fechar').click(function () {
		window.close();
	});

	$('#botao_undo').click(function () {
		$("#saveimg").append("<input type='hidden' name='undo' value='undo'/>");
		$('#saveimg').submit();
	});

	$('#botao_guardar_como').click(function () {
		$('#caixa_guardar_como').toggle();
	});
 
	$("ul.sf-menu").superfish();
});
</script>
</head>
<style>
body {margin: 5px}
li {width: 100px; color: black; }
#saveimg {text-align: left; margin-top: 20px;}
#caixa_guardar_como{margin-top: 15px}
.div_menu_efeitos {margin-bottom: 5px}
</style>
<body>
					
<div class="clearfix">
	<h2 style="color: black;">Editor imagens</h2>
	<div id="jquery-pixastic-editor-example" class="clearfix">
		<img id="imagem" src="<?=$imagem ?>" alt="imagem a editar"/>
	</div>
	<div class="clearfix">
		<form enctype="multipart/form-data" name="saveimg" id="saveimg" action="saveimg.php" method="POST">
			<input class="botao_guardar" id="botao_guardar" type="button" value="Guardar">
			<input id="botao_guardar_como" type="button" value="Guardar como">
			<?if(is_file($img_name . "_old" . $ext)){ ?>
				<input id="botao_undo" type="button" value="Undo">
			<?} ?>
			<input id="botao_fechar" type="button" value="Fechar">
			<input type="hidden" value="<?=$imagem ?>" name="img_old">
			
			<div id="caixa_guardar_como" style="display: none;">
				<label for="nome_img">Nome da imagem: </label>
				<input id="nome_img" type="text" name="nome_img" value="<?=basename($imagem) ?>">
				<input class="botao_guardar" type="button" value="Guardar" id="botao_guardar2">
			</div>
		</form>
	</div>	
</div>	
</body>
</html>