$(document).ready(function(){
var editInPlace_id;
var editInPlace_table;
var editInPlace_column;
setClickable();
});

function setClickable() {
$('#editInPlace').click(function() {
var textarea = '<div><textarea class="editTextArea" rows="10" cols="60">'+$(this).html()+'</textarea>';
var button	 = '<div><input type="button" value="Uložit" class="saveButton" /> | <input type="button" value="Zrušit" class="cancelButton" /> | <input type="button" value="Upravit v editoru" class="editInEditorButton" /> | <input type="button" value="Nápověda" class="helpButton" /></div></div>';
var revert = $(this).html();
$(this).after(textarea+button).remove();
$('.saveButton').click(function(){saveChanges(this, false);});
$('.cancelButton').click(function(){saveChanges(this, revert);});
$('.editInEditorButton').click(function(){ editInEditor(editInPlace_id, editInPlace_table, editInPlace_column);});
$('.helpButton').click(function(){showHelp();});
})
.mouseover(function() {
$(this).addClass("editable");
})
.mouseout(function() {
$(this).removeClass("editable");
});
};

function saveChanges(obj, cancel) {
if(!cancel) {

var t = $(obj).parent().siblings(0).val();
$.post("http://www.prohunting-shop.cz/scripts/editInPlace.php",{
  'content': t,
  'id': editInPlace_id,
  'table': editInPlace_table,
  'column': editInPlace_column
},function(txt){

});
}
else {
var t = cancel;
}
if(t=='') t='(klikni pro přidání textu)';
$(obj).parent().parent().after('<div id="editInPlace">'+t+'</div>').remove();
setClickable();
}	

function showHelp() {
alert('Nápověda: \n V režimu přímé editace se vám zobrazují i HTML tagy, které se starají o formátování textu. Pokud chcete více přehlednou editaci, klikněte na tlačítko "Upravit v editoru". \n\nZákladní HTML znaky: \n<br /> \t - Vytvoří nový řádek\n<strong>Text</strong>\t - Tučný text\n<u>text</u> \t - Podtržení\n<i>Text</i> \t - Kurzíva\n<p>text</p>\t - Odstavcový text\n<h1>text</h1>\t - Nadpis 1\n<h2>text</h2>\t - Nadpis 2');
}
function editInEditor(text, table, column) {
if(column == 'content') {
	window.location.replace( 'http://www.prohunting-shop.cz/adminator/index.php?section=1admin&tool=01texty&action=editText&id=' + text + '&id2=' + table );	
} else {
	window.location.replace( 'http://www.prohunting-shop.cz/adminator/index.php?section=1admin&tool=01texty&action=randomText&id=' + text + '&id2=' + table + '&id3=' + column );	
}
}
