var tettool_dia_drag_ctrl={init:function initTETtool(g,c){console.log(c.attr("itemtitle"));var j=$(web_mode?"body":"#mainPaneScrollWrapper")[0];var d=get_tettool_param(c,"diashow_name");var l=Number(get_tettool_param(c,"x-Richtung",300));var i=Number(get_tettool_param(c,"y-Richtung",0));var m=false;var f,h;var a;if(!d.length){$(".dia_controller",c).html("<span class='tetError'>Kein Diashowname angegeben</span>");return}d=d.split(",");var b=[];var e;$.each(d,function(n,p){p=p.trim();if(p.substring(0,8)==="trigger:"){p=p.substring(8).trim();p=p.split(/ +/);b.push("trigger:"+p[0]);if(!e){a=parseInt(p[1])||0}}else{var o=$tet(p.trim(),c.parent().closest(".tetitem"),true);if(!o.length){o=$tet(p.trim())}o.each(function(){if(!this.hasAttribute("tetbox_dia")){console.error("Diashow Controller - "+this.getAttribute("itemtitle")+": not a diashow tetbox");return true}if(!e){e=this}b.push(this.id)})}});if(!b.length){$(".tetitem_inner div",c).html("Diashow Controller - "+d+": no diashow tetboxes found");console.error("Diashow Controller - "+d+": no diashow tetboxes found");return}c.on("tet:beforedynvar",function(){callWhenVisible(c,k)});$(e).on("diashow_change",function(n,o){if(m||h===undefined||window.layouting_modexxx){return}f=o.i;c.offset({left:h.left-j.scrollLeft+l*f/(a-1),top:h.top-j.scrollTop+i*f/(a-1),})});function k(){f=e&&diashow[e.id].i;a=a||(e?diashow[e.id].subs.length:100);c.attr("notetdata","1");var o=Math.sqrt(l*l+i*i);h=c.offset();h.top+=j.scrollTop;h.left+=j.scrollLeft;c.offset({left:h.left-j.scrollLeft+l*f/(a-1),top:h.top-j.scrollTop+i*f/(a-1),});c.on("drag.schiebectrl",function(r,s){if(window.layouting_mode){return}var v=j.scrollLeft+s.offset.left-h.left;var t=j.scrollTop+s.offset.top-h.top;var p=(v*l+t*i)/o;var u=Math.floor(a*p/o);if(u<0){u=0}else{if(u>=a){u=a-1}}if(u===f){return}f=u;m=true;for(var q in b){if(b[q].substring(0,8)==="trigger:"){tettrigger(b[q].substring(8),0,c,{i:f,n:a})}else{diashow_show(b[q],f)}}m=false});var n=c.draggable("option","stop");c.draggable("option","stop",function(s,t){if(window.layouting_mode){if(f===0){h=t.offset;h.top+=j.scrollTop;h.left+=j.scrollLeft;return n.call(this,s,t)}var q=t.offset.left-h.left+j.scrollLeft;var p=t.offset.top-h.top+j.scrollTop;l=Number(Int(q/(f/(a-1)),1));i=Number(Int(p/(f/(a-1)),1));o=Math.sqrt(l*l+i*i);c.attr("tettool_param_x-Richtung",l);c.attr("tettool_param_y-Richtung",i);setTETitem_template_params(c,"x-Richtung",l,function(){setTETitem_template_params(c,"y-Richtung",i,reloadMainPane_afterChange_onlyOthers)});return}else{for(var r in b){if(b[r].substring(0,8)==="trigger:"){tettrigger(b[r].substring(8),0,c,{i:f,stop:true})}}}c.offset({left:h.left-j.scrollLeft+l*f/(a-1),top:h.top-j.scrollTop+i*f/(a-1)});return n.call(this,s,t)})}}};