function adjustTextCenter() {var www = jQuery("#zitPreviewText").width();var hhh = jQuery("#zitPreviewText").height();var lll = Math.round((widthSize  - www - 0) / 2);var ttt = Math.round((heightSize - hhh - 0 ) / 2);if (zitFirstTimeCenter == 1) {zitFirstTimeCenter = 0;lll = lll - 14;ttt = ttt +  2;}jQuery("#zitPreviewText").css({'top' : ttt});jQuery("#zitPreviewText").css({'left' : lll});texteOffsetX = lll;texteOffsetY = ttt;updateDebug();}function adjustTextSize() {var newTextSize = Math.round(previewRatio * textSize);jQuery("#zitPreviewText").css({'font-size' : newTextSize + 'px'});Cufon.replace("#zitPreviewText", { fontFamily: jQuery("#zitFont").val() });updateDebug();}function adjustImageSize() {var w = widthSize  + 100;var h = heightSize + 100;if (widthSize < 400)  w = 400 + 100 ;if (heightSize < 630) h = 630 + 100 ;jQuery("#zitPreviewMask").css({'width' : w+'px'});jQuery("#zitPreviewMask").css({'height' : h+'px'});w = widthSize ;h = heightSize;jQuery("#zitPreviewZone").css({'width' : w+'px'});jQuery("#zitPreviewZone").css({'height' : h+'px'});w = widthSize  + 100 + 0;h = heightSize + 100 + 0;if (widthSize < 400)  w = 400 + 100 ;jQuery("#zitPreviewImage").css({'width' : w+'px'});jQuery("#zitPreviewImage").css({'height' : h+'px'});w = widthSize  + 100 + 1;h = heightSize + 100 + 1 + 35;if (widthSize < 400)  w = 400 + 100 + 1;if (heightSize < 630) h = 630 + 100 + 1 + 35;jQuery("#zitPreview").css({'width' : w+'px'});jQuery("#zitPreview").css({'height' : h+'px'});h = h - 35;jQuery("#zitPreviewImage").css({'height' : h+'px'});jQuery("#zitBackgroundImage").css({'width' : widthSize+'px'});jQuery("#zitBackgroundImage").css({'height' : heightSize+'px'});jQuery("#zitPreviewMask").css({'background-image' : 'url(http://www.sublicentre.com/zit/images/products/'+widthSize+"x"+heightSize+'.png)'});jQuery("#zitToolsTabs").css({'height' : h+'px'});jQuery("#zitCreation").css({'height' : h+'px'});jQuery("#zitDebug").css({'height' : h+'px'});maxWidth = widthSize - 10;maxHeight = heightSize - 10;resizeImageAfterUpload();}function resizeImageAfterUpload() {var radioOld = ratio;var www = jQuery('#draggableImageSrc').width();var hhh = jQuery('#draggableImageSrc').height();if ( (www == 1) || (hhh == 1) ) {www = imageWidthOriginalBackup;hhh = imageHeightOriginalBackup;}if (imageOriginal == 1) {imageWidthOriginal = imageWidthOriginalBackup;imageHeightOriginal = imageHeightOriginalBackup;www = imageWidthOriginalBackup;hhh = imageHeightOriginalBackup;}var ratio = Math.round(www / hhh * 100) / 100;if (isNaN(ratio)) ratio = 1;if (ratio < 1) {ratio = ratio;zoomStepX = Math.round(ratio * 10);zoomStepY = 10;zoomStepXfloat = ratio * 10;zoomStepYfloat = 10;} else {zoomStepY = 1;if ( (ratio >= 1) && (ratio < 2) ) zoomStepY = 5;if ( (ratio >= 2) && (ratio < 5) ) zoomStepY = 2;zoomStepX = Math.round(ratio * zoomStepY);zoomStepY = zoomStepY;zoomStepXfloat = ratio * zoomStepY;zoomStepYfloat = zoomStepY;}if ( (imageOriginal == 1) || (radioOld != ratio) ) {www = Math.round(imageWidthOriginal * previewRatio);hhh = Math.round(imageHeightOriginal * previewRatio);imageWidthFloat  = www;imageHeightFloat = hhh;}maxWidth  = www;maxHeight = hhh;var k = 0;wMax = widthSize  + 0;hMax = heightSize + 0;jQuery('#draggableImageSrc').width(www);jQuery('#draggableImageSrc').height(hhh);imageWidth  = www;imageHeight = hhh;imageOriginal = 0;updateDebug();}function nl2br (str, is_xhtml) {var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '' : '<br/>';return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');}function updateDebug() {var debugTime3 = new Date();var debugTime3OK = debugTime3.getTime();if (debugTime3OK - debugTimeOK > 1000) {debugTimeOK = debugTime3OK;texteNow = nl2br(jQuery("#zitText").val(), false);imageNow = jQuery("#draggableImageSrc").attr("src");var widthSizeBig = Math.floor(widthSize / previewRatio);var heightSizeBig = Math.floor(heightSize / previewRatio);jQuery("#debugProduit").html(txtProduit);jQuery("#debugDimension").html(widthSizeBig + " x " + heightSizeBig + " = " + Math.round(widthSize) + " x " + Math.round(heightSize));jQuery("#debugRatio").html(previewRatio);jQuery("#prevRatio").html(Math.round(previewRatio * 100)+"%");jQuery("#zitResolution").html(widthSizeBig + " x " + heightSizeBig);jQuery("#debugTextColor").html(textColor);jQuery("#debugTextSize").html(textSize);jQuery("#debugTextFont").html(textFont);jQuery("#debugTexte").html(texteNow);jQuery("#debugImage").html(imageNow);jQuery("#debugImageWidth").html(imageWidth+" px");jQuery("#debugImageHeight").html(imageHeight+" px");jQuery("#debugImageWidthOriginal").html(imageWidthOriginal+" px");jQuery("#debugImageHeightOriginal").html(imageHeightOriginal+" px");jQuery("#debugBackgroundColor").html(backgroundColor);jQuery("#debugTexteOffsetX").html(texteOffsetX);jQuery("#debugTexteOffsetY").html(texteOffsetY);imageOffsetX = parseInt(jQuery("#draggableImage").css("left").replace("px", ""));imageOffsetY = parseInt(jQuery("#draggableImage").css("top").replace("px", ""));jQuery("#debugImageOffsetX").html(imageOffsetX);jQuery("#debugImageOffsetY").html(imageOffsetY);}}function resetAll() {var txt_tmp = "demo test texte";jQuery("#zitText").val(txt_tmp);jQuery("#zitPreviewText").html(txt_tmp);textSize = 30;jQuery("#zitFont").val(1);jQuery("#zitFontSize").val(textSize + 'px');jQuery('#zitFontSizeSlider').slider('option', 'value', textSize);jQuery("#zitPreviewText").css({'font-size' : textSize + 'px'});Cufon.replace("#zitPreviewText", { fontFamily: jQuery("#zitFont").val() });imageWidthOriginalBackup = 0;imageHeightOriginalBackup = 0;imageWidth = 0;imageHeight = 0;imageWidthOriginal = 0;imageHeightOriginal = 0;jQuery('#draggableImageSrc').attr("src", "http://www.sublicentre.com/zit/images/clear.gif");jQuery("#draggableImageSrc").css({'width' : 0+'px'});jQuery("#draggableImageSrc").css({'height' : 0+'px'});jQuery("#draggableImage").css({'top' : 50+'px'});jQuery("#draggableImage").css({'left' : 50});var hex = "000000";textColor = "#" + hex;jQuery("#zitColorPicker div").css("backgroundColor", "#" + hex);jQuery("#zitPreviewText").css("color", "#" + hex);Cufon.replace("#zitPreviewText", { fontFamily: jQuery("#zitFont").val() });var hex = "FFFFFF";backgroundColor = "#" + hex;jQuery("#zitBackgroundColorPicker div").css("backgroundColor", "#" + hex);jQuery("#zitBackgroundImage").css("background-color", "#" + hex);adjustTextSize();adjustTextCenter();adjustImageSize();updateDebug();}function bgPositionX(id) {var imagePosition = jQuery('#'+id).css('background-position');if (typeof(imagePosition) === 'undefined') {var imagePositionX = jQuery('#' + id).css('background-position-x');var reg = new RegExp("(px)", "g");var imagePositionX = imagePositionX.replace(reg,'');return imagePositionX;}else {var position = imagePosition.split(" ");var reg = new RegExp("(px)", "g");var imagePositionX = position[0].replace(reg,'');return imagePositionX;}}function bgPositionY(id) {var imagePosition = jQuery('#'+id).css('background-position');if (typeof(imagePosition) === 'undefined') {var imagePositionY = jQuery('#' + id).css('background-position-y');var reg = new RegExp("(px)", "g");var imagePositionY = imagePositionY.replace(reg,'');return imagePositionY;}else {var position = imagePosition.split(" ");var reg = new RegExp("(px)", "g");var imagePositionY = position[1].replace(reg,'');return imagePositionY;}}