var initial=true;var boxes=null;var box_images=null;var my_images=null;var resize_mode=false;var resize_startx=null;var resize_starty=null;var color=new Color();var dpi_alert_active=false;var _history=new Array();var present_boxes_index=0;var undo_or_redo_pressed=false;var selected_tab=null;var selected_box_seqno=0;var fonts=null;var HSV_MAX=91;var just_uploaded_image_id=0;var popup=null;var uii=0;var sci=0;var sai=0;var smi=0;$(function(){$("#delete-all-boxes").click(function(){return confirm("Ali želiš zares zbrisati vse elemente z vseh področij?")});$("#show-layer, #model").click(function(){activate_view_tab("design");return false});$("#show-product").click(function(){activate_view_tab("model");return false});$(".help").mouseover(function(o){$(".help-content").hide();var n=$(this).attr("alt");$("#"+n).show();var A=$("#help-popup");var l=$(this).offset();A.show();var k=$(window).width();var B=$(window).height();var q=$("#hc").width();var j=$("#hc").height();var z=parseInt(l.left);var u=parseInt(l.top);var f="";if(z<k/2){var f=z+30+"px"}else{var f=z-q-45+"px"}if(o.clientY<B/3){var t=u+20+"px"}else{if(o.clientY>2*B/3){var t=u-j-20+"px"}else{var t=u-j/2+"px"}}A.css({left:f,top:t});$("#hr").css("height",j+20+"px");$("#hb").css("width",q+20+"px")});$(".help").mouseout(function(){$("#help-popup").fadeOut(100)});$("#add-image-dialog").dialog({autoOpen:false,modal:true,width:390,height:490,buttons:{Zapri:function(){$(this).dialog("close")}},open:function(){$.ajax({type:"GET",url:"/images/",dataType:"json",success:handle_images_response,cache:false})}});$("#add-text-dialog").dialog({autoOpen:false,modal:true,width:390,height:190,buttons:{Zapri:function(){$(this).dialog("close")},Dodaj:function(){add_text();$(this).dialog("close")}}});$("#add-image-btn").click(function(){$("#add-image-dialog").dialog("open");return false});$("#add-text-btn").click(function(){$("#add-text-dialog").dialog("open");return false});$("#change-text-dialog").dialog({autoOpen:false,modal:true,width:390,height:190,open:function(){box=_get_box(parseInt($("#boxes li.selected").attr("id")));$("#text-to-change").val(box.fields.text)},buttons:{Zapri:function(){$(this).dialog("close")},Spremeni:function(){box=_get_box(parseInt($("#boxes li.selected").attr("id")));new_text=$("#text-to-change").val();if(box.fields.text!=new_text){box.fields.text=new_text;update_box(box)}$(this).dialog("close")}}});$("#move-align a").click(function(){return false});$("#btn-move-up").mousedown(move_up);$("#btn-move-down").mousedown(move_down);$("#btn-move-left").mousedown(move_left);$("#btn-move-right").mousedown(move_right);$("#btn-move-center").mousedown(boxalign_center);$("#btn-align-left").mousedown(boxalign_left);$("#btn-align-right").mousedown(boxalign_right);$("#btn-align-up").mousedown(boxalign_top);$("#btn-align-down").mousedown(boxalign_bottom);$("#btn-align-upleft").mousedown(boxalign_upleft);$("#btn-align-upright").mousedown(boxalign_upright);$("#btn-align-downleft").mousedown(boxalign_downleft);$("#btn-align-downright").mousedown(boxalign_downright);$("#textalign-left").mousedown(function(){text_align("l")});$("#textalign-center").mousedown(function(){text_align("c")});$("#textalign-right").mousedown(function(){text_align("r")});$("#halign").mousedown(boxalign_center_h);$("#valign").mousedown(boxalign_center_v);$("#selected-font").click(open_font_or_image_dialog);$("#standard-colors li").click(function(){color.from_string($(this).css("background-color"));update_satval();update_colorpick();update_box_color()});$("#resize-up").click(function(){if($("#boxes li.selected").length==0){return false}box=_get_box(parseInt($("#boxes li.selected").attr("id")));if(!box.fields.image){return false}MAX=WIDTH>HEIGHT?WIDTH:HEIGHT;box.fields.x-=0.05*(box.fields.width*MAX/(WIDTH*1));box.fields.y-=0.05*(box.fields.height*MAX/(HEIGHT*1));box.fields.width*=1.1;box.fields.height*=1.1;update_box(box)});$("#resize-down").click(function(){if($("#boxes li.selected").length==0){return false}box=_get_box(parseInt($("#boxes li.selected").attr("id")));if(!box.fields.image){return false}box.fields.x+=0.05*box.fields.width;box.fields.y+=0.05*box.fields.height;box.fields.width/=1.1;box.fields.height/=1.1;update_box(box)});$("#stretch").click(function(){if($("#boxes li.selected").length==0){return false}box=_get_box(parseInt($("#boxes li.selected").attr("id")));if(!box.fields.image){return false}var e=WIDTH>HEIGHT?WIDTH:HEIGHT;box.fields.x=0;box.fields.y=0;if(WIDTH>HEIGHT){box.fields.width=1;box.fields.height=HEIGHT/WIDTH}else{box.fields.width=WIDTH/HEIGHT;box.fields.height=1}update_box(box)});$("#fit").click(function(){if($("#boxes li.selected").length==0){return false}box=_get_box(parseInt($("#boxes li.selected").attr("id")));if(!box.fields.image){return false}if(WIDTH>HEIGHT){W=1;H=HEIGHT/WIDTH}else{W=WIDTH/HEIGHT;H=1}MAX=WIDTH>HEIGHT?WIDTH:HEIGHT;R=WIDTH/HEIGHT;for(i in box_images){if(box_images[i].pk==box.fields.image){r=box_images[i].width/box_images[i].height;break}}if(r>R){box.fields.x=0;box.fields.width=W;box.fields.height=W/r;box.fields.y=0.5-(box.fields.height*MAX/(HEIGHT*1))/2}else{box.fields.y=0;box.fields.height=H;box.fields.width=H*r;box.fields.x=0.5-(box.fields.width*MAX/(WIDTH*1))/2}update_box(box)});$("#fill").click(function(){if($("#boxes li.selected").length==0){return false}box=_get_box(parseInt($("#boxes li.selected").attr("id")));if(!box.fields.image){return false}MAX=WIDTH>HEIGHT?WIDTH:HEIGHT;if(WIDTH>HEIGHT){W=1;H=HEIGHT/WIDTH}else{W=WIDTH/HEIGHT;H=1}R=WIDTH/HEIGHT;for(i in box_images){if(box_images[i].pk==box.fields.image){r=box_images[i].width/box_images[i].height;break}}if(r>R){box.fields.y=0;box.fields.height=H;box.fields.width=H*r;box.fields.x=0.5-(box.fields.width*MAX/(WIDTH*1))/2}else{box.fields.x=0;box.fields.width=W;box.fields.height=W/r;box.fields.y=0.5-(box.fields.height*MAX/(HEIGHT*1))/2}update_box(box)});$("a.open-edit").click(function(){open_step($(".edit-acc"));return false});$("a.lnk-palette").click(function(){$("#palette").toggleClass("hide");return false});$("div.voting a.star").click(function(f){var e=$(f.currentTarget);$.post(e.attr("href"),{vote:e.attr("id").split("_")[1]},function(j){rating=parseInt(parseFloat(j.rating));items=$("div.voting a.star");for(i=0;i<items.length;i++){if(parseInt($(items[i]).attr("id").split("_")[1])<=rating){$(items[i]).attr("class","star on")}else{$(items[i]).attr("class","star")}}$("div.thanks-for-vote").show();$("div.voting").html("")},"json");return false});$("div.rating").mouseover(function(){$("div.voting").show()});$("div.voting a.star").mouseover(function(){$("div.voting a.star").css("background-position","0 0");rate=parseInt($(this).attr("id").split("_")[1]);for(i=1;i<=rate;i++){$("#vote_"+i).css("background-position","0 -32px")}});$("div.voting").mouseout(function(){$("div.voting a.star").css("background-position","0 0");$(this).hide()});var d="";dpi_dialog=$("div#dpi-dialog").dialog({bgiframe:true,resizable:false,height:140,width:450,modal:true,autoOpen:false,overlay:{backgroundColor:"#000",opacity:0.5},buttons:{Nadaljuj:function(e){document.location=d},"Prekliči":function(){$(this).dialog("close")}}});$("a.validate_dpi").click(function(e){d=$(e.currentTarget).attr("href");if(dpi_alert_active){dpi_dialog.dialog("open","asd")}else{return true}return false});$("a.lnk-zoom").click(function(){window.open("/print_preview/","_blank","height=700,width=700,toolbar=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=no");return false});$("#model-img").click(function(){activate_view_tab("tab-design")});$("#lnk-eggotrip").click(function(){$.ajax({type:"GET",url:"/images/?type=eggotrip",dataType:"json",success:handle_images_response,cache:false});$("#lnk-myimages").removeClass("active");$(this).addClass("active")});$("#lnk-myimages").click(function(){$.ajax({type:"GET",url:"/images/",dataType:"json",success:handle_images_response,cache:false});$("#lnk-eggotrip").removeClass("active");$(this).addClass("active")});$("#targets li").click(function(){target=$(this).attr("id");if(target=="all_targets"){$.ajax({type:"GET",url:"/products/",dataType:"json",success:display_target_products})}else{$.ajax({type:"GET",url:"/products/"+parseInt(target)+"/",dataType:"json",success:display_target_products})}});$(".product-acc .gallery a.ctrl").click(function(){ul=$(".gallery .gallery-box ul");len=ul.children().length;if(!len||len<=5){return false}ml=parseInt(ul.css("margin-left"));li_w=parseInt($(ul.children("li")[0]).css("width"));gb_w=parseInt($(".gallery .gallery-box").css("width"));if($(this).hasClass("next")){if(li_w*len+ml-gb_w<=0){return false}ml-=gb_w}else{if(ml>=0){return false}ml+=gb_w}ul.css({"margin-left":ml+"px"});return false});$(".tabs-box .tabset.tabs .tab").click(function(){activate_view_tab($(this).attr("id"))});$("#text-edit-popup").mouseleave(function(){$(this).hide("fast")});$(".btn-text").click(add_text);$(".addtext-acc .lnk-delete").click(function(){$("#text-to-add").attr("value","")});$("#text-to-add").focus(function(){this.select()});$("a.btn-next").click(function(){open_step($(this).parents("div.box").next());return false});$(".edit-holder .heading").click(function(){open_step($(this).parent())});$("#show-guides").click(function(){toggle_guides()});$("img.product").click(change_product);$("input[type=radio][name=printarea]").click(function(){change_option("printarea",$(this).attr("value"))});$("#sizes li").click(function(){change_size($(this))});$("#text-left").mousedown(function(){text_align("l")});$("#text-center").mousedown(function(){text_align("c")});$("#text-right").mousedown(function(){text_align("r")});$("#boxalign-top").mousedown(boxalign_top);$("#boxalign-bottom").mousedown(boxalign_bottom);$("#boxalign-left").mousedown(boxalign_left);$("#boxalign-right").mousedown(boxalign_right);$(document).keydown(function(e){key_down(e)});$("#view").tabs({fx:{opacity:"toggle"},spinner:"Retrieving data...",tabTemplate:'<div id="model"><img src="{href}"></div>'});$("#view").bind("tabsselect",function(e,f){selected_tab=f.panel.id;if(f.panel.id=="design"){return}f.panel.firstChild.src="/"+f.panel.id+"/?r="+Math.random()});$("#add-text-dialog-link").click(function(){$("#add-text-dialog").dialog("open");return false});$("#add-text-dialog").dialog({autoOpen:false,width:600,modal:true,open:function(){$(this).css("visibility","visible")},buttons:{Ok:function(){add_box($("#add_text").attr("value"));$(this).dialog("close")},Cancel:function(){$(this).dialog("close")}}});$("#id_image").change(function(){$("#file-upload-form").submit();$(this).attr("value","")});$("#file-upload-form").submit(function(){uii=setInterval(increase_upload_progress_bar,100);$("#upload-target").unbind("load");$("#file-upload-form").attr("target","upload-target");$("#upload-target").load(function(e){just_uploaded_image_id=parseInt($(window.frames[0].document.getElementsByTagName("body")[0]).html());$.ajax({type:"GET",url:"/images/",dataType:"json",success:handle_images_response,cache:false});img.css("width","500px");clearInterval(uii);img.css("width","0")}).error(function(){alert("Prišlo je do napake pri nalaganju slike. Prosimo poizkusi znova.")})});$("div.im-upload").click(function(){add_box("",parseInt($(this).attr("id")))});$("#colorpick").mouseleave(function(){$(this).hide("fast")});$("#sv-sel").mouseup(function(e){offset=$("#satval").offset();if(e.pageY){s=parseInt(e.pageX-offset.left-4);v=parseInt(e.pageY-offset.top-4)}else{s=parseInt(e.clientX-offset.left-document.body.scrollLeft-4);v=parseInt(e.clientY-offset.top-document.body.scrollTop-4)}if(s<0){s=0}if(s>HSV_MAX){s=HSV_MAX}if(v<0){v=0}if(v>HSV_MAX){v=HSV_MAX}$("#sv-sel").css({left:s,top:v});color.from_hsv(color.hue,s/HSV_MAX,(HSV_MAX-v)/HSV_MAX);update_box_color()});$("#h-sel").mouseup(update_box_color);$("#sv-sel").draggable({containment:"parent"});$("#satval").mousedown(function(e){offset=$("#satval").offset();if(e.pageY){s=parseInt(e.pageX-offset.left-4);v=parseInt(e.pageY-offset.top-4)}else{s=parseInt(e.clientX-offset.left-document.body.scrollLeft-4);v=parseInt(e.clientY-offset.top-document.body.scrollTop-4)}if(s<0){s=0}if(s>HSV_MAX){s=HSV_MAX}if(v<0){v=0}if(v>HSV_MAX){v=HSV_MAX}$("#sv-sel").css({left:s,top:v});color.from_hsv(color.hue,s/HSV_MAX,(HSV_MAX-v)/HSV_MAX);refresh_color()});$("#h-sel").draggable({containment:"parent",drag:function(e,f){color.from_hsv((HSV_MAX-f.position.top)/HSV_MAX,color.saturation,color.value);update_satval();refresh_color()}});$("#hue").mousedown(function(e){offset=$("#hue").offset();if(e.pageY){h=parseInt(e.pageY-offset.top-4)}else{h=parseInt(e.pageY-offset.top-4)}if(h<0){h=0}if(h>HSV_MAX){h=HSV_MAX}$("#h-sel").css({top:h});color.from_hsv((HSV_MAX-h)/HSV_MAX,color.saturation,color.value);bgc=new Color();bgc.from_hsv(color.hue,1,1);$("#satval").css("background-color","#"+bgc.hex());refresh_color()});$("#edit-text-dialog").dialog({autoOpen:false,width:600,modal:true,open:function(){$(this).css("visibility","visible")},buttons:{Ok:function(){box=_get_box(parseInt($("#boxes li.selected").attr("id")));new_text=$("#edit-text").attr("value");if(box.fields.text!=new_text){box.fields.text=new_text;update_box(box)}$(this).dialog("close")},Cancel:function(){$(this).dialog("close")}}});$("#selected-textalign").click(function(){if($("#boxes li.selected").length==0){return false}box=_get_box(parseInt($("#boxes li.selected").attr("id")));if(box.fields.image){return false}if($("#textalign").css("visibility")=="hidden"){$("#textalign").css({visibility:"visible"})}else{$("#textalign").css({visibility:"hidden"})}});$(".textalign").click(function(){$("#textalign").css({visibility:"hidden"});$("#selected-textalign").attr("src",$(this).attr("src"))});$("#sqr-n, #sqr-s").draggable({axis:"y",drag:function(e,f){height=$("#canvas div.selected").height();if($(this).attr("id")=="sqr-n"){delta=$("#sqr-nw").position().top-f.position.top;$("#canvas div.selected").css({top:f.position.top+4,height:height+delta})}else{delta=$("#sqr-sw").position().top-f.position.top;$("#canvas div.selected").css({height:height-delta})}update_resizers()},stop:finish_resize});$("#sqr-w, #sqr-e").draggable({axis:"x",drag:function(e,f){width=$("#canvas div.selected").width();if($(this).attr("id")=="sqr-w"){delta=$("#sqr-nw").position().left-f.position.left;$("#canvas div.selected").css({left:f.position.left+4,width:width+delta})}else{delta=$("#sqr-ne").position().left-f.position.left;$("#canvas div.selected").css({width:width-delta})}update_resizers()},stop:finish_resize});$("#sqr-nw, #sqr-ne, #sqr-sw, #sqr-se").draggable({drag:function(j,k){width=$("#canvas div.selected").width();height=$("#canvas div.selected").height();var e=$("#boxes li.selected");var l=parseInt(e.attr("id"))-1;var f=boxes[l];aspect_ratio=0;if(f.fields.image){for(ii in box_images){if(box_images[ii].pk==f.fields.image){aspect_ratio=box_images[ii].width/box_images[ii].height;break}}}if($(this).attr("id")=="sqr-nw"){deltaX=$("#sqr-w").position().left-k.position.left;deltaY=$("#sqr-n").position().top-k.position.top;if(aspect_ratio){pos=$("#sqr-se").position();if((width+deltaX)/(height+deltaY)>aspect_ratio){h=height+deltaY;w=parseInt(h*aspect_ratio+0.5)}else{w=width+deltaX;h=parseInt(w/aspect_ratio+0.5)}$("#canvas div.selected").css({top:pos.top-h+4,left:pos.left-w+4,width:w,height:h})}else{$("#canvas div.selected").css({left:k.position.left+4,top:k.position.top+4,width:width+deltaX,height:height+deltaY})}}if($(this).attr("id")=="sqr-sw"){deltaX=$("#sqr-w").position().left-k.position.left;deltaY=$("#sqr-s").position().top-k.position.top;if(aspect_ratio){if((width-deltaX)/(height+deltaY)>aspect_ratio){$("#canvas div.selected").css({left:k.position.left+4,width:width+deltaX,height:parseInt((width+deltaX)/aspect_ratio+0.5)})}else{w=parseInt((height-deltaY)*aspect_ratio+0.5);pos=$("#sqr-ne").position();$("#canvas div.selected").css({left:pos.left-w+4,width:w,height:height-deltaY})}}else{$("#canvas div.selected").css({left:k.position.left+4,width:width+deltaX,height:height-deltaY})}}if($(this).attr("id")=="sqr-ne"){deltaX=$("#sqr-e").position().left-k.position.left;deltaY=$("#sqr-n").position().top-k.position.top;if(aspect_ratio){if((width-deltaX)/(height+deltaY)>aspect_ratio){$("#canvas div.selected").css({top:k.position.top+4,width:parseInt((height+deltaY)*aspect_ratio+0.5),height:height+deltaY})}else{h=parseInt((width-deltaX)/aspect_ratio+0.5);pos=$("#sqr-sw").position();$("#canvas div.selected").css({top:pos.top-h+4,width:width-deltaX,height:h})}}else{$("#canvas div.selected").css({top:k.position.top+4,width:width-deltaX,height:height+deltaY})}}if($(this).attr("id")=="sqr-se"){deltaX=$("#sqr-e").position().left-k.position.left;deltaY=$("#sqr-s").position().top-k.position.top;if(aspect_ratio){if((width+deltaX)/(height+deltaY)>aspect_ratio){$("#canvas div.selected").css({width:width-deltaX,height:parseInt((width-deltaX)/aspect_ratio+0.5)})}else{$("#canvas div.selected").css({width:parseInt((height-deltaY)*aspect_ratio+0.5),height:height-deltaY})}}else{$("#canvas div.selected").css({width:width-deltaX,height:height-deltaY})}}update_resizers()},stop:finish_resize});$("#set-font-dialog").mouseleave(function(){$(this).css({visibility:"hidden"})});$("a.lnk-undo").click(function(){if(present_boxes_index){boxes=JSON.parse(_history[present_boxes_index-1]);present_boxes_index--;undo_or_redo_pressed=true;unselect_box();update_all_boxes()}return false});$("a.lnk-redo").click(function(){if(present_boxes_index<_history.length-1){boxes=JSON.parse(_history[present_boxes_index+1]);present_boxes_index++;undo_or_redo_pressed=true;unselect_box();update_all_boxes()}return false});$("a.lnk-revert").click(function(){if(present_boxes_index){boxes=JSON.parse(_history[0]);present_boxes_index=0;undo_or_redo_pressed=true;unselect_box();update_all_boxes()}return false})});function _in_array(e,d){for(i in d){if(d[i]==e){return true}}return false}function _clog(d){try{console.log(d)}catch(f){}}function redraw_canvas(d){$(".class").unbind("click");$("#canvas div.cbox").unbind("mousedown");$("#boxes li").unbind("mousedown");$("#canvasimage").unbind("mousedown");if(d){r=d;boxes=d.boxes;box_images=d.images;if(boxes){if(undo_or_redo_pressed){undo_or_redo_pressed=false}else{if(_history[present_boxes_index]!=JSON.stringify(boxes)){_history.splice(present_boxes_index+1,_history.length);_history.push(JSON.stringify(boxes));present_boxes_index=_history.length-1}}}if(d.selected){$("#product-name").html(d.selected.product.name);$(".buy-acc .cont h3").text(d.selected.product.name);$("#starting-from").text(d.selected.product.start_price);$("#product-description p").html(d.selected.product.description);$("#updated-price").html(d.selected.product.price+" &euro;");if(d.selected.product.details){$("#fitted").unbind("click");$("#fitted").click(function(){window.open(d.selected.product.details,"_blank","height=450,width=600,toolbar=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=no");return false});$("div.info-hold div.image").show()}else{$("div.info-hold div.image").hide()}}if(d.options){if(d.options.colors&&d.options.colors.length>1){$("#colors").html("");for(i in d.options.colors){c=d.options.colors[i];html='<li id="'+c.id+'_color"';if(c.selected){html+=' class="sel"'}html+='><img src="'+c.image+'" title="'+c.name+'" alt="'+c.name+'" />';$("#colors").append(html)}$("#colors li").unbind("click");$("#colors li").click(function(){change_color($(this))});$("div.color-box").show()}else{$("div.color-box").hide()}if(d.options.sizes&&d.options.sizes.length>1){$("#sizes").html("");for(i in d.options.sizes){s=d.options.sizes[i];html='<li id="'+s.id+'_size"';if(s.selected){html+=' class="sel"'}html+="><div>"+s.name+"</div>";$("#sizes").append(html)}$("#sizes li").unbind("click");$("#sizes li").click(function(){change_size($(this))});$("div.size-box").show()}else{$("div.size-box").hide()}if(d.options.models){if(d.options.models.length<2){$(".available-models").hide()}else{$(".available-models").show()}$("#models").html("");for(i in d.options.models){m=d.options.models[i];html='<li id="'+m.id+'_model"';if(m.id==d.selected.model.id){html+=' class="selected"'}html+='><img src="'+m.image+'">';html+="<span>"+m.name+"</span></a></li>";$("#models").append(html)}$("#models li").unbind("click");$("#models li").click(function(){selected_tab="model";smi=parseInt($(this).attr("id"));change_option("model",smi)})}if(d.options.areas){if(d.options.areas.length<2){$(".available-areas").hide()}else{$(".available-areas").show()}$("#areas").html("");for(i in d.options.areas){a=d.options.areas[i];html='<li id="'+a.id+'_area"';if(a.id==d.selected.area.id&&a.has_boxes){html+=' class="selected has_boxes"'}else{if(a.has_boxes){html+=' class="has_boxes"'}if(a.id==d.selected.area.id){html+=' class="selected"';$("#edit-box").show()}else{$("#edit-box").hide()}}html+='><img class="area" src="'+a.image+'">';html+="<span>"+a.name;html+="</span></a>";if(a.dpi_info){if(a.dpi_info<0){html+='<img class="dpi" src="/s/img/edit/icon-bad16.png" />'}else{if(a.dpi_info<1){html+='<img class="dpi" src="/s/img/edit/icon-so-so16.png" />'}else{html+='<img class="dpi" src="/s/img/edit/icon-good16.png" />'}}}html+="</li>";$("#areas").append(html)}$("#areas li").unbind("click");$("#areas li").click(function(){unselect_box();selected_tab="model";sai=parseInt($(this).attr("id"));change_option("area",sai)})}if(d.options.printareas){if(d.options.printareas.length<2){$(".print-box").hide()}else{$(".print-box").show()}$("#printareas").html("");for(i in d.options.printareas){p=d.options.printareas[i];html='<li><input type="radio" name="printarea" class="radio" value="'+p.id+'" ';if(p.selected){html+=' checked="checked"'}html+='/><label for="a4-v">'+p.display+"</label></li>";$("#printareas").append(html)}$("input[type=radio][name=printarea]").unbind("click");$("input[type=radio][name=printarea]").click(function(){change_option("printarea",$(this).attr("value"))})}}if(d.canvas_data){WIDTH=d.canvas_data.dimension[0];HEIGHT=d.canvas_data.dimension[1];var f=WIDTH>HEIGHT?WIDTH:HEIGHT;LEFT=d.canvas_data.upperleft[0]-1;UPPER=d.canvas_data.upperleft[1]-1}if(d.images&&d.images.length){$(".image-quality a").hide();if(d.dpi_ratio<0){$("a.image-bad").show()}else{if(d.dpi_ratio>=1){$("a.image-good").show()}else{$("a.image-so-so").show()}}$(".image-quality").show()}else{$(".image-quality").hide()}if(d.dpi_ratio){}if(d.boxes.length>0){$("#has-boxes").show();$("a.lnk-zoom").show()}else{$("#has-boxes").hide();$("a.lnk-zoom").hide()}}$("#canvas").css({left:LEFT,top:UPPER,width:WIDTH,height:HEIGHT});$("#boxes").html("");$("#canvas-boxes").html("");$("#guides").html("");$("#guides").append('<div class="guide" style="width: '+WIDTH+"px; height: "+HEIGHT+'px; position: absolute; top: 0px; left: 0px;"><div>');dpi_alert_active=false;$("#custom-colors").html("");var e=new Array();for(i in boxes){box=boxes[i];boxli_id=box.fields.seqno+"_boxli";if(box.fields.visible){xl=parseInt(box.fields.x*WIDTH);xr=parseInt(box.fields.x*WIDTH+box.fields.width*f);yt=parseInt(box.fields.y*HEIGHT);yb=parseInt(box.fields.y*HEIGHT+box.fields.height*f);$("#guides").append('<div class="guide" style="border-left: 1px dotted #aaf; width: 0px; height: '+f+"px; position: absolute; top: 0px; left: "+xl+'px;"><div>');$("#guides").append('<div class="guide" style="border-left: 1px dotted #aaf; width: 0px; height: '+f+"px; position: absolute; top: 0px; left: "+(xr+1)+'px;"><div>');$("#guides").append('<div class="guide" style="border-top: 1px dotted #aaf; width: '+f+"px; height: 0px; position: absolute; top: "+yt+'px; left: 0px;"><div>');$("#guides").append('<div class="guide" style="border-top: 1px dotted #aaf; width: '+f+"px; height: 0px; position: absolute; top: "+(yb+1)+'px; left: 0px;"><div>')}element='<li id="'+boxli_id+'">';if(box.fields.image){if(box.fields.dpialert){dpi_alert_active=true}for(ii in box_images){if(box_images[ii].pk==box.fields.image){element+='<img class="image-icon" src="'+box_images[ii].tinyimg+'"/>';element+='<span class="box-text">'+box_images[ii].image.split("/").pop()+"</span>";break}}}else{element+='<img class="text-icon" src="/s/img/edit/icon-edit-text.gif" />';element+='<span class="box-text">';if(box.fields.text.length>50){element+=box.fields.text.substring(0,50)+"..."}else{element+=box.fields.text}element+="</span>";uc_string="#"+e.join("#")+"#";if(uc_string.indexOf("#"+box.fields.fontcolor+"#")==-1){e.push(box.fields.fontcolor);$("#custom-colors").append('<li style="background-color: rgb('+box.fields.fontcolor+');"></li>')}}element+='<img class="action box-del" src="/s/img/edit/icon-delete.gif" alt="Izbriši element" title="Izbriši element" />';if(!box.fields.image){element+='<img class="action box-edit" id="'+box.fields.seqno+'_edit" src="/s/img/edit/icon-edit-font-color-size.png" alt="Uredi besedilo" title="Spremeni tip, barvo ali velikost pisave" />';element+='<img class="action change-text" id="'+box.fields.seqno+'_txt" src="/s/img/edit/icon-change-text.png" alt="Spremeni besedilo" title="Spremeni besedilo" />'}$("#boxes").prepend(element);if(!box.fields.image){color.from_string(box.fields.fontcolor);$("#"+boxli_id+" .edit-col").css("background","#"+color.hex())}$("#"+boxli_id+" .edit-col").unbind("click");$("#"+boxli_id+" .edit-col").click(function(){if($("#colorpick").is(":visible")){$("#colorpick").hide("fast")}else{update_colorpick();cp=$("#colorpick");cp.css("visibility","hidden");cp.show();if($("#boxes li.selected").length==0){return false}box=_get_box(parseInt($("#boxes li.selected").attr("id")));if(box.fields.image){return false}p1=$(this).position();o1=$(this).offset();cp.css(p1);p2=cp.position();o2=cp.offset();p2.left-=o2.left-o1.left;p2.top-=o2.top-o1.top-20;cp.css(p2);cp.hide();cp.css("visibility","visible");cp.show("fast")}});if(!box.fields.visible){continue}boxdiv_id=box.fields.seqno+"_boxdiv";$("#canvas-boxes").append('<div class="cbox" id="'+boxdiv_id+'"></div>');x=parseInt(box.fields.x*WIDTH-1),y=parseInt(box.fields.y*HEIGHT-1),w=parseInt(box.fields.width*WIDTH),h=parseInt(box.fields.height*HEIGHT),$("#"+boxdiv_id).css({left:parseInt(box.fields.x*WIDTH-1),top:parseInt(box.fields.y*HEIGHT-1),width:parseInt(box.fields.width*f),height:parseInt(box.fields.height*f),"z-index":30+box.fields.seqno});$("#"+boxdiv_id).draggable({snap:".guide",snapTolerance:5,start:function(){box=_get_box(parseInt(this.id));$(".resizer").css("visibility","hidden");$(this).css({background:"url(/design/"+box.fields.seqno+"/?r="+Math.random()+") -"+parseInt(WIDTH*box.fields.x)+"px -"+parseInt(HEIGHT*box.fields.y)+"px",opacity:"0.5"})},stop:function(){newx=parseInt($(this).css("left"));newy=parseInt($(this).css("top"));newbox=_get_box(parseInt(this.id));newbox.fields.x=newx/WIDTH;newbox.fields.y=newy/HEIGHT;box.fields.vcentered=box.fields.hcentered=false;update_box(newbox);update_resizers();$(".resizer").css("visibility","visible")}})}$("#remove-white").unbind("click");$("#remove-white").click(function(j){box=_get_box(parseInt($("#boxes li.selected").attr("id")));box.fields.remove_white=$(this).attr("checked");update_box(box)});$("#custom-colors li").unbind("click");$("#custom-colors li").click(function(){color.from_string($(this).css("background-color"));update_satval();update_colorpick();update_box_color()});if(dpi_alert_active){$("img.alert").show()}else{$("img.alert").hide()}$("#boxes .change-text").unbind("click");$("#boxes .change-text").click(function(){select_box(parseInt($(this).parent().attr("id")));$("#change-text-dialog").dialog("open");return false});$("#boxes .box-edit").unbind("click");$("#boxes .box-edit").click(function(){select_box(parseInt($(this).attr("id")));$(this).parent().dblclick();return false});$("#canvas div.cbox").unbind("dblclick");$("#canvas div.cbox").dblclick(open_font_or_image_dialog);$("#boxes li").unbind("dblclick");$("#boxes li").dblclick(open_font_or_image_dialog);$("#canvas div.cbox").unbind("mousedown");$("#canvas div.cbox").mousedown(function(){select_box(parseInt(this.id));$("#text-edit-popup").hide()});$("#boxes li").unbind("click");$("#boxes li").click(function(){select_box(parseInt(this.id));$("#text-edit-popup").hide()});$("#canvasimage").unbind("mousedown");$("#canvasimage").mousedown(unselect_box);$("#boxes").sortable({axis:"y",opacity:0.5,update:sort_boxes});$(".box-del").unbind("click");$(".box-del").click(function(){delete_box(parseInt(this.parentNode.id));return false});if(selected_box_seqno){box=_get_box(selected_box_seqno);if(box&&box.fields.visible&&!box.fields.locked){select_box(selected_box_seqno);color.from_string(box.fields.fontcolor)}}else{$("#boxes li").removeClass("selected");$("#canvas-boxes div").removeClass("selected");unselect_box()}update_resizers();if($.cookie("show_guides")){$(".guide").css("visibility","visible")}else{$(".guide").css("visibility","hidden")}delete pic;pic=new Image();if(selected_tab=="design"){pic.src="/design/?r="+SHA1(JSON.stringify(boxes)+sci)}if(selected_tab=="model"){pic.src="/model/?r="+SHA1(JSON.stringify(boxes)+sci+" "+smi+" "+sai)}if(selected_tab=="zoom"){pic.src="/zoom/?r="+Math.random()}if(pic.complete){end_wait()}else{pic.onload=end_wait}if(selected_tab=="design"){document.getElementById("canvasimage").src=pic.src}if(selected_tab=="model"){document.getElementById("model").src=pic.src}}function increase_upload_progress_bar(){img=$("#ajax-loader img");width=parseInt(img.css("width"));width+=5;img.css("width",width+"px")}function open_font_or_image_dialog(n){box=_get_box(parseInt($(this).attr("id")));if(!box){box=_get_box(parseInt($("#boxes li.selected").attr("id")))}if(box.fields.image){}else{update_colorpick();var d=$("#text-edit-popup");var q=$(this).offset();var f=$(this).height();var o=$(this).width();var j=d.width();var l=parseInt(q.left)+o/2-j/2;var k=parseInt(q.top)+f;if(l<5){l=5}d.css({left:l+"px",top:k+"px"});d.show()}}function open_step(d){if(d.hasClass("disabled")){return}if(d.hasClass("active")){return}unselect_box();$(".edit-holder .box.active").removeClass("active");d.addClass("active");if(d.hasClass("addimg-acc")&&!my_images){$.ajax({type:"POST",url:"/images/",dataType:"json",success:handle_images_response,cache:false})}}function _strip(d){return d.replace(/^[\s\r\n]*/,"").replace(/[\s\r\n]*$/,"")}function add_text(){var d=_strip($("#text-to-add").attr("value"));if(d!=""){add_box(encodeURIComponent(d));$("#text-to-add").val($("#text-to-add").text());$(".addtext-acc").removeClass("active");$(".edit-acc").addClass("active")}}function scroll(d,e){}function activate_view_tab(d){wait();tab=$("#"+d);if(d=="design"){$("#canvas").show();$("#model").hide();$("#zoom").hide();selected_tab="design";$.ajax({type:"GET",url:"/canvas/",dataType:"json",success:redraw_canvas,cache:false});return}delete pic;pic=new Image();pic.onload=end_wait;if(d=="model"){$("#canvas").hide();$("#model").show();$("#zoom").hide();selected_tab="model";pic.src="/model/?r="+Math.random();$("#model").attr("src",pic.src);return}}function change_color(d){wait();sci=parseInt(d.attr("id"));change_option("color",sci);$("#colors li.active").removeClass("active");d.addClass("active")}function change_size(d){wait();change_option("size",parseInt(d.attr("id")));$("#sizes li.active").removeClass("active");d.addClass("active")}function change_product(){wait();change_option("product",parseInt($(this).attr("id")));$("#products li.selected").removeClass("selected");$(this).parent().addClass("selected");if(selected_tab=="design"){activate_view_tab("tab-model")}else{activate_view_tab("tab-"+selected_tab)}}function toggle_guides(){var d=$.cookie("show_guides");if(d){$(".guide").css("visibility","hidden");$.cookie("show_guides","")}else{$(".guide").css("visibility","visible");$.cookie("show_guides",1)}}function finish_resize(){box_seqno=parseInt($("#canvas div.selected").attr("id"));box=_get_box(box_seqno);MAX=WIDTH>HEIGHT?WIDTH:HEIGHT;box.fields.width=parseInt($("#canvas div.selected").css("width"))/MAX;box.fields.height=parseInt($("#canvas div.selected").css("height"))/MAX;newx=parseInt($("#canvas div.selected").css("left"));newy=parseInt($("#canvas div.selected").css("top"));box.fields.x=newx/WIDTH;box.fields.y=newy/HEIGHT;update_box(box)}function update_resizers(){if($("#canvas div.selected").length==0){return}selected=$("#canvas div.selected");P=selected.position();H=selected.height();W=selected.width();$("#sqr-nw").css({left:P.left-4,top:P.top-4});$("#sqr-ne").css({left:P.left+W-4,top:P.top-4});$("#sqr-sw").css({left:P.left-4,top:P.top+H-4});$("#sqr-se").css({left:P.left+W-4,top:P.top+H-4});$("#sqr-n").css({left:P.left+W/2-4,top:P.top-4});$("#sqr-s").css({left:P.left+W/2-4,top:P.top+H-4});$("#sqr-w").css({left:P.left-4,top:P.top+H/2-4});$("#sqr-e").css({left:P.left+W-4,top:P.top+H/2-4});$(".border.left").css({height:selected.css("height")});$(".border.right").css({height:selected.css("height"),left:selected.css("width")});$(".border.top").css({width:selected.css("width")});$(".border.bottom").css({width:selected.css("width"),top:selected.css("height")})}function unselect_box(){$("#canvas div.selected").removeClass("selected").html("");$("#boxes li.selected").removeClass("selected");$(".resizer").css("visibility","hidden");selected_box_seqno=0;$("#edit-box").hide();$("#text-edit-popup").hide()}function select_box(d){$(".edit-holder .box.active").removeClass("active");$(".edit-holder .edit-acc").addClass("active");selected_box_seqno=d;box=_get_box(d);if(!box.fields.visible){unselect_box();return}if(box.fields.remove_white){$("#remove-white").attr("checked","checked")}else{$("#remove-white").attr("checked","")}$("#edit-box").show();if(box.fields.image){$("#image-edit").show()}else{$("#image-edit").hide()}$("#selected-font img").attr("src","/font/"+box.fields.fontfamily+"/");$("#font-list li.sel").removeClass("sel");selfont=$("#font-list span.sprite-"+box.fields.fontfamily.replace(/ /g,"-"));selfont.addClass("sel");$("#fontsize li.sel").removeClass("sel");$("#f"+parseInt(box.fields.fontsize*100)).addClass("sel");update_colorpick();$("#boxes li.selected").removeClass("selected");$("#"+d+"_boxli").addClass("selected");prev_id=parseInt($("#canvas div.selected").attr("id"));if(prev_id){prev_box=_get_box(prev_id);$("#canvas div.selected").css("z-index",30+prev_box.fields.seqno)}$("#canvas div.selected").html("");$("#canvas div.selected").removeClass("selected");selected=$("#"+d+"_boxdiv");selected.addClass("selected").css("z-index","50");selected.append('<div class="outer"><div class="border top"></div><div class="border left"></div><div class="border right"></div><div class="border bottom"></div></div>');$(".border.left").css({height:selected.css("height")});$(".border.right").css({height:selected.css("height"),left:selected.css("width")});$(".border.top").css({width:selected.css("width")});$(".border.bottom").css({width:selected.css("width"),top:selected.css("height")});if(!box.fields.image){$("#selected-fontsize").text(parseInt(box.fields.fontsize*100));color.from_string(box.fields.fontcolor);$("#colorpick-link").css("background","#"+color.hex())}$("#set-font-dialog").css({visibility:"hidden"});update_resizers();$(".resizer").css({visibility:"visible"})}function save_fonts(d){fonts=d;fontlist=$("#font-list");for(i in fonts){fontlist.append('<span class="font sprite-'+fonts[i].replace(/ /g,"-")+'">'+fonts[i]+"</span>")}$("#font-list span.font").unbind("click");$("#font-list span.font").click(function(){box=_get_box(parseInt($("#boxes li.selected").attr("id")));box.fields.fontfamily=$(this).text();update_box(box);$("#selected-font img").attr("src","/font/"+box.fields.fontfamily+"/");$("#font-list span.sel").removeClass("sel");$(this).addClass("sel")})}function wait(){$("#wait").show()}function end_wait(){if(selected_tab=="model"){$("#canvas").hide();$("#model").show()}if(selected_tab=="design"){$("#model").hide();$("#canvas").show()}$("#wait").hide()}function display_target_products(d){html="";for(i in d){html+='<li><img src="'+d[i].image+'" alt="" class="product" id="'+d[i].id+'_product" /></li>'}$("#products").html(html);$(".gallery .gallery-box ul").css("margin-left","0");$("img.product").unbind("click");$("img.product").click(change_product)}function handle_images_response(d){if(just_uploaded_image_id){add_box("",just_uploaded_image_id);just_uploaded_image_id=0;$("#add-image-dialog").dialog("close")}my_images=d.reverse();var e=$("#images-list");e.html("");for(i in my_images){e.append('<li id="'+my_images[i].pk+'_ui" class="im-upload"><center><img src="'+my_images[i].thumb+'" alt="" /></center></li>')}$("li.im-upload").unbind("click");$("li.im-upload").click(function(){add_box("",parseInt($(this).attr("id")));$("#add-image-dialog").dialog("close")});if($("#lnk-myimages").hasClass("active")){$("div.ajax-loader").hide();$("div.upload-form").show()}}function display_images_page(e){var l=8;var j=7;var f=$("#images-list");var k=my_images.slice(l*(e-1),l*e);f.html("");for(i in k){f.append('<li id="'+k[i].pk+'_ui" class="im-upload"><center><img src="'+k[i].thumb+'" alt="" /><!--a class="image-delete">Close</a--></center></li>')}var d=Math.ceil(my_images.length/l);pagelist=$("#images-list-pages");pagelist.html("");if(d>1){pagelist=$("#images-list-pages");pagelist.html("");if(e<=4){start=1;end=d<j?d:j}else{if(d-e<4){end=d;start=1<(d-j+1)?(d-j+1):1}else{start=e-3;end=e+3}}for(i=start;i<=end;i++){if(i==e){pagelist.append('<li class="selected" id="'+i+'_pg">'+i+"</li>")}else{pagelist.append('<li id="'+i+'_pg">'+i+"</li>")}}$("#images-list-pages li").unbind("click");$("#images-list-pages li").click(function(){$("#images-list-pages li.selected").removeClass("selected");$(this).addClass("selected");e=parseInt($(this).attr("id"));display_images_page(e)})}$("li.im-upload").unbind("click");$("li.im-upload").click(function(){add_box("",parseInt($(this).attr("id")));$("#add-image-dialog").dialog("close")})}function display_fonts(d){}function update_products(){}function change_option(e,d){if(!d){var d=$("#"+e+"s option:selected").attr("value")}if(!d){return}wait();$.ajax({type:"POST",cache:false,async:false,url:"/active_"+e+"/",data:"id="+d,dataType:"json",success:redraw_canvas})}function sort_boxes(e,f){wait();var d=$("#boxes").sortable("toArray");pks=new Array();new_selected_box_seqno=0;for(i in d){index=parseInt(d[i]);if(selected_box_seqno==index){new_selected_box_seqno=parseInt(i)}pks.push(index)}if(new_selected_box_seqno){selected_box_seqno=new_selected_box_seqno}$.ajax({type:"POST",url:"/canvas/sort_boxes/",data:"sort_order="+pks.reverse().join(","),dataType:"json",success:redraw_canvas,cache:false})}function update_all_boxes(){wait();$.ajax({type:"POST",url:"/canvas/update_boxes/",data:JSON.stringify(boxes),dataType:"json",success:redraw_canvas,cache:false})}function delete_box(d){if(confirm("Ali želite zbrisati element?")){wait();selected_box_seqno=0;$(".resizer").css("visibility","hidden");$.ajax({type:"post",url:"/canvas/"+d+"/delete/",dataType:"json",success:redraw_canvas,cache:false})}}function update_box(d){if(d){wait();$.ajax({type:"POST",url:"/canvas/"+d.fields.seqno+"/",dataType:"json",data:JSON.stringify(d),success:redraw_canvas,cache:false})}}function update_seleted_box(){boxid=parseInt($("#canvas div.selected").attr("id"));box=_get_box(boxid);update_box(box)}function update_box_color(){selected_box_seqno=parseInt($("#boxes li.selected").attr("id"));if(selected_box_seqno){box=_get_box(selected_box_seqno);box.fields.fontcolor=color.to_string();update_box(box)}}function add_box(e,d){wait();data="text="+e;if(d){data+="&image="+d}max_id=parseInt($("#boxes li").attr("id"));selected_box_seqno=max_id+1;$.ajax({type:"POST",url:"/canvas/add_box/",dataType:"json",data:data,success:redraw_canvas,cache:false,error:function(){alert("Prišlo je do napake pri dodajanju elementa.\n\nV kolikor je šlo za sliko, te prosimo, da poizkusiš spremeniti format slike v JPG, ali PNG. Včasih se zgodi, da sistem ne more prebaviti kakšne slike, zato jo poizkusi posneti ali v drug format, ali pa jo posnemi z drugim programom.")}})}function get_selected_box(){var d=$("#canvas div.selected");if(d.length==0){return false}xpos=parseInt(d.css("left"));ypos=parseInt(d.css("top"));box=_get_box(parseInt(d.attr("id")));return box}function move_left(d){box=get_selected_box();if(!box){return false}box.fields.hcentered=false;MOVE=10;if(d.shiftKey){MOVE=40}box.fields.x=(xpos-MOVE)/WIDTH;update_box(box)}function move_right(d){box=get_selected_box();if(!box){return false}box.fields.hcentered=false;MOVE=10;if(d.shiftKey){MOVE=40}box.fields.x=(xpos+MOVE)/WIDTH;update_box(box)}function move_up(d){box=get_selected_box();if(!box){return false}box.fields.vcentered=false;MOVE=10;if(d.shiftKey){MOVE=40}box.fields.y=(ypos-MOVE)/HEIGHT;update_box(box)}function move_down(d){box=get_selected_box();if(!box){return false}box.fields.vcentered=false;MOVE=10;if(d.shiftKey){MOVE=40}box.fields.y=(ypos+MOVE)/HEIGHT;update_box(box)}function move_center(d){boxalign_center_h();boxalign_center_v()}function key_down(d){}function text_align(e){var d=$("#canvas div.selected");if(d.length==0){return}box=_get_box(parseInt(d.attr("id")));if(e==box.fields.alignment){return}box.fields.alignment=e;update_box(box)}function boxalign_center(){var d=$("#canvas div.selected");if(d.length==0){return}box=_get_box(parseInt(d.attr("id")));MAX=WIDTH>HEIGHT?WIDTH:HEIGHT;x=0.5-(box.fields.width*MAX/(WIDTH*1))/2;y=0.5-(box.fields.height*MAX/(HEIGHT*1))/2;if(y==box.fields.y&&x==box.fields.x){return}box.fields.y=y;box.fields.x=x;box.fields.vcentered=box.fields.hcentered=true;update_box(box);return false}function boxalign_center_h(){var d=$("#canvas div.selected");if(d.length==0){return}box=_get_box(parseInt(d.attr("id")));box.fields.hcentered=true;MAX=WIDTH>HEIGHT?WIDTH:HEIGHT;x=0.5-(box.fields.width*MAX/(WIDTH*1))/2;if(x==box.fields.x){return}box.fields.x=x;update_box(box);return false}function boxalign_center_v(){var d=$("#canvas div.selected");if(d.length==0){return}box=_get_box(parseInt(d.attr("id")));box.fields.vcentered=true;MAX=WIDTH>HEIGHT?WIDTH:HEIGHT;y=0.5-(box.fields.height*MAX/(HEIGHT*1))/2;if(y==box.fields.y){return}box.fields.y=y;update_box(box);return false}function boxalign_upleft(){var d=$("#canvas div.selected");if(d.length==0){return}box=_get_box(parseInt(d.attr("id")));box.fields.vcentered=box.fields.hcentered=false;if(box.fields.y==0&&box.fields.x==0){return}box.fields.x=0;box.fields.y=0;update_box(box)}function boxalign_upright(){var e=$("#canvas div.selected");if(e.length==0){return}box=_get_box(parseInt(e.attr("id")));box.fields.vcentered=box.fields.hcentered=false;MAX=WIDTH>HEIGHT?WIDTH:HEIGHT;var d=1-(box.fields.width*MAX/(WIDTH*1));if(box.fields.y==0&&box.fields.x==d){return}box.fields.x=d;box.fields.y=0;update_box(box)}function boxalign_downleft(){var d=$("#canvas div.selected");if(d.length==0){return}box=_get_box(parseInt(d.attr("id")));box.fields.vcentered=box.fields.hcentered=false;MAX=WIDTH>HEIGHT?WIDTH:HEIGHT;var e=1-(box.fields.height*MAX/(HEIGHT*1));if(box.fields.y==e&&box.fields.x==0){return}box.fields.x=0;box.fields.y=e;update_box(box)}function boxalign_downright(){var e=$("#canvas div.selected");if(e.length==0){return}box=_get_box(parseInt(e.attr("id")));box.fields.vcentered=box.fields.hcentered=false;MAX=WIDTH>HEIGHT?WIDTH:HEIGHT;var d=1-(box.fields.width*MAX/(WIDTH*1));var f=1-(box.fields.height*MAX/(HEIGHT*1));if(box.fields.y==f&&box.fields.x==d){return}box.fields.x=d;box.fields.y=f;update_box(box)}function boxalign_top(){var d=$("#canvas div.selected");if(d.length==0){return}box=_get_box(parseInt(d.attr("id")));box.fields.vcentered=false;if(box.fields.y==0){return}box.fields.y=0;update_box(box)}function boxalign_bottom(){var d=$("#canvas div.selected");if(d.length==0){return}box=_get_box(parseInt(d.attr("id")));box.fields.vcentered=false;MAX=WIDTH>HEIGHT?WIDTH:HEIGHT;var e=1-(box.fields.height*MAX/(HEIGHT*1));if(e==box.fields.y){return}box.fields.y=e;update_box(box)}function boxalign_left(){var d=$("#canvas div.selected");if(d.length==0){return}box=_get_box(parseInt(d.attr("id")));box.fields.hcentered=false;if(box.fields.x==0){return}box.fields.x=0;update_box(box)}function boxalign_right(){var e=$("#canvas div.selected");if(e.length==0){return}box=_get_box(parseInt(e.attr("id")));box.fields.hcentered=false;MAX=WIDTH>HEIGHT?WIDTH:HEIGHT;var d=1-(box.fields.width*MAX/(WIDTH*1));if(d==box.fields.x){return}box.fields.x=d;update_box(box)}function update_color(d){offset=$("#satval").offset();if(d.pageY){s=parseInt(d.pageX-offset.left-4);v=parseInt(d.pageY-offset.top-4)}else{s=parseInt(d.clientX-offset.left-document.body.scrollLeft-4);v=parseInt(d.clientY-offset.top-document.body.scrollTop-4)}if(s<0){s=0}if(s>HSV_MAX){s=HSV_MAX}if(v<0){v=0}if(v>HSV_MAX){v=HSV_MAX}$("#sv-sel").css({left:s,top:v});color.from_hsv(color.hue,s/HSV_MAX,(HSV_MAX-v)/HSV_MAX);update_box_color()}function refresh_color(){$("#selected-color").css({background:"#"+color.hex(),color:"#"+color.get_inverse().hex()});$("#selected-color").attr("value","#"+color.hex());$("#sample-text").css("color","#"+color.hex())}function update_satval(){bgc=new Color();bgc.from_hsv(color.hue,1,1);$("#satval").css("background-color","#"+bgc.hex())}function update_colorpick(){color.to_hsv();h=parseInt(HSV_MAX-color.hue*HSV_MAX);s=parseInt(color.saturation*HSV_MAX);v=parseInt(HSV_MAX-color.value*HSV_MAX);$("#sv-sel").css({left:s,top:v});$("#h-sel").css({top:h});refresh_color();update_satval()}function Color(){this.red=0;this.green=0;this.blue=0;this.hue=0;this.saturation=0;this.value=0;this.num="0123456789abcdef";this.from_hsv=hsv2rgb;this.to_hsv=rgb2hsv;this.rgb=rgb;this.hex=hex;this.get_inverse=get_inverse;this.from_string=from_string;this.to_string=to_string}function rgb(f,e,d){this.red=f;this.green=e;this.blue=d}function to_string(){return this.red+","+this.green+","+this.blue}function from_string(d){if(d.indexOf("rgb(")==0){d=d.slice(4,-1)}if(d.indexOf("rgba(")==0){d=d.slice(5,-1)}if(d.indexOf("#")==0){d=d.slice(1);this.red=parseInt(d.slice(0,2),16);this.green=parseInt(d.slice(2,4),16);this.blue=parseInt(d.slice(4,6),16);return}splstr=d.split(",");this.red=parseInt(splstr[0]);this.green=parseInt(splstr[1]);this.blue=parseInt(splstr[2])}function get_inverse(){inv=new Color();inv.red=255-this.red;inv.green=255-this.green;inv.blue=255-this.blue;return inv}function hex(f){var e=this.red.toString(16);var d=this.green.toString(16);var j=this.blue.toString(16);if(e.length==1){e="0"+e}if(d.length==1){d="0"+d}if(j.length==1){j="0"+j}return e+d+j}function min(e,d){if(e<d){return e}return d}function max(e,d){if(e>d){return e}return d}function min3(e,d,f){if(d<f){m=d}else{m=f}if(e<m){return e}return m}function max3(e,d,f){if(d>f){m=d}else{m=f}if(e>m){return e}return m}function rgb2hsv(f,e,d){min=min3(this.red,this.green,this.blue);max=max3(this.red,this.green,this.blue);if(max==0){this.hue=0;this.saturation=0;this.value=0;return}this.value=max/255;f=this.red/max;e=this.green/max;d=this.blue/max;min=min3(f,e,d);max=max3(f,e,d);this.saturation=max-min;if(max==min){this.hue=0;return}f=(f-min)/this.saturation;e=(e-min)/this.saturation;d=(d-min)/this.saturation;if(max==f){this.hue=0+60*(e-d);if(this.hue<0){this.hue+=360}}else{if(max==e){this.hue=120+60*(d-f)}else{this.hue=240+60*(f-e)}}this.hue/=360}function hsv2rgb(f,e,d){if(f==1){f=0}this.hue=f;this.saturation=e;this.value=d;if(e==0){r=g=b=d}else{var_h=f*6;var_i=Math.floor(var_h);var_1=d*(1-e);var_2=d*(1-e*(var_h-var_i));var_3=d*(1-e*(1-(var_h-var_i)));if(var_i==0){r=d;g=var_3;b=var_1}else{if(var_i==1){r=var_2;g=d;b=var_1}else{if(var_i==2){r=var_1;g=d;b=var_3}else{if(var_i==3){r=var_1;g=var_2;b=d}else{if(var_i==4){r=var_3;g=var_1;b=d}else{r=d;g=var_1;b=var_2}}}}}}this.red=parseInt(r*255);this.green=parseInt(g*255);this.blue=parseInt(b*255)}function _get_box(d){for(i in boxes){if(boxes[i].fields.seqno==d){return boxes[i]}}return null}$(document).ready(function(){$.ajax({type:"GET",url:"/canvas/",dataType:"json",success:redraw_canvas,cache:false});fontsizes=Array(1,2,3,4,5,6,7,8,9,10,12,14,16,18,20,24,28,32,36,40,50,60,70,80,90,100,120,150,200,250,300);for(i in fontsizes){$("#fontsize").append('<li class="fontsize" id="f'+fontsizes[i]+'">'+fontsizes[i]+"</li>")}$("#fontsize li").click(function(){box=_get_box(parseInt($("#boxes li.selected").attr("id")));box.fields.fontsize=parseFloat($(this).text()/100);update_box(box);$("#fontsize li.sel").removeClass("sel");$(this).addClass("sel")});if($.cookie("show_guides")){$("#show-guides").attr("checked",true)}else{$("#show-guides").attr("checked",false)}selected_tab="model";$.ajax({type:"GET",url:"/fonts/",dataType:"json",success:save_fonts})});function SHA1(l){function k(B,A){var j=(B<<A)|(B>>>(32-A));return j}function L(C){var B="";var j;var D;var A;for(j=0;j<=6;j+=2){D=(C>>>(j*4+4))&15;A=(C>>>(j*4))&15;B+=D.toString(16)+A.toString(16)}return B}function N(C){var B="";var A;var j;for(A=7;A>=0;A--){j=(C>>>(A*4))&15;B+=j.toString(16)}return B}function e(A){A=A.replace(/\r\n/g,"\n");var j="";for(var C=0;C<A.length;C++){var B=A.charCodeAt(C);if(B<128){j+=String.fromCharCode(B)}else{if((B>127)&&(B<2048)){j+=String.fromCharCode((B>>6)|192);j+=String.fromCharCode((B&63)|128)}else{j+=String.fromCharCode((B>>12)|224);j+=String.fromCharCode(((B>>6)&63)|128);j+=String.fromCharCode((B&63)|128)}}}return j}var q;var Q,O;var f=new Array(80);var F=1732584193;var u=4023233417;var t=2562383102;var o=271733878;var n=3285377520;var M,K,J,I,G;var S;l=e(l);var d=l.length;var z=new Array();for(Q=0;Q<d-3;Q+=4){O=l.charCodeAt(Q)<<24|l.charCodeAt(Q+1)<<16|l.charCodeAt(Q+2)<<8|l.charCodeAt(Q+3);z.push(O)}switch(d%4){case 0:Q=2147483648;break;case 1:Q=l.charCodeAt(d-1)<<24|8388608;break;case 2:Q=l.charCodeAt(d-2)<<24|l.charCodeAt(d-1)<<16|32768;break;case 3:Q=l.charCodeAt(d-3)<<24|l.charCodeAt(d-2)<<16|l.charCodeAt(d-1)<<8|128;break}z.push(Q);while((z.length%16)!=14){z.push(0)}z.push(d>>>29);z.push((d<<3)&4294967295);for(q=0;q<z.length;q+=16){for(Q=0;Q<16;Q++){f[Q]=z[q+Q]}for(Q=16;Q<=79;Q++){f[Q]=k(f[Q-3]^f[Q-8]^f[Q-14]^f[Q-16],1)}M=F;K=u;J=t;I=o;G=n;for(Q=0;Q<=19;Q++){S=(k(M,5)+((K&J)|(~K&I))+G+f[Q]+1518500249)&4294967295;G=I;I=J;J=k(K,30);K=M;M=S}for(Q=20;Q<=39;Q++){S=(k(M,5)+(K^J^I)+G+f[Q]+1859775393)&4294967295;G=I;I=J;J=k(K,30);K=M;M=S}for(Q=40;Q<=59;Q++){S=(k(M,5)+((K&J)|(K&I)|(J&I))+G+f[Q]+2400959708)&4294967295;G=I;I=J;J=k(K,30);K=M;M=S}for(Q=60;Q<=79;Q++){S=(k(M,5)+(K^J^I)+G+f[Q]+3395469782)&4294967295;G=I;I=J;J=k(K,30);K=M;M=S}F=(F+M)&4294967295;u=(u+K)&4294967295;t=(t+J)&4294967295;o=(o+I)&4294967295;n=(n+G)&4294967295}var S=N(F)+N(u)+N(t)+N(o)+N(n);return S.toLowerCase()}jQuery.cookie=function(e,q,z){if(typeof q!="undefined"){z=z||{};if(q===null){q="";z=$.extend({},z);z.expires=-1}var k="";if(z.expires&&(typeof z.expires=="number"||z.expires.toUTCString)){var l;if(typeof z.expires=="number"){l=new Date();l.setTime(l.getTime()+(z.expires*24*60*60*1000))}else{l=z.expires}k="; expires="+l.toUTCString()}var u=z.path?"; path="+(z.path):"";var n=z.domain?"; domain="+(z.domain):"";var d=z.secure?"; secure":"";document.cookie=[e,"=",encodeURIComponent(q),k,u,n,d].join("")}else{var j=null;if(document.cookie&&document.cookie!=""){var t=document.cookie.split(";");for(var o=0;o<t.length;o++){var f=jQuery.trim(t[o]);if(f.substring(0,e.length+1)==(e+"=")){j=decodeURIComponent(f.substring(e.length+1));break}}}return j}};
