$(function(){$(document).pngFix();});

$(document).ready(function(){
	reloadStatement ();
	var statement = window.setInterval("reloadStatement()", 24000);
	
	$("#imagemove button").click(function(){
		$("#pdfpreviewimage").html('<div><img src="/cms/images/pdf/loading.gif" alt="" /></div>');
		pdfImageMove(this.id);
		return false;
	});
	$("#imagezoom button").click(function(){
		$("#pdfpreviewimage").html('<div><img src="/cms/images/pdf/loading.gif" alt="" /></div>');
		pdfImageZoom(this.id);
		return false;
	});
	
	
});

function reloadStatement () {
  $.ajax({
      type: "GET",
      url: "/cms/front_content.php",
      data: "idart=106",
      dataType: "html",
      success: function(html){
        $("#statement").html(html);
      }
  });
}
function pdfImageZoom (zoomtype) {
	for (i = 0; i < document.pdfform.zoomstep.length; ++i)
		if (document.pdfform.zoomstep.options[i].selected == true)
			zoomstep = document.pdfform.zoomstep.options[i].value;

	if (zoomtype == "in") {
		document.pdfform.zoomfaktor.value = parseFloat(document.pdfform.zoomfaktor.value)+parseFloat(zoomstep);
	} else if (zoomtype == "out") {
		document.pdfform.zoomfaktor.value = parseFloat(document.pdfform.zoomfaktor.value)-parseFloat(zoomstep);
	}
	$.ajax({
		type: "POST",
		url: "pdfimageedit.php",
		data: "zoom=" + zoomtype + "&zoomstep=" + document.pdfform.zoomstep.value + "&image=" + document.pdfform.image.value + "&paddingx=" + document.pdfform.paddingx.value + "&paddingy=" + document.pdfform.paddingy.value + "&maxx=" + document.pdfform.rx.value + "&maxy=" + document.pdfform.ry.value + "&zoomfaktor=" + document.pdfform.zoomfaktor.value + "&width=" + document.pdfform.vmaxx.value + "&height=" + document.pdfform.vmaxy.value,
		dataType: "html",
		success: function(html){
			var image = document.createElement("img");
			$(image).attr("width",document.pdfform.vmaxx.value);
			$(image).attr("height",document.pdfform.vmaxy.value);
			$(image).attr("src",html);
			$("#pdfpreviewimage").html(image);
		}
	});
}
function pdfImageMove (movetype) {
	for (i = 0; i < document.pdfform.paddingstep.length; ++i)
		if (document.pdfform.paddingstep.options[i].selected == true)
			paddingstep = document.pdfform.paddingstep.options[i].value;

	if (movetype == "up") {
		document.pdfform.paddingy.value = parseInt(document.pdfform.paddingy.value)+parseInt(paddingstep);
	} else if (movetype == "down") {
		document.pdfform.paddingy.value = parseInt(document.pdfform.paddingy.value)-parseInt(paddingstep);
	} else if (movetype == "right") {
		document.pdfform.paddingx.value = parseInt(document.pdfform.paddingx.value)-parseInt(paddingstep);
	} else if (movetype == "left") {
		document.pdfform.paddingx.value = parseInt(document.pdfform.paddingx.value)+parseInt(paddingstep);
	}
	$.ajax({
		type: "POST",
		url: "pdfimageedit.php",
		data: "move=" + movetype + "&movestep=" + document.pdfform.paddingstep.value + "&image=" + document.pdfform.image.value + "&paddingx=" + document.pdfform.paddingx.value + "&paddingy=" + document.pdfform.paddingy.value + "&maxx=" + document.pdfform.rx.value + "&maxy=" + document.pdfform.ry.value + "&zoomfaktor=" + document.pdfform.zoomfaktor.value + "&width=" + document.pdfform.vmaxx.value + "&height=" + document.pdfform.vmaxy.value,
		dataType: "html",
		success: function(html){
			var image = document.createElement("img");
			$(image).attr("width",document.pdfform.vmaxx.value);
			$(image).attr("height",document.pdfform.vmaxy.value);
			$(image).attr("src",html);
			$("#pdfpreviewimage").html(image);
		}
	});
	return false;
}

function pdfCheckLength() {
	maxlength = 135;
	aktlength = document.pdfform.statement.value.length;
	if (aktlength > maxlength) {
		alert('Sie dürfen maximal '+maxlength+' Zeichen eingeben!');
		document.pdfform.statement.value = document.pdfform.statement.value.substr(0,maxlength-1);
	}
}
