
var isExport = false;

function $SVG(id){
    return window.A.SVG.document.getElementById(id);
}

function $SVG_Trans(obj)
{
	var transforms = obj.getAttribute('transform');
	
	if (transforms != null) {
		transforms = transforms.split(')');
		
		var rotate = transforms[0].replace('rotate(', '').split(',');
		
		var translate = transforms[1].replace('translate(', '').replace(')', '').split(',');
		
		////console.log('---- '+transforms+' -----');
		
		////console.log('---- '+rotate+' -----');
		
		return {
			'rotate': rotate,
			'translate': translate
		};
		
	} else {
		return false;
	}

}


function ObjectToString(object)
{
	  var str = '<'+object.nodeName;
	  for (k = 0; k < object.attributes.length; k++) {
		str += ' '+object.attributes[k].nodeName+'=@'+object.attributes[k].nodeValue+'@';
	  }
	  str += '>';
	  return str;
}

function PointRotator(o,r,a)
{
	var angle = (180+parseInt(a)) * (Math.PI/180);					
								
	var X = parseInt(r.x)-parseInt(o.x);
	var Y = parseInt(r.y)-parseInt(o.y);
								
	var kX = Math.cos(angle) * X + Math.cos(angle) * Y;
	var kY = X * Math.sin(angle) - Math.sin(angle) * Y;
								
	return {
		x : kX + parseInt(r.x),
		y : kY + parseInt(r.y)
	}
}

function childsToJSON(p,toExport){
    var s = '';
	
	if(!p){ return '[]'; }
	
    for (var i = 0; i < p.childNodes.length; i++) {
		
		if( p.childNodes[i].getAttribute('id').search('door') > -1)
		{
			var element_name = 'door';
		} 
		else if( p.childNodes[i].getAttribute('id').search('window') > -1)
		{
			var element_name = 'window';
		}
		else {
			var element_name = p.childNodes[i].nodeName;
		} 			
		
        s += '{ "element" : "' + element_name + '", "attributes" : {';
        for (k = 0; k < p.childNodes[i].attributes.length; k++) {
            if (p.childNodes[i].attributes[k].nodeName != 'eName' && p.childNodes[i].attributes[k].nodeName != 'title') {
				if(k>0){s+=',';}
                s += '"' + p.childNodes[i].attributes[k].nodeName + '":"' + p.childNodes[i].attributes[k].nodeValue + '"';
            }
        }
		if (p.childNodes[i].nodeName == 'text')
		{
			s += ', "textContent":"'+p.childNodes[i].textContent+'"';
			if(toExport){
				s += ', "width":"'+p.childNodes[i].getBBox().width+'", "height":"'+p.childNodes[i].getBBox().height+'"';
			}
		}
		s += '}';
		
		if (p.childNodes[i].nodeName == 'g') {
			if (p.childNodes[i].hasChildNodes()) {
				s += ', "childs" : [';
				for (var c = 0; c < p.childNodes[i].childNodes.length; c++) {
					if (c > 0) {
						s += ',';
					}
					s += '{ "element" : "' + p.childNodes[i].childNodes[c].nodeName + '", "attributes" : {';
					for (t = 0; t < p.childNodes[i].childNodes[c].attributes.length; t++) {
						if (t > 0) {
							s += ',';
						}
						s += '"' + p.childNodes[i].childNodes[c].attributes[t].nodeName + '":"' + p.childNodes[i].childNodes[c].attributes[t].nodeValue + '"';
					}
					s += '}}';
				}
				s += ']}';
			}
			else {
				s += '}';
			}
		} else {
			s += '}';
		}
        s += '' + ((i + 1) == p.childNodes.length ? '' : ',');

    }	
	
    return s;
}




function parseSVG(str) {
  //str = '<g xmlns="http://www.w3.org/2000/svg">' + str + '</g>';
  return new DOMParser().parseFromString(str, "text/xml").childNodes[0];
}




var gDims = 40;
var offset = 0;

function alignToGrid(eX, eY){
    /*
     //////console.log(e.clientX+' : '+e.clientY);
     //////console.log('----------------------------');
     //////console.log( (e.clientX-13) / gDims );
     //////console.log( (e.clientY-13) / gDims );
     */
    var sX = Math.round((eX - offset) / (gDims));
    var sY = Math.round((eY - offset) / (gDims));
    
    var nX = offset + (sX * gDims); - 1;
    var nY = offset + (sY * gDims); - 1;
    
    ////////console.log('Legközelebbi pont: ['+nX+','+nY+']');
    
    return {
        'x': nX,
        'y': nY
    };
    
}


function centerOfLine(c){
    var X = ((c.x1 * Math.pow((c.y2 - c.y1), 2)) + (c.x3 * Math.pow((c.x2 - c.x1), 2)) + ((c.x2 - c.x1) * (c.y2 - c.y1) * (c.y3 - c.y1))) / (Math.pow((c.x2 - c.x1), 2) + Math.pow((c.y2 - c.y1), 2));
    var Y = (((c.y2 - c.y1) / (c.x2 - c.x1)) * (X - c.x1)) + c.y1;
    return {
        'x': X,
        'y': Y
    }
}

var Alaprajz = Class.create({

    /* 
     *  ALAPRAJZ ALKALMAZÁS VÁLTOZÓI
     * 	 @ OBJECT :
     *   @ selectedTool : az éppen kiválasztott eszközt tárolja
     *
     */
    OBJECT: null,
    selectedTool: null,
    selectedElement: null,
    	
    
    /* 
     *  ALAPRAJZ ALKALMAZÁS INICIALIZÁLÁSA
     *
     */
    initialize: function(){
    
        this.initializeSVG();

    },
	
	
	
	State: {
        changed: false,
        saved: false
    },
    
    
    
    calcRatio: function(length){
   		

        var osztas = 40; // 33pixel
        var arany = 1; // 1m
        
		//var div = length % osztas;
		//////console.log(div);
               
        var length_in_m = ((length/osztas)*arany).toFixed(2);
         
		return length_in_m;
		 
    },
	
	
	svg2json : function(toExport){
		
		var objects = childsToJSON( $SVG('objectGroup'), toExport );
		var lines = childsToJSON( $SVG('lineGroup'), toExport );		
		var windows = childsToJSON( $SVG('windowGroup'), toExport );
		var doors = childsToJSON( $SVG('doorGroup'), toExport );
		var texts = childsToJSON( $SVG('textGroup'), toExport );
		
		var content = '[';
		content += objects;
		content += ( ( lines && objects ) ? ',' : '') + lines;
		content += ( ( windows && lines )? ',' : '') + windows;
		content += ( ( doors && lines ) ? ',' : '') + doors;
		content += ( ( texts && doors ) ? ',' : '') + texts;		
		content +=  ']';
		
		return content.replace('}{','},{');
		
	},
	
	
	checkUser : function(func,event)
	{
		new Ajax.Request('/check-user',{
			onComplete : function(t){
				if (func) {
					if (t.responseText != 'false') {
						func(event);
					} else {
						if( confirm("Ez a funkció csak regisztrált felhasználóknak elérhető!\nHa szeretne most bejelentkezni, kérjük kattintson az \"OK\" gombra!") ){
							showBox('Reg');
						} else {
							return false;
						}
					}
				} else {
					return t.responseText;
				}	
			}
		});
	},
	
	displayLT : true,
	toggleLengthTexts : function()
	{
		if(window.A.displayLT){
			window.A.displayLT = false;
		} else {
			window.A.displayLT = true;
		}
		var sizeTexts = $SVG('textGroup').childNodes;
		for (var i = 0; i < sizeTexts.length; i++) {		
			if (sizeTexts[i].getAttribute('id').search('size-text') > -1)
			{
				window.A.SVG.changeElement(sizeTexts[i], {
					'visibility' : (window.A.displayLT) ? 'visible' : 'hidden'
				});
			}
		}
	},
	
	
	showTips : true,
	toggleTips : function(){
		if(window.A.showTips){
			window.A.showTips = false;
			$$('.tip').invoke('hide');
			$('tips_container').hide();
		} else {
			window.A.showTips = true;
			$('tips_container').show();
		}
	},
	
	
	/* 
     *  ÚJ DOKUMENTUM
     *
     */
	
	newDocument : function()
	{		
       showBox('Msg');
	   $$('.msgTitle h1')[0].innerHTML = 'Új rajz';
	   
	   var str = '';
	   str += '<div style="text-align:center">';
	   str += '<span style="color:#AE1412;font-weight:bold;">A művelet végrehajtásával minden módosítás el fog veszni.<br/>Biztosan folytatja?</span><br/><br/>';
	   str += '<input type="button" class="default-button" onclick="hideBox(\'Msg_Box\')" value="MÉGSEM" />&nbsp;&nbsp;<input type="button" class="default-button" onclick="window.A.clearDocument();hideBox(\'Msg_Box\');" value="IGEN, FOLYTATOM" />';
	   str += '</div>';
				
	   $$('.msgBody')[0].innerHTML = str;
    },
	
	clearDocument : function()
	{	
		
		window.A.States.previous = [];
		window.A.States.actual = [];
		
		while ($SVG('lineGroup').hasChildNodes()) {
            $SVG('lineGroup').removeChild($SVG('lineGroup').lastChild);
        }
        while ($SVG('objectGroup').hasChildNodes()) {
            $SVG('objectGroup').removeChild($SVG('objectGroup').lastChild);
        }
        while ($SVG('resizeGroup').hasChildNodes()) {
            $SVG('resizeGroup').removeChild($SVG('resizeGroup').lastChild);
        }
		while ($SVG('doorGroup').hasChildNodes()) {
            $SVG('doorGroup').removeChild($SVG('doorGroup').lastChild);
        }
		while ($SVG('windowGroup').hasChildNodes()) {
            $SVG('windowGroup').removeChild($SVG('windowGroup').lastChild);
        }
		while ($SVG('textGroup').hasChildNodes()) {
            $SVG('textGroup').removeChild($SVG('textGroup').lastChild);
        }
		
		if($$('.sample')[0]){
			$$('.sample')[0].remove();
		}
		
	},
	
	/* 
     *  MENTÉS
     *
     */
	
	saveDocument : function()
	{		
		window.A.checkUser(function(){
			showBox('Save');
			$$('.saveBody .popup-message')[0].hide();
			$$('.saveBody .form')[0].show();
		});
	},
	
	
	doSave : function()
	{
		
			var file = '&postal-code='+$('save-form-postal-code').value;
			file += '&city='+$('save-form-city').value;
			file += '&street='+$('save-form-street').value;
			file += '&number='+$('save-form-number').value;
			file += '&stair='+$('save-form-stair').value;
			file += '&m2='+$('save-form-m2').value;
			file += '&is_public='+($('is_public').checked ? 1 : 0);
			
			var content = window.A.svg2json();
			
			new Ajax.Request('/alaprajz-mentese',{
				method : 'post',
				parameters : encodeURI(file+'&content='+content),
				encoding: "utf-8",
				contentType: "application/x-www-form-urlencoded", 
				onLoading : function()
				{
					$$('.saveBody .popup-loading')[0].show();
					$$('.saveBody .form')[0].hide();
				},
				onComplete : function(t){
					$$('.saveBody .popup-loading')[0].hide();
					$$('.saveBody .popup-message')[0].show();
					if ( t.responseText == 'true' ) {
						var str = '<strong>Az alaprajz sikeresen elmentve.</strong><br/><br/><input type="button" class="default-button" onclick="hideBox(\'Save_Box\')" value="Ablak bezárása" />';					
					} 
					else if( t.responseText == 'false' ) {
						var str = '<strong>Az alaprajz mentése nem sikerült.</strong><br/>Kérjük próbálja meg később újra.<br/><br/><input type="button" class="default-button" onclick="hideBox(\'Save_Box\')" value="Ablak bezárása" />';					
					}
					else if( t.responseText == 'empty' ) {
						var str = '<strong>Üres alaprajz nem menthető el.</strong><br/><br/><input type="button" class="default-button" onclick="hideBox(\'Save_Box\')" value="Ablak bezárása" />';					
					}
					else if( t.responseText == 'not_logged' ) {
							var str = '<strong>A mentés funkció csak bejelentkezett felhasználók számára érhető el.</strong><br/>Kérjük <a href="javascript:;" onclick="showBox(\'Reg\');$$(\'.regBody .popup-message\')[0].hide();$$(\'.regBody .form\')[0].show();">jelentkezzen be</a>, vagy <a href="javascript:;" onclick="showBox(\'Reg\');$$(\'.regBody .popup-message\')[0].hide();$$(\'.regBody .form\')[0].show();">regisztráljon</a>.<br/><br/><input type="button" class="default-button" onclick="hideBox(\'Save_Box\')" value="Ablak bezárása" />';					
					}
					
					$$('.saveBody .popup-message')[0].innerHTML = str;
				}
			});
		
	},
	
	
	/*
	 *  VISSZAVONÁS / ÚJRA
	 *  
	 */
	
	States : {
		previous : [],
		actual : []
	},
	
	Undo : function(){
		window.A.States.actual = window.A.svg2json();
		window.A.Build_Document_From_JSON(window.A.States.previous.evalJSON());
		if (window.A.selectedElement) {
			window.A.selectedElement = $SVG(window.A.selectedElement.getAttribute('id'));
			if (window.A.selectedElement) {
				window.A.SVG.unselectElement();
			}
		}
	},
	
	Redo : function()
	{
		window.A.Build_Document_From_JSON(window.A.States.actual.evalJSON());
	},
	
	
	/*
	 *  EXPORTÁLÁS
	 *  
	 */
	
	doExport : function()
	{
		window.A.checkUser(function(){		
			window.isExport = true;
			var content = window.A.svg2json(true);	
			if (content.length > 2) {
				$$('#export-form input')[0].value = content;
				$('export-form').submit();
			} else {
				alert('Üres alaprajz nem exportálható!');
			}
		});		
	},
	
	
	/*
	 *  KÜLDÉS E-MAILBEN
	 *  
	 */
	
	SendWithMail_Window : function()
	{
		window.A.checkUser(function(){
			showBox('Mail');
			$$('.mailBody .popup-message')[0].hide();
			$$('.mailBody .form')[0].show();
		});		
	},
	
	SendWithMail : function()
	{
		if (checkForm('mail-form')) {
			var content = window.A.svg2json();
			var form = $('mail-form').serialize();
			new Ajax.Request('/alaprajz-kuldese', {
				method: 'post',
				parameters: '&' + form + '&data=' + content,
				onLoading: function(){
					$$('.mailBody .popup-loading')[0].show();
					$$('.mailBody .form')[0].hide();
				},
				onComplete: function(t){
					$$('.mailBody .popup-loading')[0].hide();
					$$('.mailBody .popup-message')[0].show();
					if (t.responseText == 'true') {
						var str = '<strong>Az alaprajz sikeresen elküldve.</strong><br/><br/><input type="button" class="default-button" onclick="hideBox(\'Mail_Box\')" value="Ablak bezárása" />';
					}
					else 
						if (t.responseText == 'false') {
							var str = '<strong>Az alaprajz elküldése nem sikerült.</strong><br/>Kérjük próbálja meg később újra.<br/><br/><input type="button" class="default-button" onclick="hideBox(\'Mail_Box\')" value="Ablak bezárása" />';
						}
						else 
							if (t.responseText == 'empty') {
								var str = '<strong>Üres alaprajz nem küldhető el.</strong><br/><br/><input type="button" class="default-button" onclick="hideBox(\'Mail_Box\')" value="Ablak bezárása" />';
							}
							else 
								if (t.responseText == 'not_logged') {
									var str = '<strong>Az e-mailben továbbítás funkció csak bejelentkezett felhasználók számára érhető el.</strong><br/>Kérjük <a href="javascript:;" onclick="hideBox(\'Mail_Box\');showBox(\'Reg\')">jelentkezzen be</a>, vagy <a href="javascript:;" onclick="hideBox(\'Mail_Box\');showBox(\'Reg\')">regisztráljon</a>.<br/><br/><input type="button" class="default-button" onclick="hideBox(\'Mail_Box\')" value="Ablak bezárása" />';
								}
					
					$$('.mailBody .popup-message')[0].innerHTML = str;
				}
			});
		}
	},
	
	
	/*
	 *  NYOMTATÁS
	 *  
	 */
	
	Print : function(event)
	{		
		window.A.checkUser(function(ev){
			var content = window.A.svg2json(true);
			if (content.length > 2) {
				new Ajax.Request('/alaprajz-nyomtatasa', {
					method: 'post',
					parameters: '&data=' + content,
					onComplete: function(t){				
						
						$('alaprajz_print').innerHTML = '<img src="/wordpress/wp-content/themes/alaprajzkeszites/_prints/'+t.responseText+'.jpg"  alt="Alaprajz"/>';
						window.print();
																							
					}
				});
			} else {
				alert('Üres alaprajz nem nyomtatható!');
			}
		},event);		
		return false;
	},
	
	/* 
     *  MEGNYITÁS
     *
     */
	
	openDocument : function()
	{		
	
		showBox('Open');
		$$('.openBody .popup-message')[0].hide();
		$$('.openBody .form')[0].show();				

		window.A.loadGPs('public');
		
	},	
	
	deleteGP : function(id){
		if (confirm('Biztosan törölni szeretné ezt az alaprajzot?')) {
			window.A.loadGPs('public', '', id);
		}
	},
	
	loadGPs : function(type,filter,del_id)
	{
		var filters = '';
		if(filter)
		{			
			$$('.filter').each(function(item){
				if (item.value) {
					filters += '&' + item.name + '=' + item.value;
				}
			});
		}
		
		if (!type || type == 'public')
		{
			var params = '&type=public'+filters;
		} 
		else {
			var params = filters;
		}
		
		if(del_id)
		{
			params += '&del_id='+del_id;
		}
		
			new Ajax.Request('/alaprajz-lekerdezes', {
				method: 'post',
				parameters: params,
				onLoading: function(){
					$$('#groundplan_open thead')[0].show();
					$$('#groundplan_open tbody')[0].hide();
				},
				onComplete: function(t){
					$$('#groundplan_open tbody')[0].update(t.responseText).show();
					$$('#groundplan_open thead')[0].hide();
				}
			});
	
	},
	
	doOpen : function(id)
	{
		new Ajax.Request('/alaprajz-megnyitasa',{
			method : 'post',
			parameters : '&id='+id.replace('gp-',''),
			onLoading : function(){
				//$$('#groundplan_open thead')[0].show();
				//$$('#groundplan_open tbody')[0].hide();
			},
			onComplete : function(t){		
				hideBox('Open_Box');
				window.A.Build_Document_From_JSON( t.responseText.evalJSON() );				
			}
		});
	},
    
    /* 
     *  SVG DOKUMENTUM FELÉPÍTÉSE
     *
     */
    Build_Document_From_JSON: function(json){
		
        /* GROUP-OK TÖRLÉSE */
        while ($SVG('lineGroup').hasChildNodes()) {
            $SVG('lineGroup').removeChild($SVG('lineGroup').lastChild);
        }
        while ($SVG('objectGroup').hasChildNodes()) {
            $SVG('objectGroup').removeChild($SVG('objectGroup').lastChild);
        }
		while ($SVG('doorGroup').hasChildNodes()) {
            $SVG('doorGroup').removeChild($SVG('doorGroup').lastChild);
        }
		while ($SVG('windowGroup').hasChildNodes()) {
            $SVG('windowGroup').removeChild($SVG('windowGroup').lastChild);
        }
        while ($SVG('resizeGroup').hasChildNodes()) {
            $SVG('resizeGroup').removeChild($SVG('resizeGroup').lastChild);
        }
		while ($SVG('textGroup').hasChildNodes()) {
            $SVG('textGroup').removeChild($SVG('textGroup').lastChild);
        }
		
		var lineCounter = 0;
		var objectCounter = 0;
		var lRectCounter = 0;
		var uRectCounter = 0;
		var iRectCounter = 0;
		var rectCounter = 0;
		var doorCounter = 0;
		var windowCounter = 0;
		var textCounter = 0;
        		
        /* ELEMEK LÉTREHOZÁSA */
        for (var i = 0; i < json.length; i++) {
			
            /* group meghatározása */
            switch (json[i].element) {
                case 'line':
                    var group = 'lineGroup';
					var title = '';					
					break;
				case 'g':
				case 'rect':
                case 'image':
                    var group = 'objectGroup';
					break;
				case 'door':
                    var group = 'doorGroup';
					break;
				case 'window':
                    var group = 'windowGroup';
					break;
				case 'text':
                    var group = 'textGroup';
					break;
            }
            

            /* elem létrehozása */
            //json[i].attributes.eName = Language.getString('element.names.' + json[i].attributes.type);
			
			/* objektumokra title ráhúzása */
			if (json[i].element == 'image') {
				//console.log(json[i]);
				json[i].attributes.title = Language.getString('element.names.' + json[i].attributes.eType);
			}
			
			if(json[i].element == 'door'){
				var element = 'image';
			} 
			else if(json[i].element == 'window'){
				var element = 'g';
			}
			else {
				var element = json[i].element;
			}
			
            var THIS_OBJECT = this.SVG.createElement(element, json[i].attributes, group);       				
			
			if(element == 'g')
			{
				for(var c=0;c<json[i].childs.length;c++)
				{					
					this.SVG.createElement(json[i].childs[c].element, json[i].childs[c].attributes, json[i].attributes.id);
				}
			}
			
			if (element == 'text')
			{
				var textNode = window.A.SVG.document.createTextNode( json[i].attributes.textContent );												
				THIS_OBJECT.appendChild( textNode );								
			}
			
			if(json[i].attributes.id.search('l_rect') > -1)
			{
				json[i].element = 'l_rect';
			}
			
			if(json[i].attributes.id.search('i_rect') > -1)
			{
				json[i].element = 'i_rect';
			}
			
			if(json[i].attributes.id.search('u_rect') > -1)
			{
				json[i].element = 'u_rect';
			}
			
            /* event-ek hozzáadása */
            switch (json[i].element) {
            
                case 'line':
                    
                    this.eventSelectLine = this.Tools.Line.Select;
                    
                    THIS_OBJECT.addEventListener('mousedown', this.eventSelectLine, false);
                    
                    this.eventDrag = window.A.SVG.Drag_n_Drop.Drag;
                    THIS_OBJECT.addEventListener('mousedown', this.eventDrag, false);
                    
                    THIS_OBJECT.addEventListener('mouseover', this.Tools.Line.onOver, false);
                    THIS_OBJECT.addEventListener('mouseout', this.Tools.Line.onOut, false);										
					
					lineCounter++;
					
					break;
					
                case 'image':
                    
                    this.eventDrag = window.A.SVG.Drag_n_Drop.Drag;
                    THIS_OBJECT.addEventListener('mousedown', this.eventDrag, false);
					
					//THIS_OBJECT.addEventListener('mouseover', this.Objects.onOver, false);
                    //THIS_OBJECT.addEventListener('mouseout', this.Objects.onOut, false);	
					
					objectCounter++;
					
					break;
					
				case 'door':
                    
                    this.eventDrag = window.A.SVG.Drag_n_Drop.Drag;
                    THIS_OBJECT.addEventListener('mousedown', this.eventDrag, false);
					
					doorCounter++;
					
					break;
                
				case 'window' :
					
					this.eventSelectLine = this.Tools.Window.Select;
	                THIS_OBJECT.addEventListener('mousedown', this.eventSelectLine, false);
	                
	                this.eventDrag = window.A.SVG.Drag_n_Drop.Drag;
	                THIS_OBJECT.addEventListener('mousedown', this.eventDrag, false);
				  	
					windowCounter++;
					
					break;
				
				case 'i_rect':                   
					
                    this.eventDrag = window.A.SVG.Drag_n_Drop.Drag;
                    THIS_OBJECT.addEventListener('mousedown', this.eventDrag, false);
					
					this.eventSelect= this.Tools.i_Rect.Select;
	                THIS_OBJECT.addEventListener('mousedown', this.eventSelect, false);	                
				
					iRectCounter++;
				
					break;
						
				case 'l_rect':
                    
					//console.log(THIS_OBJECT);
					
                    this.eventDrag = window.A.SVG.Drag_n_Drop.Drag;
                    THIS_OBJECT.addEventListener('mousedown', this.eventDrag, false);
					
					this.eventSelect= this.Tools.l_Rect.Select;
	                THIS_OBJECT.addEventListener('mousedown', this.eventSelect, false);	                
				
					lRectCounter++;
				
					break;
					
				case 'u_rect':
 
                    this.eventDrag = window.A.SVG.Drag_n_Drop.Drag;
                    THIS_OBJECT.addEventListener('mousedown', this.eventDrag, false);
					
					this.eventSelect= this.Tools.u_Rect.Select;
	                THIS_OBJECT.addEventListener('mousedown', this.eventSelect, false);	                
				
					uRectCounter++;
				
					break;
				
				case 'text' :
					
					if (json[i].attributes.id.search('size') == -1) {
					
						// EVENT-ek
						this.eventDrag = window.A.SVG.Drag_n_Drop.Drag;
						THIS_OBJECT.addEventListener('mousedown', window.A.eventDrag, false);
						
						this.eventOver = window.A.Tools.Text.onOver;
						THIS_OBJECT.addEventListener('mouseover', window.A.eventOver, false);
						
						this.eventOut = window.A.Tools.Text.onOut;
						THIS_OBJECT.addEventListener('mouseout', window.A.eventOut, false);
						
						this.eventEdit = window.A.Tools.Text.reEdit;
						THIS_OBJECT.addEventListener('dblclick', window.A.eventEdit, false);
						
						this.eventSelectText = window.A.Tools.Text.Select;
						THIS_OBJECT.addEventListener('mousedown', window.A.eventSelectText, false);
						
					}
					textCounter++;
					
					break;
            }

        }

		
		window.A.Tools.Line.counter = lineCounter;
		window.A.Tools.Window.counter = windowCounter;
		window.A.Tools.Door.counter = doorCounter;
		window.A.Tools.Text.counter = textCounter;
		
    },
	
    
    /* 
     *  SVG DOKUMENTUM INICIALIZÁLÁSA
     *
     */
    initializeSVG: function(){
 
        this.SVG.document = null;
        this.SVG.window = null;
        
        var object = $('object');
        this.OBJECT = object;
        
        if (object && object.contentDocument) {
            this.SVG.document = object.contentDocument;
        }
        else 
            try {
                this.SVG.document = object.getSVGDocument();
            } 
            catch (exception) {
                alert('Neither the HTMLObjectElement nor the GetSVGDocument interface are implemented');
            }
        
        if (this.SVG.document && this.SVG.document.defaultView) 
            this.SVG.window = this.SVG.document.defaultView;
        else 
            if (object.window) 
                this.SVG.window = object.window;
            else 
                try {
                    this.SVG.window = object.getWindow();
                } 
                catch (exception) {
                    alert('The DocumentView interface is not supported\r\n' +
                    'Non-W3C methods of obtaining "window" also failed');
                }
        
        
        this.SVG.body = this.SVG.document.rootElement;        	
        
        /*
         *  ALAPVETŐ event-ek
         *  @ selectedElement kilövése, sstb.
         */
        this.SVG.body.addEventListener('click', alignToGrid, false);
        this.SVG.body.addEventListener('click', function(e){
            if (e.target.nodeName == 'svg' && window.A.selectedElement) {
            
				window.A.SVG.unselectElement();
                
                // Méretező objektumok törlése
                window.A.SVG.Resizer.removeSizers();
                
                // Kiválasztott elem objektum nullázása
                window.A.selectedElement = null;
                
                // Információs box elrejtése
                InformationBox.hide();
                InformationBox.update('');
                
            }
        }, false);
		
		
		this.SVG.body.addEventListener('mousemove',function(e){
			window.mouseX = e.clientX;
			window.mouseY = e.clientY;	
			$SVG('renderBug').textContent  = new Date().valueOf();
		}, false);	
		
		this.SVG.body.addEventListener('mousemove',function(e){
			if (typeof(ToolTip) != 'undefined') {
				ToolTip.move(e, true);
			}
		}, false);			
        
		
		//rect_str = '<rect id="teszt-rect" x="160" y="60" width="250" height="250" />';
		
		//rect_str = '<line rel="window-0" class="window" stroke-width="9" stroke="black" x1="175" y1="35" x2="331" y2="35"/>';
		
		
		
    },
    
    /* 
     *  SVG OBJEKTUM
     *   @ createElement : létrehoz egy elemet az SVG objektumban
     *   @ insertElement : beszúr egy elemet az SVG objektumba
     *   @ changeEelement : egy elem tulajdonságainak módosítása objektumként átadott paraméterekre. pl: { stroke: 'red' }
     *   @ moveElement : elem elmozdítása az aktuális pozíciójából a megadott értékekre
     *   @ Drag_and_Drop : SVG objektum mozgatása
     */
    SVG: {
    
        document: null,
        window: null,
        body: null,
        
        createElement: function(el, attributes, autoInsert){
        
            var svgNS = "http://www.w3.org/2000/svg";
            var xlinkNS = "http://www.w3.org/1999/xlink";
            
            var nEl = this.document.createElementNS(svgNS, el);
            
            Object.keys(attributes).each(function(k){
				if(k=='textContent'){ return; }
                if (k.search('xlink') > -1) {
                    nEl.setAttributeNS(xlinkNS, k, attributes[k]);
                }
                else {
                    nEl.setAttributeNS(null, k, attributes[k]);
                }
            });
            
            if (autoInsert !== false) {
                this.insertElement(nEl, autoInsert);
            }
            
            /* document is changed */
            window.A.State.changed = true;            			
			
            return nEl;
            
        },
        
        insertElement: function(el, group){
						
			if (typeof(group) == 'string') {
				this.document.getElementById(group).appendChild(el);
			} else {
				group.appendChild(el);
			}
			
        },
        
        changeElement: function(el, attributes, no_save_state){
						
            Object.keys(attributes).each(function(k){
                el.setAttributeNS(null, k, attributes[k]);
            });
					
            /* document is changed */
            if (!no_save_state) {
                window.A.State.changed = true;
            }
        },
        
        removeElement: function(obj){
			
			if (obj) {
			
				window.A.SVG.unselectElement();
				
				window.A.States.previous = window.A.svg2json();
				
				if (obj == '') {
					this.deleteAttachedElements(this.selectedElement);
					this.selectedElement.parentNode.removeChild(this.selectedElement);
					this.selectedElement = null;
					if (this.selectedElement.nodeName == 'line') {
						window.A.SVG.removeElement($SVG('size-text-' + this.selectedElement.getAttribute('id')));
					}
				}
				else {
					this.deleteAttachedElements(obj);
					if (obj.nodeName == 'line') {
						window.A.SVG.removeElement($SVG('size-text-' + obj.getAttribute('id')));
					}
					obj.parentNode.removeChild(obj);
				}
				window.A.SVG.Resizer.removeSizers();
				
			}
        },
		
		deleteAttachedElements : function(obj)
		{
			if(obj.nodeName == 'line'){
				
				var windows = $SVG('windowGroup').getElementsByTagName('g');
				var doors = $SVG('doorGroup').getElementsByTagName('image');
				

				for(var i=0;i<windows.length;i++)
				{
					if( windows[i].getAttribute('rel') == obj.getAttribute('id') )
					{
						window.A.SVG.removeElement(windows[i]);
					}
				};
				
				for(var i=0;i<doors.length;i++)
				{
					if( doors[i].getAttribute('rel') == obj.getAttribute('id') )
					{
						window.A.SVG.removeElement(doors[i]);
					}
				};								
				
			}
		},
        
		unselectElement : function()
		{
			if (window.A.selectedElement) {
				switch (window.A.selectedElement.getAttribute('class')) {
				
					case 'l_rect':
						window.A.SVG.changeElement(window.A.selectedElement.childNodes[0], { stroke: 'black' });
						window.A.SVG.changeElement(window.A.selectedElement.childNodes[1], { stroke: 'black' });
						break;
						
					case 'u_rect':
						window.A.SVG.changeElement(window.A.selectedElement.childNodes[0], { stroke: 'black' });
						window.A.SVG.changeElement(window.A.selectedElement.childNodes[1], { stroke: 'black' });
						window.A.SVG.changeElement(window.A.selectedElement.childNodes[2], { stroke: 'black' });
						break;
					
					case 'text':
					case 'window':
						break;
					
					
					default:
						window.A.SVG.changeElement(window.A.selectedElement, { stroke: 'black' });
						break;
						
				}
			}
		},
		
        moveElement: function(el, top, left){
        
            el = window.A.selectedElement;
            
            switch (el.nodeName) {
            
                case 'line':
                    var changes = {
                        x1: parseInt(el.getAttribute('x1')) + left,
                        y1: parseInt(el.getAttribute('y1')) + top,
                        x2: parseInt(el.getAttribute('x2')) + left,
                        y2: parseInt(el.getAttribute('y2')) + top
                    }
                    break;
                    
                case 'rect':
                case 'image':
                    var changes = {
                        x: parseInt(el.getAttribute('x')) + left,
                        y: parseInt(el.getAttribute('y')) + top
                    }
                    break;
                    
            }
            
            window.A.SVG.changeElement(el, changes);
            
        },
        
        Drag_n_Drop: {
        
            object: null,
            tempData: [],
            onDrag: function(){
            },
            onMove: function(){
            },
            onDrop: function(){
            },
            
            Drag: function(e, options){
            
                var T = window.A.SVG;
				
                if (window.A.selectedTool == null ) {
					
					window.A.States.previous = window.A.svg2json();			
					
                    T.Drag_n_Drop.object = e.target;
                    
                    T.Drag_n_Drop.eX = e.clientX;
                    T.Drag_n_Drop.eY = e.clientY;
                    
                    T.eventDD_Move = T.Drag_n_Drop.Move;
                    T.eventDD_Drop = T.Drag_n_Drop.Drop;
                    
                    // Eseménykezelők beállítása
                    T.document.addEventListener('mousemove', T.eventDD_Move, false);
                    T.document.addEventListener('mouseup', T.eventDD_Drop, false);
                    
                    ////////console.log(this);
                    if (e.target.nodeName == 'line') {
                        if (e.target.parentNode.getAttribute('id').search('window') > -1) {
                            T.Drag_n_Drop.tempData[0] = Math.vectorLength([e.clientX, e.clientY], [e.target.getAttribute('x1'), e.target.getAttribute('y1')]);
                            T.Drag_n_Drop.tempData[1] = Math.vectorLength([e.clientX, e.clientY], [e.target.getAttribute('x2'), e.target.getAttribute('y2')]);
                        }
                    }
                    
                    
                    T.Drag_n_Drop.onDrag(e, options);
                    
                }
                
                
            },
            
            Move: function(e){
            
                var DD = window.A.SVG.Drag_n_Drop;
                
                var sX = e.clientX - DD.eX;
                var sY = e.clientY - DD.eY;
                
                var objectType = DD.object.nodeName;
                
				
                // Window?
                if (objectType == 'line') {
                    if (DD.object.parentNode.getAttribute('id').search('window') > -1) {
						////console.log( DD.object.parentNode.getAttribute('id') );
                        var objectType = 'window';
                    }
                } 
				else 
				{
					if (DD.object.parentNode != null) {
						if (DD.object.parentNode.getAttribute('id').search('l_rect') > -1) {
							var objectType = 'l_rect';
						}
						if (DD.object.parentNode.getAttribute('id').search('u_rect') > -1) {
							var objectType = 'u_rect';
						}
						if(DD.object.id.search('door') > -1)
						{
							var objectType = 'door';
						}
					}  

				}
                
                
                switch (objectType) {
                
                    case 'line':
                        
                        var changes = {
                            x1: parseInt(DD.object.getAttribute('x1')) + sX,
                            y1: parseInt(DD.object.getAttribute('y1')) + sY,
                            x2: parseInt(DD.object.getAttribute('x2')) + sX,
                            y2: parseInt(DD.object.getAttribute('y2')) + sY
                        }
						
						window.A.SVG.deleteAttachedElements(DD.object);
                        
                        break;
                        
                    case 'circle':
                        
                        var changes = {
                            cx: parseInt(DD.object.getAttribute('cx')) + sX,
                            cy: parseInt(DD.object.getAttribute('cy')) + sY
                        }
                        
                        break;
                        
                    case 'rect':
					case 'text':											
                    case 'image':
                        
						var nX = parseInt(DD.object.getAttribute('x')) + sX;
						var nY = parseInt(DD.object.getAttribute('y')) + sY;
						
                        var changes = {
                            x: nX,
                            y: nY
                        }
                        
                        break;		
						
					case 'l_rect':
					
						var changes = {
                            x: parseInt(DD.object.parentNode.childNodes[0].getAttribute('x')) + sX,
                            y: parseInt(DD.object.parentNode.childNodes[0].getAttribute('y')) + sY
                        }
                        
                        break;		
					
					case 'u_rect':	
					
						var changes = {
                            x: parseInt(DD.object.parentNode.childNodes[0].getAttribute('x')) + sX,
                            y: parseInt(DD.object.parentNode.childNodes[0].getAttribute('y')) + sY
                        }
                        
                        break;										
                        
                    case 'window':
                        
                        // Elements
                        var pL = $SVG(DD.object.parentNode.getAttribute('rel'));                       
						
                        // lineX1-X2,lineY1-Y2
                        var lineX1 = parseInt(pL.getAttribute('x1'));
                        var lineX2 = parseInt(pL.getAttribute('x2'));
                        var lineY1 = parseInt(pL.getAttribute('y1'));
                        var lineY2 = parseInt(pL.getAttribute('y2'));
                        
						if (lineX1 != lineX2) {
						
							var cPos = window.A.Tools.Window.getCoordinates(e, pL);
							
							// Base
							var A = [lineX1, lineY1];
							var B = [lineX2, lineY2];
							
							// x1,y1
							var E1 = Math.vectorDiv({
								'A': A,
								'B': B,
								'F': [cPos.x, cPos.y],
								'dist': -DD.tempData[0]
							});
							
							// x2, y2
							var E2 = Math.vectorDiv({
								'A': A,
								'B': B,
								'F': [cPos.x, cPos.y],
								'dist': DD.tempData[1]
							});
							
							
							if ((lineX1 >= E1[0] && lineY1 <= E1[1]) ||
							(lineX1 >= E1[0] && lineY1 >= E1[1])) {
							
							
								E1 = [lineX1, lineY1];
								E2 = Math.vectorDiv({
									'A': A,
									'B': B,
									'F': A,
									'dist': Math.vectorLength([parseInt(DD.object.getAttribute('x1')), parseInt(DD.object.getAttribute('y1'))], [parseInt(DD.object.getAttribute('x2')), parseInt(DD.object.getAttribute('y2'))])
								});
								
							}
							else 
								if ((lineX2 <= E2[0] && lineY2 >= E2[1]) ||
								(lineX2 <= E2[0] && lineY1 <= E2[1])) {
								
									E1 = Math.vectorDiv({
										'A': A,
										'B': B,
										'F': B,
										'dist': -Math.vectorLength([parseInt(DD.object.getAttribute('x1')), parseInt(DD.object.getAttribute('y1'))], [parseInt(DD.object.getAttribute('x2')), parseInt(DD.object.getAttribute('y2'))])
									});
									E2 = [lineX2, lineY2];
									
								}
								
						}  
						
						//Függőleges ablak
						else {
							
							/*
							var length = parseInt(DD.object.getAttribute('y2'))-parseInt(DD.object.getAttribute('y1'))
							
							var E1 = [parseInt(DD.object.getAttribute('x1')), (e.clientY-parseInt(DD.object.getAttribute('y1'))) ];
							var E2 = [parseInt(DD.object.getAttribute('x1')), (E1[1]+length) ];													
							*/
						
							var x1 = parseInt(DD.object.getAttribute('x1'));
							var y1 = parseInt(DD.object.getAttribute('y1'));
							
							var x2 = parseInt(DD.object.getAttribute('x2'));
	                        var y2 = parseInt(DD.object.getAttribute('y2'));							
							
							var length = y2-y1;
							
							if(y1 < lineY1){ 
								y1 = lineY1; 				
							} 
							else if((y1+length) > lineY2) {
								y1 = lineY2-length;
							}	
							else {
								y1 += sY;
							}
								
							var E1 = [x1,y1];
							var E2 = [x2,(y1+length)];
						
						}
                        
                        
                        // CHANGES						
                        var changes = {
                            x1: E1[0],
                            y1: E1[1],
                            x2: E2[0],
                            y2: E2[1]
                        }

                        break;
						
						
					case 'door':
							
	                        // Elements
	                        var pL = $SVG(DD.object.getAttribute('rel'));
	                        
							var transforms = DD.object.getAttribute('transform').split(') ');
							var rotate = transforms[0]+')';
							
							var cPos = window.A.Tools.Door.getCoordinates(e,pL);	                        															
							var E1 = [parseInt(pL.getAttribute('x1')),parseInt(pL.getAttribute('y1'))];
							var E2 = [parseInt(pL.getAttribute('x2')),parseInt(pL.getAttribute('y2'))];
							
							//if (DD.tempData.length == 0) {
								//DD.tempData = ;
							//}
							
							var dWIDTH = parseInt(DD.object.getAttribute('width'));
							
							if (E1[0] != E2[0]) {
								
								var tTop = -5;
								var tLeft = Math.vectorLength(E1, [cPos.x, cPos.y]);
								
								// Flipped
								if( DD.object.getAttribute('class').search('flipped') > -1 )
								{
									tLeft = tLeft * -1;									
									if ((Math.abs(tLeft)) > Math.vectorLength(E1, E2)) {
										tLeft = -Math.vectorLength(E1, E2);
									}
									if ((e.clientX-dWIDTH) < E1[0]) {
										tLeft = -dWIDTH;
									}
								} 
								// Normal
								else {
									if ((tLeft + dWIDTH) > Math.vectorLength(E1, E2)) {
										tLeft = Math.vectorLength(E1, E2) - dWIDTH;
									}								
									if (e.clientX < E1[0]) {
										tLeft = 0;
									}
								}
																
								
							} else {
								
								var tTop = -5;
								
								// Flipped
								if (DD.object.getAttribute('class').search('flipped') > -1) {
									
									var tLeft = e.clientY-E1[1]; 																		
										
									if (tLeft < 0) {
										tLeft = 0;
									}
									
									////////console.log( (e.clientY-E1[1]) );
									
									if ((e.clientY+dWIDTH) > E2[1]){
										tLeft = E2[1]-E1[1]-dWIDTH;
									}
								
								}
								else
								// Normal 
								{									
									var tLeft = -dWIDTH-(e.clientY-E1[1]); 
									
									if (tLeft > -dWIDTH) {
										tLeft = -dWIDTH;
									}
									
									if (tLeft + dWIDTH < (-(E2[1] - E1[1] - dWIDTH))) {
										tLeft = -(E2[1] - E1[1]);
									}
								}
														
							}							
	                        
											
							// CHANGES						
	                        var changes = {
	                        	'transform': rotate + ' translate('+tLeft+','+tTop+')'
	                        }
							

                       		break;
                        
                }
                
                DD.eX = e.clientX;
                DD.eY = e.clientY;
                
                window.A.SVG.Resizer.removeSizers();
                
				
                switch (objectType) {
                
                    case 'window':
                        window.A.SVG.changeElement(DD.object.parentNode.childNodes[0], changes);
                        window.A.SVG.changeElement(DD.object.parentNode.childNodes[1], changes);
					 	window.A.SVG.changeElement(DD.object.parentNode.childNodes[2], changes);
                        
                        break;
					
					
				    case 'l_rect':
						
						
						var trans = $SVG_Trans(DD.object.parentNode);											
						
						if (trans.rotate) {
							
							var BBOX = DD.object.parentNode.getBBox();													
							var angle = trans.rotate[0];
							var tLeft = Math.round(BBOX.width/2);
							var tTop = Math.round(BBOX.height/2);
							
							window.A.SVG.changeElement(DD.object.parentNode, {								
								'transform': "rotate(" + (angle) + "," + (changes.x + tLeft) + "," + (changes.y + tTop)+ ")"
							});														
							
						}
												
						window.A.SVG.changeElement(DD.object.parentNode.childNodes[0], changes);
                       	window.A.SVG.changeElement(DD.object.parentNode.childNodes[1], changes);
                        
						changes.x = changes.x+19;
						changes.y = changes.y+1;
						
						window.A.SVG.changeElement(DD.object.parentNode.childNodes[2], changes);
						
                        break;
						
					case 'u_rect':
						
						var trans = $SVG_Trans(DD.object.parentNode);											
						
						if (trans.rotate) {
							
							var BBOX = DD.object.parentNode.getBBox();													
							var angle = trans.rotate[0];
							var tLeft = Math.round(BBOX.width/2);
							var tTop = Math.round(BBOX.height/2);
							
							window.A.SVG.changeElement(DD.object.parentNode, {								
								'transform': "rotate(" + (angle) + "," + (changes.x + tLeft) + "," + (changes.y + tTop) + ")"
							});														
							
						}						
						
                        window.A.SVG.changeElement(DD.object.parentNode.childNodes[0], changes);
                        window.A.SVG.changeElement(DD.object.parentNode.childNodes[2], changes);
						
						changes.x = parseInt(DD.object.parentNode.childNodes[2].getAttribute('x'))+parseInt(DD.object.parentNode.childNodes[2].getAttribute('width'))-20;
						window.A.SVG.changeElement(DD.object.parentNode.childNodes[1], changes);
                        
						changes.x = parseInt(DD.object.parentNode.childNodes[2].getAttribute('x'));
						changes.y = changes.y+19;						
						window.A.SVG.changeElement(DD.object.parentNode.childNodes[3], changes);
						
						changes.x = parseInt(DD.object.parentNode.childNodes[2].getAttribute('x'))+parseInt(DD.object.parentNode.childNodes[2].getAttribute('width'))-20;
						changes.y = changes.y;						
						window.A.SVG.changeElement(DD.object.parentNode.childNodes[4], changes);
						
                        break;
					
				    case 'circle' : 
					
						window.A.SVG.changeElement(DD.object, changes);
						
						break;
						
					case 'door' : 
					
						window.A.SVG.changeElement(DD.object, changes);
						
						break;
						
					case 'line' : 
					
						window.A.SVG.changeElement(DD.object, changes);
						var SVG_TEXT = $SVG('size-text-'+DD.object.getAttribute('id'));
							
						var dims = SVG_TEXT.getBBox();			
						var x = (Math.vectorLength([changes.x1,changes.y1], [changes.x2, changes.y2]) - dims.width) / 2;
						//var tAngle = Math.AngleFromVectors([changes.x1,changes.y1], [changes.x2, changes.y2]);
						
						var tAngle = $SVG_Trans(SVG_TEXT).rotate[0];
								
						var tX = changes.x1;
						var tY = changes.y1;
				
						if(changes.x2 < changes.x1)
						{
							x = -(x+dims.width);										
							var transform = 'rotate('+(tAngle)+','+changes.x1+','+changes.y1+') translate('+x+',-10)';
						}
						else 
						{
							var transform = 'rotate('+(tAngle)+','+changes.x1+','+changes.y1+') translate('+x+',-10)';
						}											
															
						window.A.SVG.changeElement(SVG_TEXT, {
							'x': tX,
							'y': tY,
							'transform': transform
						});
													
						
						break;
						
                    default:

						var rotate = DD.object.getAttribute('transform');
						
						if (rotate) {
							
							var angle = rotate.replace('rotate(', '').split(',')[0];
							var tLeft = Math.round( parseInt(DD.object.getAttribute('width')) / 2 );
							var tTop = Math.round( parseInt(DD.object.getAttribute('height')) / 2 );
							
							window.A.SVG.changeElement(DD.object, {
								'x': changes.x,
								'y': changes.y,
								'transform': "rotate(" + (angle) + "," + (changes.x + tLeft) + "," + (changes.y + tTop) + ")"
							});
							
						} else {
							window.A.SVG.changeElement(DD.object, changes);
						}
						
                        break;
                        
                }
                
                DD.onMove(e, changes);
                
            },
            
            Drop: function(e, t, options){
            
                var T = window.A.SVG;
                
                T.Drag_n_Drop.onDrop();
                
                switch (window.A.SVG.Drag_n_Drop.object.nodeName) {
                    case 'circle':
                        break;
                    case 'image':
                        window.A.SVG.Resizer.removeSizers();
                        window.A.Objects.selectThis(null, window.A.SVG.Drag_n_Drop.object);
                        break;
                    default:
                        window.A.SVG.Resizer.addSizers(window.A.SVG.Drag_n_Drop.object);
                }
                
                T.document.removeEventListener('mousemove', T.eventDD_Move, false);
                T.document.removeEventListener('mouseup', T.eventDD_Drop, false);
                
                T.Drag_n_Drop.object = null;
                
                // Funkciók kilövése
                T.Drag_n_Drop.onDrag = function(){};
                T.Drag_n_Drop.onMove = function(){};
                T.Drag_n_Drop.onDrop = function(){};
                
                
            }
            
        },
        
        Resizer: {
        
            addSizers: function(el, remove){
            
                window.A.SVG.Resizer.removeSizers();
                
                var circleElement = {
                    r: 4,
                    stroke: 'blue',
                    'stroke-width': 1,
                    fill: 'white',
                    cx: 0,
                    cy: 0
                }
                
                var objectType = el.getAttribute('type') ? el.getAttribute('type') : el.nodeName;
                
				if(el.nodeName == 'rect'){
					if( el.parentNode != null ){
						if(el.parentNode.getAttribute('id').search('l_rect') > -1)
						{
							objectType = 'l_rect';
							var o_el = el;
							el = el.parentNode;
						}
						if(el.parentNode.getAttribute('id').search('u_rect') > -1)
						{
							objectType = 'u_rect';
							var o_el = el;
							el = el.parentNode;
						}
					}					
				}
				

                switch (objectType) {
                
                    /*
                     * 	LINE
                     */
                    case 'line':
					case 'thin_line':
						
                        var c1 = window.A.SVG.createElement('circle', circleElement, 'resizeGroup', true);
                        var c2 = window.A.SVG.createElement('circle', circleElement, 'resizeGroup', true);
                        
                        c1.setAttribute('cy', el.getAttribute('y1'));
                        c1.setAttribute('cx', el.getAttribute('x1'));
                        
                        c2.setAttribute('cy', el.getAttribute('y2'));
                        c2.setAttribute('cx', el.getAttribute('x2'));
                        
                        c1.setAttribute('class', 'c1');
                        c2.setAttribute('class', 'c2');
                        
                        this.eventDrag = function(e){
                        
                            var DD = window.A.SVG.Drag_n_Drop;
                            
							DD.onDrag = function(){
								
								/* DISPLAY LENGTH */				
								var SVG_Text = window.A.SVG.createElement('text',{
										'id' : 'size-text-'+el.getAttribute('id'),
										'font-family' : 'Verdana',
										'font-size' : '12px',
										'font-weight' : 'bold',
										'x' : el.getAttribute('x1'),
										'y' : el.getAttribute('y1'),
										'transform' : 'translate(0,-10)'
								}, 'textGroup');
									
								var textNode = window.A.SVG.document.createTextNode('');												
								SVG_Text.appendChild( textNode );	
								
							}						
							
							DD.onDrag = function(){
								window.A.States.previous = window.A.svg2json();								
							}
							
							DD.onDrop = function(){
								window.A.SVG.Resizer.addSizers(el);							
							}
							
                            DD.onMove = function(e, changes){
                            	

								// Nem "window"
								if (window.A.selectedElement.getAttribute('class') != 'window') {	
																											
									if (this.object.getAttribute('class') == 'c1'){
										var Pos = window.A.Tools.Line.getCoordinates(e, [parseInt(window.A.selectedElement.getAttribute('x2')), parseInt(window.A.selectedElement.getAttribute('y2'))], true);                    					
										var changes = {
											x1 : Pos.x,
											y1 : Pos.y,
											x2 : window.A.selectedElement.getAttribute('x2'),
											y2 : window.A.selectedElement.getAttribute('y2')
										}
		
									}
									else {
										var Pos = window.A.Tools.Line.getCoordinates(e, [parseInt(window.A.selectedElement.getAttribute('x1')), parseInt(window.A.selectedElement.getAttribute('y1'))], true);                    															
										var changes = {
											x1 : window.A.selectedElement.getAttribute('x1'),
											y1 : window.A.selectedElement.getAttribute('y1'),
											x2 : Pos.x,
											y2 : Pos.y
										}
									}
																																						
									
									window.A.SVG.deleteAttachedElements(window.A.selectedElement);								
									window.A.SVG.changeElement(window.A.selectedElement, changes);																											
																	
								}
								
								// "Window"
								else {
																
									// Elements
			                        var pL = $SVG(window.A.selectedElement.parentNode.getAttribute('rel'));		
										                        			                        
									var lineX1 = parseInt(pL.getAttribute('x1'));
				                    var lineX2 = parseInt(pL.getAttribute('x2'));
				                    var lineY1 = parseInt(pL.getAttribute('y1'));
				                    var lineY2 = parseInt(pL.getAttribute('y2'));
					
									
									if(lineX1 != lineX2)
									{
										
										var cPos = window.A.Tools.Window.getCoordinates(e,pL);																		
										 
					                    if ((lineX1 < cPos.x && lineX2 > cPos.x) ||
					                    (lineX2 < cPos.x && lineX1 > cPos.x)) {
					                        var in_inner_line = true;
					                    }
					                    else {
					                        var in_inner_line = false;
					                    }
					                    
					                    
					                    if (!in_inner_line) {
					                        if ((lineX1 >= cPos.x && lineY1 <= cPos.y) ||
					                        (lineX1 >= cPos.x && lineY1 >= cPos.y)) {
					                            cPos.x = lineX1;
					                            cPos.y = lineY1;
					                        }
					                        else 
					                            if ((lineX2 <= cPos.x && lineY2 >= cPos.y) ||
					                            (lineX2 <= cPos.x && lineY1 <= cPos.y)) {
					                                cPos.x = lineX2;
					                                cPos.y = lineY2;
					                        	}
					                    }
										
				                    } 
									
									// Függőleges ablak
									else {
																											
										if(e.clientY > lineY2){ var nY = lineY2; }
										else if(e.clientY < lineY1){ var nY = lineY1; }
										else { var nY = e.clientY; }
										
										var cPos = {
											x: lineX1,
											y: nY
										}
										
									}
					
										
									if (this.object.getAttribute('class') == 'c1') {
										var changes = {
											x1 : cPos.x,
											y1 : cPos.y,
											x2 : window.A.selectedElement.getAttribute('x2'),
											y2 : window.A.selectedElement.getAttribute('y2')
										}
									}
									else {
										var changes = {
											x1 : window.A.selectedElement.getAttribute('x1'),
											y1 : window.A.selectedElement.getAttribute('y1'),
											x2 : cPos.x,
											y2 : cPos.y
										}
									}

									window.A.SVG.changeElement(window.A.selectedElement.parentNode.childNodes[0], changes);
									window.A.SVG.changeElement(window.A.selectedElement.parentNode.childNodes[1], changes);
									window.A.SVG.changeElement(window.A.selectedElement.parentNode.childNodes[2], changes);
																											
					
								}
								
								
									/*
									 * 	DISPLAY LENGTH
									 */
									
									var length_in_m = window.A.calcRatio(Math.vectorLength([changes.x1,changes.y1], [changes.x2, changes.y2]));
                    					
									var lengthText = $SVG('size-text-'+window.A.selectedElement.getAttribute('id'));												
									if(length_in_m > 2)
									{
										lengthText.textContent = length_in_m+' m';					
										var dims = lengthText.getBBox();
										
										var x = (Math.vectorLength([changes.x1,changes.y1], [changes.x2, changes.y2]) - dims.width) / 2;
										var tAngle = Math.AngleFromVectors([changes.x1,changes.y1], [changes.x2, changes.y2]);
										
										var tX = changes.x1;
										var tY = changes.y1;
					
										if(changes.x2 < changes.x1)
										{
											x = -(x+dims.width);										
											var transform = 'rotate('+(180-tAngle)+','+changes.x1+','+changes.y1+') translate('+x+',-10)';
										}
										else 
										{
											var transform = 'rotate('+(-tAngle)+','+changes.x1+','+changes.y1+') translate('+x+',-10)';
										}																	
				
										
										window.A.SVG.changeElement(lengthText, {
											'x' : tX,
											'y' : tY,
											'transform' : transform
										});
									} else {
										lengthText.textContent = '';
									}
									//if(length_in_m)
								
                            }
                            
                            DD.Drag(e);
                            
                        }.bind(this)
                        
                        c1.addEventListener('mousedown', this.eventDrag, false);
                        c2.addEventListener('mousedown', this.eventDrag, false);
                        
                        break;
                        
                        
                    /*
                     *  RECTANGLE
                     */
                    case 'rect':
                        
						var objTransform = $SVG_Trans(el);
						if(!objTransform){
							
	                        var c = new Array();
	                        for (var i = 1; i <= 2; i++) {
	                            c[i] = window.A.SVG.createElement('circle', circleElement, 'resizeGroup', true);
	                            c[i].setAttribute('class', 'c' + i);
	                        }
													
	                        // Bal felső
	                        c[1].setAttribute('cy', el.getAttribute('y'));
	                        c[1].setAttribute('cx', el.getAttribute('x'));
	                        
	                        // Jobb alsó
	                        c[2].setAttribute('cy', parseInt(el.getAttribute('y')) + parseInt(el.getAttribute('height')));
	                        c[2].setAttribute('cx', parseInt(el.getAttribute('x')) + parseInt(el.getAttribute('width')));
							
						
                        
	                        this.eventDrag = function(e){
	                        
	                            var DD = window.A.SVG.Drag_n_Drop;
	                            
	                            DD.tempData = [parseInt(el.getAttribute('x')), parseInt(el.getAttribute('y')), parseInt(el.getAttribute('width')), parseInt(el.getAttribute('height'))];
	                            
								DD.onDrag = function(){
									window.A.States.previous = window.A.svg2json();								
								}
							
								DD.onDrop = function(){
									window.A.SVG.Resizer.addSizers(el);							
								}
								
	                            DD.onMove = function(e, changes){
	                            
	                                var eX = changes.cx;
	                                var eY = changes.cy;
	                                
	                                switch (this.object.getAttribute('class')) {
	                                
	                                    case 'c1':
	                                        
	                                        var fX = DD.tempData[0] + DD.tempData[2];
	                                        var fY = DD.tempData[1] + DD.tempData[3];
	                                        
	                                        var nW = Math.abs(eX - fX);
	                                        var nH = Math.abs(eY - fY);
	                                        
	                                        if (eX > fX) {
	                                            var nX = fX;
	                                        }
	                                        else {
	                                            var nX = eX;
	                                        }
	                                        
	                                        if (eY > fY) {
	                                            var nY = fY;
	                                        }
	                                        else {
	                                            var nY = eY;
	                                        }
	                                        
	                                        break;
	                                        
	                                    case 'c2':
	                                        
	                                        var nW = Math.abs(eX - DD.tempData[0]);
	                                        var nH = Math.abs(eY - DD.tempData[1]);
	                                        
	                                        if (eX > DD.tempData[0]) {
	                                            var nX = DD.tempData[0];
	                                        }
	                                        else {
	                                            var nX = eX;
	                                        }
	                                        
	                                        if (eY > DD.tempData[1]) {
	                                            var nY = DD.tempData[1];
	                                        }
	                                        else {
	                                            var nY = eY;
	                                        }
	                                        
	                                        break;
	                                        
	                                }
	                                
	                                window.A.SVG.changeElement(window.A.selectedElement, {
	                                    width: nW,
	                                    height: nH,
	                                    x: nX,
	                                    y: nY
	                                });
	                                
	                            //////////console.log(window.A.selectedElement);
	                            //////////console.log(this.object);
	                            
	                            
	                            }
	                            
	                            DD.Drag(e);
	                            
	                        }.bind(this)
	                        
	                        c[1].addEventListener('mousedown', this.eventDrag, false);
	                        c[2].addEventListener('mousedown', this.eventDrag, false);
                        }
                        
                        break;
                        
                        
                    /*
                     *  "I" KONYHAPULT
                     */
                    case 'i_rect':
                        
						var objTransform = $SVG_Trans(el);
						if(!objTransform){
							
	                        var c = new Array();
	                        for (var i = 1; i <= 2; i++) {
	                            c[i] = window.A.SVG.createElement('circle', circleElement, 'resizeGroup', true);
	                            c[i].setAttribute('rel', 'c' + i);
								c[i].setAttribute('id', 'c' + i);
	                        }
	                        
	                        var width = parseInt(el.getAttribute('width'));
	                        var height = parseInt(el.getAttribute('height'));
	                        
	                        var x1 = parseInt(el.getAttribute('x'));
	                        var y1 = parseInt(el.getAttribute('y'));
	                        
	                        var x2 = parseInt(el.getAttribute('x'));
	                        var y2 = parseInt(el.getAttribute('y')) + height;
	                        
	                        var x3 = parseInt(el.getAttribute('x')) + width;
	                        var y3 = y1;
	                        
	                        var x4 = x3;
	                        var y4 = y2;
	                        
	                        
	                        // Bal / felső
	                        c[1].setAttribute('cy', (height == 20) ? ((y1 + y2) / 2) : (y1));
	                        c[1].setAttribute('cx', (height == 20) ? (x1) : ((x1 + x3) / 2));
	                        
	                        // Jobb / alsó
	                        c[2].setAttribute('cy', (height == 20) ? ((y3 + y4) / 2) : (y2));
	                        c[2].setAttribute('cx', (height == 20) ? (x3) : ((x2 + x4) / 2));
	                        
	                        this.eventDrag = function(e){
	                        
	                          	var DD = window.A.SVG.Drag_n_Drop;
	                                                      
	                            DD.tempData = [parseInt($SVG('c1').getAttribute('cx')), parseInt($SVG('c1').getAttribute('cy')), parseInt($SVG('c2').getAttribute('cx')), parseInt($SVG('c2').getAttribute('cy'))];
								
								
								DD.onDrag = function(){
									window.A.States.previous = window.A.svg2json();								
								}
							
							
								DD.onDrop = function(){
									window.A.SVG.Resizer.addSizers(el);							
								}
								
								
								var K = $SVG_Trans(window.A.selectedElement);
									
								if (K.rotate) {
									DD.tempData[5] = [K.rotate[1], K.rotate[2]];
									DD.tempData[4] = Math.round(Math.AngleFromVectors(DD.tempData[5],[DD.tempData[0],DD.tempData[1]],false,true));							           
									DD.tempData[6] = K;
								} else {
									DD.tempData[4] = 0;
								}
											
	                            DD.onMove = function(e, changes){
	                            
	                                switch (this.object.getAttribute('rel')) {
										
	                                    // C1
	                                    //----------------------
	                                    case 'c1':
	                                        
	                                        var eX = changes.cx;
	                                        var eY = changes.cy;
	                                        																				                                       
	                                        
	                                        var changes = {
	                                            width: nW,
	                                            height: nH,
	                                            x: nX,
	                                            y: nY
	                                        }
	                                        
	                                        break;
	                                        
	                                    // C2
	                                    //----------------------
	                                    case 'c2':
	                                                                              
											var cPos = centerOfLine({
							                    x1: DD.tempData[0],
							                    y1: DD.tempData[1],
							                    x2: DD.tempData[2],
							                    y2: DD.tempData[3],
							                    x3: e.clientX,
							                    y3: e.clientY
							                });
	                                        										
											var dAngle = DD.tempData[4]; //360-Math.abs(trans.rotate[0]) ;
																				
											// Síknegyed meghatározása										
											if( dAngle > 0 && dAngle < 90 ){ var siknegyed = 1; }
											else if( dAngle > 90 && dAngle < 180 ){ var siknegyed = 2; }
											else if( dAngle > 180 && dAngle < 270 ){ var siknegyed = 3; }
											else if( dAngle > 270 && dAngle < 360 ){ var siknegyed = 4; }									
											
											if( 
												(cPos.x < DD.tempData[0] && cPos.y < DD.tempData[1] && siknegyed==1) ||
												(cPos.x > DD.tempData[0] && cPos.y < DD.tempData[1] && siknegyed==2) ||
												(cPos.x > DD.tempData[0] && cPos.y > DD.tempData[1] && siknegyed==3) ||	
												(cPos.x < DD.tempData[0] && cPos.y > DD.tempData[1] && siknegyed==4) ||										
												(dAngle==0 && e.clientX < DD.tempData[0]) ||
												(dAngle==90 && e.clientY < DD.tempData[1]) ||
												(dAngle==270 && e.clientY > DD.tempData[1])
											)
											{
												nW = 1;
											}
											else {											
												if (dAngle == 90) {
													var nW = e.clientY - DD.tempData[1];
												}
												else if (dAngle == 270) {
													var nW = DD.tempData[1] - e.clientY;
												}
												else {
													var nW = Math.vectorLength([cPos.x, cPos.y], [DD.tempData[0], DD.tempData[1]]);										
												}
											}
										
		                                    var changes = {
		                                    	width: nW	                                        
		                                    }
											
	                                        break;
	                                        
	                                }
	                                
	                                window.A.SVG.changeElement(window.A.selectedElement, changes);
	                                
	                                
	                                
	                            }
	                            
	                            DD.Drag(e);
	                            
	                        }.bind(this)
	                        
	                        c[2].addEventListener('mousedown', this.eventDrag, false);
	                        c[1].addEventListener('mousedown', this.eventDrag, false);
                        
						}
						
                        break;
						
						
					/*
                     *  "L" KONYHAPULT
                     */
                    case 'l_rect':
                        
						var objTransform = $SVG_Trans(el);
						if(!objTransform){
							
	                        var c = new Array();
	                        for (var i = 1; i <= 2; i++) {
	                            c[i] = window.A.SVG.createElement('circle', circleElement, 'resizeGroup', true);
	                            c[i].setAttribute('rel', 'c'+i);
	                        }
	                        
	                        						
	                        // Vízszintes összetevő
	                        c[1].setAttribute('cy', parseInt(el.childNodes[0].getAttribute('y'))+8);
	                        c[1].setAttribute('cx', parseInt(el.childNodes[0].getAttribute('x'))+parseInt(el.childNodes[0].getAttribute('width')));
	                        
							// Függőleges összetevő
	                        c[2].setAttribute('cy', parseInt(el.childNodes[1].getAttribute('y'))+parseInt(el.childNodes[1].getAttribute('height')));
	                        c[2].setAttribute('cx', parseInt(el.childNodes[1].getAttribute('x'))+8);
							
	                        this.eventDrag = function(e){
	                        
	                            var DD = window.A.SVG.Drag_n_Drop;
	                            	                            
	                            DD.tempData = {
									child1 : [parseInt(el.childNodes[0].getAttribute('x')), parseInt(el.childNodes[0].getAttribute('y')), parseInt(el.childNodes[0].getAttribute('width')), parseInt(el.childNodes[0].getAttribute('height'))],
									child2 : [parseInt(el.childNodes[1].getAttribute('x')), parseInt(el.childNodes[1].getAttribute('y')), parseInt(el.childNodes[1].getAttribute('width')), parseInt(el.childNodes[1].getAttribute('height'))]
								}	
								
								DD.onDrag = function(){
									window.A.States.previous = window.A.svg2json();								
								}
							
								DD.onDrop = function(){
									window.A.SVG.Resizer.addSizers(o_el);							
								}																					
	                            
	                            DD.onMove = function(e, changes){
	                            
	                                switch (this.object.getAttribute('rel')) {
										
	                                    // C1
	                                    //----------------------
	                                    case 'c1':
	                                        
	                                        var nW = changes.cx-DD.tempData.child1[0];
	                                          
											window.A.SVG.changeElement(window.A.selectedElement.childNodes[0], {
	                                            width: (nW < 19) ? 19 : nW
	                                        });
											
	                                        break;
	                                        
	                                    // C2
	                                    //----------------------
	                                    case 'c2':
	                                        
	                                        var nH = changes.cy-DD.tempData.child2[1];
	                                          
											window.A.SVG.changeElement(window.A.selectedElement.childNodes[1], {
	                                            height: (nH < 19) ? 19 : nH
	                                        });
											
	                                        break;
	                                        
	                                        break;
	                                        
	                                }
	                                                                                               
	                                
	                                
	                            }
	                            
	                            DD.Drag(e);
	                            
	                        }.bind(this)
	                        
	                        c[2].addEventListener('mousedown', this.eventDrag, false);
	                        c[1].addEventListener('mousedown', this.eventDrag, false);
                        
						}
						
                        break;
						
						
						
					/*
                     *  "L" KONYHAPULT
                     */
                    case 'u_rect':
                        
						var objTransform = $SVG_Trans(el);
						if(!objTransform){
							
	                        var c = new Array();
	                        for (var i = 1; i <= 4; i++) {
	                            c[i] = window.A.SVG.createElement('circle', circleElement, 'resizeGroup', true);
	                            c[i].setAttribute('rel', 'c'+i);
	                        }
	                                             
	                        // Bal
	                        c[1].setAttribute('cy', parseInt(el.childNodes[0].getAttribute('y'))+10);
	                        c[1].setAttribute('cx', parseInt(el.childNodes[0].getAttribute('x')));
	                        
							// Jobb
	                        c[2].setAttribute('cy', parseInt(el.childNodes[1].getAttribute('y'))+10);
	                        c[2].setAttribute('cx', parseInt(el.childNodes[1].getAttribute('x'))+parseInt(el.childNodes[1].getAttribute('width')));
							
							// Bal lent
							c[3].setAttribute('cy', parseInt(el.childNodes[0].getAttribute('y'))+parseInt(el.childNodes[0].getAttribute('height')));
	                        c[3].setAttribute('cx', parseInt(el.childNodes[0].getAttribute('x'))+10);
							
							// Jobb lent
							c[4].setAttribute('cy', parseInt(el.childNodes[1].getAttribute('y'))+parseInt(el.childNodes[1].getAttribute('height')));
	                        c[4].setAttribute('cx', parseInt(el.childNodes[1].getAttribute('x'))+10);
							
	   					
	                        this.eventDrag = function(e){
	                        
	                            var DD = window.A.SVG.Drag_n_Drop;
	                            
	                            
	                            DD.tempData = {
									child1 : [parseInt(el.childNodes[0].getAttribute('x')), parseInt(el.childNodes[0].getAttribute('y')), parseInt(el.childNodes[0].getAttribute('width')), parseInt(el.childNodes[0].getAttribute('height'))],
									child2 : [parseInt(el.childNodes[1].getAttribute('x')), parseInt(el.childNodes[1].getAttribute('y')), parseInt(el.childNodes[1].getAttribute('width')), parseInt(el.childNodes[1].getAttribute('height'))],
									child3 : [parseInt(el.childNodes[2].getAttribute('x')), parseInt(el.childNodes[2].getAttribute('y')), parseInt(el.childNodes[2].getAttribute('width')), parseInt(el.childNodes[2].getAttribute('height'))]
								}
								
								DD.onDrag = function(){
									window.A.States.previous = window.A.svg2json();								
								}
							
								DD.onDrop = function(){
									window.A.SVG.Resizer.addSizers(o_el);							
								}																						                            
	                            
	                            DD.onMove = function(e, changes){
	                            
	                                switch (this.object.getAttribute('rel')) {
										
	                                    // C1
	                                    //----------------------
	                                    case 'c1':
	                                        
	                                        var nW = changes.cx-(DD.tempData.child3[0]+DD.tempData.child3[2]);
	                                        var nX = (changes.cx > (DD.tempData.child3[0]+DD.tempData.child3[2])-47) ? (DD.tempData.child3[0]+DD.tempData.child3[2])-47 : changes.cx;
											 
											window.A.SVG.changeElement(window.A.selectedElement.childNodes[2], {
	                                            width: (Math.abs(nW) < 47 || changes.cx > (DD.tempData.child3[0]+DD.tempData.child3[2])) ? 47 : Math.abs(nW),
												x : nX
	                                        });
											
											//var cX = parseInt(window.A.selectedElement.childNodes[2].getAttribute('x'));
											//var cW = parseInt(window.A.selectedElement.childNodes[2].getAttribute('width'));
											
											window.A.SVG.changeElement(window.A.selectedElement.childNodes[0], {
	                                            x: nX
	                                        });
																				
											window.A.SVG.changeElement(window.A.selectedElement.childNodes[3], {
	                                            x: nX
	                                        });
											
	                                        break;
	                                        
	                                    // C2
	                                    //----------------------
	                                    case 'c2':
	                                        
	                                        var nW = changes.cx-DD.tempData.child3[0];
	                                          
											window.A.SVG.changeElement(window.A.selectedElement.childNodes[2], {
	                                            width: (nW < 51) ? 51 : nW
	                                        });
											
											var cX = parseInt(window.A.selectedElement.childNodes[2].getAttribute('x'));
											var cW = parseInt(window.A.selectedElement.childNodes[2].getAttribute('width'));
											
											var nX = cX+(cW-20); //-DD.tempData.child3[0];										
											window.A.SVG.changeElement(window.A.selectedElement.childNodes[1], {
	                                            x: nX
	                                        });
																				
											window.A.SVG.changeElement(window.A.selectedElement.childNodes[4], {
	                                            x: nX
	                                        });
											
	                                        break;
											
										// C3
	                                    //----------------------
	                                    case 'c3':
	        
	                                        var nH = changes.cy-DD.tempData.child1[1];
	                                          
											window.A.SVG.changeElement(window.A.selectedElement.childNodes[0], {
	                                            height: (nH < 25) ? 25 : nH
	                                        });
											
	                                        break;
											
										// C4
	                                    //----------------------
	                                    case 'c4':
	        
	                                        var nH = changes.cy-DD.tempData.child2[1];
	                                          
											window.A.SVG.changeElement(window.A.selectedElement.childNodes[1], {
	                                            height: (nH < 25) ? 25 : nH
	                                        });
											
	                                        break;
	                                        
	                                }
	                                                                                               
	                                
	                                
	                            }
	                            
	                            DD.Drag(e);
	                            
	                        }.bind(this)
	                        
							c[1].addEventListener('mousedown', this.eventDrag, false);
	                        c[2].addEventListener('mousedown', this.eventDrag, false);  
							c[3].addEventListener('mousedown', this.eventDrag, false);
	                        c[4].addEventListener('mousedown', this.eventDrag, false);                      
                        
						}
						
                        break;
                        
                }
                
                
            },
            
            removeSizers: function(){
                var cNodes = window.A.SVG.document.getElementById('resizeGroup');
      
				while (cNodes.hasChildNodes()) {
					cNodes.removeChild(cNodes.lastChild);
				}
                
            }
            
        }
    
    },
    
   
    
    /* 
     *  (RAJZ) ESZKÖZÖK
     *   @ Line : vonalak (falak) rajzolására alkalmas eszköz
     *   X Erase : radír
     *
     */
    Tools: {
    
        /*
         *   LINE TOOL
         *   @ init : eldönti, hogy a kattintás rajzolás kezdése vagy leállítása
         *   @ Start: rajzolás kezdése, vonal objektum létrehozása
         *   @ Drawing : rajzolás
         *   @ Stop : rajzolás leállítása
         *   @ Select : vonal kijelölése
         *
         */
        Line : {
        
            type: 'line',
            object: null,
            coordSystem: true,
            alignToGrid: false,
            counter: 0,
            
            init: function(e, options, t){
				
                /* START */
                if (this.Tools.Line.object == null) {					
                    this.Tools.Line.Start(e, t ? t : this, options);
                }
                /* STOP */
                else {
                    this.Tools.Line.Stop(e, t ? t : this);
                }
                
            },
            
            Start: function(e, t, options){
            	
				window.A.States.previous = window.A.svg2json();
				
                var Pos = t.Tools.Line.getCoordinates(e, [e.clientX, e.clientY], false);
                
                /* Line-ID meghatározása */
                var line_id = 'line-' + t.Tools.Line.counter;
                t.Tools.Line.counter++;
				
                t.Tools.Line.object = t.SVG.createElement('line', {
                    id: line_id,
                    x1: Pos.x,
                    y1: Pos.y,
                    x2: Pos.x,
                    y2: Pos.y,
                    'stroke-width': (t.Tools.Line.type == 'thin_line') ? 3 : 9,
                    rel: t.Tools.Line.type,
                    eName: Language.getString('element.names.' + ((t.Tools.Line.type == 'thin_line') ? 'thin_line' : 'line')),
                    eLength: 0
                }, 'lineGroup');              
				
           		
				/* DISPLAY LENGTH */
				
				var SVG_Text = window.A.SVG.createElement('text',{
						'id' : 'size-text-'+line_id,
						'visibility' : (window.A.displayLT) ? 'visible' : 'hidden',
						'font-family' : 'Verdana',
						'font-size' : '10px',
						'font-weight' : 'bold',
						'x' : Pos.x,
						'y' : Pos.y,						
						'transform' : 'translate(0,-10)'
						
				}, 'textGroup');
					
				var textNode = window.A.SVG.document.createTextNode('');												
				SVG_Text.appendChild( textNode );	
					                
                
            },
            
            Drawing: function(e){
            
                if (this.Tools.Line.object != null) {
                
                    var x1 = this.Tools.Line.object.getAttribute('x1');
                    var y1 = this.Tools.Line.object.getAttribute('y1');
                    
                    var Pos = this.Tools.Line.getCoordinates(e, [parseInt(x1), parseInt(y1)], true);
                    
                    
                    /*
                     *   Alkalmazás
                     */
                    this.SVG.changeElement(this.Tools.Line.object, {
                        x2: Pos.x,
                        y2: Pos.y
                    });
                    
                    
                    /*
                     * 	 Hossz meghatározása és kiíratása
                     */
                    var osztas = 27; // 20 (+1) -> a korrekt számolásért
                    var arany = 100; // 100 cm
                    var length_in_m = window.A.calcRatio(Math.vectorLength([x1, y1], [Pos.x, Pos.y]));
                    
                 
                    this.SVG.changeElement(this.Tools.Line.object, {
                        eLength: length_in_m
                    });
										
					/*
					 * 	DISPLAY LENGTH
					 */					
						var lengthText = $SVG('size-text-' + this.Tools.Line.object.getAttribute('id'));
						
							lengthText.textContent = length_in_m + ' m';
							var dims = lengthText.getBBox();
							
							var x = (Math.vectorLength([x1, y1], [Pos.x, Pos.y]) - dims.width) / 2;
							var tAngle = Math.AngleFromVectors([x1, y1], [Pos.x, Pos.y]);
							
							
							if (Pos.x < x1) {
								var tX = x1;
								var tY = y1;
								
								x = -(x + dims.width);
								
								var transform = 'rotate(' + (180 - tAngle) + ',' + x1 + ',' + y1 + ') translate(' + x + ',-10)';
							}
							else {
								var tX = x1;
								var tY = y1;
								var transform = 'rotate(' + (-tAngle) + ',' + x1 + ',' + y1 + ') translate(' + x + ',-10)';
							}
							
							this.SVG.changeElement(lengthText, {
								'x': tX,
								'y': tY,
								'transform': transform
							});
										
                }
                
            },
            
            getCoordinates: function(e, original, CS){
                // Rácspontokra igazítás
                if (window.A.Tools.Line.alignToGrid) {
                
                    var Pos = alignToGrid(e.clientX, e.clientY);
                    
                    if (window.A.Tools.Line.coordSystem && CS) {
                    
                        var OP = alignToGrid(original[0], original[1]);
                        
                        if (Math.abs(Pos.x - OP.x) >= Math.abs(Pos.y - OP.y)) {
                            //Pos.x = e.clientX;
                            Pos.y = OP.y;
                        }
                        else {
                            Pos.x = OP.x;
                            //Pos.y = e.clientY;
                        }
                        
                    }
                    
                    return Pos;
                    
                }
                else {
                
                    if (window.A.Tools.Line.coordSystem && CS) {
                    
                        if (Math.abs(e.clientX - original[0]) >= Math.abs(e.clientY - original[1])) {
                            var nX = e.clientX;
                            var nY = original[1];
                        }
                        else {
                            var nX = original[0];
                            var nY = e.clientY;
                        }
                        
                        return {
                            x: nX,
                            y: nY
                        };
                        
                    }
                    else {
                        return {
                            x: e.clientX,
                            y: e.clientY
                        };
                    }
                }
            },
            
            
            Stop: function(e, t){
            
                // Koordináták fecserélése, ha kell
                var x1 = parseInt(this.object.getAttribute('x1'));
                var y1 = parseInt(this.object.getAttribute('y1'));
                var x2 = parseInt(this.object.getAttribute('x2'));
                var y2 = parseInt(this.object.getAttribute('y2'));
                if (x2 < x1 || (y2 < y1 && x1==x2)) {
                    window.A.SVG.changeElement(this.object, {
                        'x1': x2,
                        'y1': y2,
                        'x2': x1,
                        'y2': y1
                    });
                }

                this.eventSelectLine = this.Select;
                this.object.addEventListener('mousedown', this.eventSelectLine, false);
                
                this.eventDrag = window.A.SVG.Drag_n_Drop.Drag;
                this.object.addEventListener('mousedown', this.eventDrag, false);
                
                this.object.addEventListener('mouseover', this.onOver, false);
                this.object.addEventListener('mouseout', this.onOut, false);
                               
                //window.A.SVG.removeElement( $SVG('size-text-'+this.object.getAttribute('id')) );
								
				var lengthText = $SVG('size-text-' + this.object.getAttribute('id'));
				if (parseFloat(lengthText.textContent)  <= 2) {
						lengthText.textContent = '';
				}	
                
				this.object = null;                
				
				
            },
            
            Abort: function(){
            
            
            
            },
            
            
            onOver: function(){
                if (window.A.selectedTool == null && window.A.SVG.Drag_n_Drop.object == null) {
                    window.A.SVG.changeElement(this, {
                        stroke: 'blue'
                    }, true);
                    window.A.SVG.Resizer.addSizers(this);
                    window.A.SVG.body.setAttribute("cursor", "move");
                }
            },
            
            onOut: function(){
                if (this != window.A.SVG.Drag_n_Drop.object &&
                this != window.A.selectedElement) /* EMIATT VAN HOGY BERAGAD A HOVER */ {
                    window.A.SVG.changeElement(this, {
                        stroke: 'black'
                    }, true);
                    window.A.SVG.Resizer.removeSizers();
                }
                window.A.SVG.body.setAttribute("cursor", "default");
            },
            
            Select: function(evt, t){
            
                if (window.A.selectedTool == null) {
                    if (window.A.selectedElement) {
                        window.A.SVG.unselectElement();
                        window.A.SVG.Resizer.removeSizers();
                    }
                    
                    
                    window.A.selectedElement = evt.target;
                    evt.target.setAttributeNS(null, 'stroke', 'blue');
                    
                    window.A.SVG.Resizer.addSizers(evt.target);
                    
                    // Információk megjelenítése az infóboxban
                    var buildedHTML = Tpl.get('IB_ELEMENT_LINE_INFORMATION', {
                        name: window.A.selectedElement.getAttribute('eName'),
                        length: window.A.selectedElement.getAttribute('eLength')
                    });
                    
                    /*for( x in evt.target ){
                     alert( x );
                     }*/
                    InformationBox.update(buildedHTML);
                    InformationBox.show();
                    
                }
                
            },
            
            unSelect: function(evt, t){
            
                window.A.removeResizers();
                window.A.selectedElement.setAttributeNS(null, 'stroke', 'black');
                window.A.selectedElement = null;
                
            }
            
        },
        
        /*
         *   WINDOW TOOL
         *
         */
        Window : {
        
            eX1: null,
            eY1: null,
            eX2: null,
            eY2: null,
            parentObject: null,
            object: null,
            counter: 0,
            
            init: function(e, options, t){
            
                /* START */
                if (this.Tools.Window.object == null) {
                    this.Tools.Window.Start(e, t ? t : this, options);
                }
                /* STOP */
                else {
                    this.Tools.Window.Stop(e, t ? t : this);
                }
                
            },
            
            Start: function(e, t, options){
            
                if (e.target.getAttribute('rel') == 'line') {
                
					window.A.States.previous = window.A.svg2json();				
				
                    t.Tools.Window.parentObject = e.target;
                    t.Tools.Window.eX1 = e.clientX;
                    t.Tools.Window.eY1 = e.clientY;
                    
                    
                    /* Pozíció lekérdezése */
					if (parseInt(e.target.getAttribute('x1')) != parseInt(e.target.getAttribute('x2'))) {
						var cPos = t.Tools.Window.getCoordinates(e);
					} else {
						var cPos = {
							x: parseInt(e.target.getAttribute('x1')),
							y: e.clientY
						}
					}
                    
                    /* Window-ID meghatározása */
                    var window_g_id = 'window-' + t.Tools.Window.counter;
                    
                    /* Window group és childNodes létrehozása  */
                    var Wnd = window.A.SVG.createElement('g', {
                        'id': window_g_id,
                        'rel': e.target.getAttribute('id')
                    }, 'windowGroup');
                    
					
					window.A.SVG.createElement('line', {
						'rel' : window_g_id,
						'class' : 'window',
                        'stroke-width': 9,
                        stroke: 'black',
                        x1: cPos.x,
                        y1: cPos.y,
                        x2: cPos.x,
                        y2: cPos.y
                    }, window_g_id);
					
					
                    window.A.SVG.createElement('line', {
						'rel' : window_g_id,
						'class' : 'window',
                        'stroke-width': 6,
                        stroke: 'white',
                        x1: cPos.x,
                        y1: cPos.y,
                        x2: cPos.x,
                        y2: cPos.y
                    }, window_g_id);
										
                    
                    window.A.SVG.createElement('line', {
						'rel' : window_g_id,
						'class' : 'window',
                        'stroke-width': 1,
                        stroke: 'black',
                        x1: cPos.x,
                        y1: cPos.y,
                        x2: cPos.x,
                        y2: cPos.y
                    }, window_g_id);
                    
                    /* Ablak objektum eltárolása */
                    t.Tools.Window.object = Wnd;
                    
                    
                }
                else {
					alert('Az ablak objektum csak falra helyezhető el!');
				}
              
                
            },
            
            
            Drawing: function(e){
            
                if (this.Tools.Window.object != null) {
                
                    var lineX1 = window.A.Tools.Window.parentObject.getAttribute('x1');
                    var lineY1 = window.A.Tools.Window.parentObject.getAttribute('y1');
                    var lineX2 = window.A.Tools.Window.parentObject.getAttribute('x2');
                    var lineY2 = window.A.Tools.Window.parentObject.getAttribute('y2');

					if(lineX1 != lineX2)
					{
						
						/* Pozíció lekérdezése */
						var cPos = this.Tools.Window.getCoordinates(e);
						 
	                    if ((lineX1 < cPos.x && lineX2 > cPos.x) ||
	                    (lineX2 < cPos.x && lineX1 > cPos.x)) {
	                        var in_inner_line = true;
	                    }
	                    else {
	                        var in_inner_line = false;
	                    }
	                    
	                    
	                    if (!in_inner_line) {
	                        if ((lineX1 >= cPos.x && lineY1 <= cPos.y) ||
	                        (lineX1 >= cPos.x && lineY1 >= cPos.y)) {
	                            cPos.x = lineX1;
	                            cPos.y = lineY1;
	                        }
	                        else 
	                            if ((lineX2 <= cPos.x && lineY2 >= cPos.y) ||
	                            (lineX2 <= cPos.x && lineY1 <= cPos.y)) {
	                                cPos.x = lineX2;
	                                cPos.y = lineY2;
	                        	}
	                    }
						
                    } 
					
					// Függőleges ablak
					else {
																							
						if(e.clientY > lineY2){ var nY = lineY2; }
						else if(e.clientY < lineY1){ var nY = lineY1; }
						else { var nY = e.clientY; }
						
						var cPos = {
							x: lineX1,
							y: nY
						}
						
					}
                    
                    for (var i = 0; i < this.Tools.Window.object.childNodes.length; i++) {
                    
                        this.SVG.changeElement(this.Tools.Window.object.childNodes[i], {
                            x2: cPos.x,
                            y2: cPos.y
                        });
                        
                    }
                    
                    /*
                     * 	 Hossz meghatározása és kiíratása
                     */
                    var osztas = 27; // 20 (+1) -> a korrekt számolásért
                    var arany = 100; // 100 cm
                    var length_in_m = window.A.calcRatio(Math.vectorLength([parseInt(this.Tools.Window.object.childNodes[0].getAttribute('x1')), parseInt(this.Tools.Window.object.childNodes[0].getAttribute('y1'))], [parseInt(cPos.x), parseInt(cPos.y)]));
                    
                    //InformationBox.update(length_in_m, 'span');
                    
                    /*this.SVG.changeElement(this.Tools.Line.object, {
                    
                     eLength : length_in_m
                    
                     });*/
                    
                }
                
            },
            
            getCoordinates: function(evt, parentObject){
                return centerOfLine({
                    x1: parseInt((parentObject ? parentObject : window.A.Tools.Window.parentObject).getAttribute('x1')),
                    y1: parseInt((parentObject ? parentObject : window.A.Tools.Window.parentObject).getAttribute('y1')),
                    x2: parseInt((parentObject ? parentObject : window.A.Tools.Window.parentObject).getAttribute('x2')),
                    y2: parseInt((parentObject ? parentObject : window.A.Tools.Window.parentObject).getAttribute('y2')),
                    x3: evt.clientX, //: window.A.Tools.Window.eX1,
                    y3: evt.clientY // window.A.Tools.Window.eY1
                });
            },
            
            
            Stop: function(e, t){
            
                this.eventSelectLine = this.Select;
                this.object.addEventListener('mousedown', this.eventSelectLine, false);
                
                this.eventDrag = window.A.SVG.Drag_n_Drop.Drag;
                this.object.addEventListener('mousedown', this.eventDrag, false);
                
                //this.object.addEventListener('mouseover', this.onOver, false);
                //this.object.addEventListener('mouseout', this.onOut, false);
                
                this.counter++;
                this.object = null;
                this.parentObject = null;
                
                InformationBox.hide();
                InformationBox.update('');
                
                
            },
            
            Abort: function(){
            
            
            
            },
            
            onOver: function(){
               /* if (window.A.selectedTool == null) {
                    window.A.SVG.changeElement(this, {
                        stroke: 'blue'
                    }, true);
                    window.A.SVG.Resizer.addSizers(this);
                }*/
            },
            
            onOut: function(){
                /*if (this != window.A.SVG.Drag_n_Drop.object &&
                this != window.A.selectedElement)  EMIATT VAN HOGY BERAGAD A HOVER {
                    window.A.SVG.changeElement(this, {
                        stroke: 'black'
                    }, true);
                    window.A.SVG.Resizer.removeSizers();
                }*/
            },
            
            Select: function(evt, t){
            
                if (window.A.selectedTool == null) {
                    /*if(window.A.selectedElement) {
                     window.A.selectedElement.setAttributeNS(null,'stroke','black');
                     window.A.SVG.Resizer.removeSizers();
                     }
                     */
                    window.A.selectedElement = evt.target;
                    //evt.target.setAttributeNS(null,'stroke','blue');
                    
                    //window.A.SVG.Resizer.addSizers(evt.target);
                    
                }
                
            },
						
            unSelect: function(evt, t){
            
                window.A.removeResizers();
                window.A.selectedElement.setAttributeNS(null, 'stroke', 'black');
                window.A.selectedElement = null;
                
            }
            
        },
        
        /*
         *   TOOL
         *
         */
        Door : {
        
            eX1: null,
            eY1: null,
            eX2: null,
            eY2: null,
            parentObject: null,
            object: null,
            counter: 0,
			flipped: false,
			dAngle : 0,
			type : null,
            
            init: function(e, options, t){
            
				/* START */
                if (this.Tools.Door.object == null) {
                  	this.Tools.Door.Start(e, t ? t : this, options);
                }
                /* STOP */
                else {
                    this.Tools.Door.Stop(e, t ? t : this);
                }
                
        
            },
            
            Start: function(e, t, options){
            
              
                if (e.target.getAttribute('rel') == 'line' || e.target.getAttribute('rel') == 'thin_line') {
                
					window.A.States.previous = window.A.svg2json();	
					
                    t.Tools.Door.parentObject = e.target;
                    t.Tools.Door.eX1 = e.clientX;
                    t.Tools.Door.eY1 = e.clientY;
                    
                    var E1 = [parseInt(e.target.getAttribute('x1')), parseInt(e.target.getAttribute('y1'))];
                    var E2 = [parseInt(e.target.getAttribute('x2')), parseInt(e.target.getAttribute('y2'))];
                    
                    var Angle = Math.AngleFromVectors(E1, E2);                    					
					t.Tools.Door.dAngle = Angle;
	
					var cPos = window.A.Tools.Door.getCoordinates(e);										
					
					var iX = E1[0];
					var iY = E1[1];	
					
					var dW = (t.Tools.Door.type != 'double_door') ? 28 : 57;
					var dH = 34;
									
					if( E1[0] != E2[0] )
					{
						var tLeft = Math.vectorLength( E1, [cPos.x,cPos.y] );
						var tTop = -5;
					} else {									
						var Angle = 90;
						var tLeft = -30-(e.clientY-E1[1]);
						var tTop = -5;
					}

                    window.A.Tools.Door.object = window.A.SVG.createElement('image', {
						id: 'door-'+window.A.Tools.Door.counter,
						rel: e.target.getAttribute('id'),
                        x: iX,
                        y: iY,
                        width: dW+'px',
                        height: dH+'px',
						'class' : 'normal',
                        'xlink:href': 'templates/default/images/_objects/'+t.Tools.Door.type+'.png',
						'transform' : 'rotate(' + (-Angle) + ',' + iX + ',' + iY + ') translate('+tLeft+','+tTop+')'						
                    }, 'doorGroup');
    				
					window.A.Tools.Door.counter++;										                
				
                } else {
					alert('Az ajtó objektum csak falra helyezhető el!');
				}
                
            
            },
            
            onMove: function(e){
            
                if (this.Tools.Door.object != null) {
                	
					var pL = $SVG(this.Tools.Door.object.getAttribute('rel'));
				
				 	var E1 = [parseInt(pL.getAttribute('x1')), parseInt(pL.getAttribute('y1'))];
                    var E2 = [parseInt(pL.getAttribute('x2')), parseInt(pL.getAttribute('y2'))];
                    
					var dWIDTH = parseInt(this.Tools.Door.object.getAttribute('width'));
				
                    /*
					 *  JEGYZET: Ha 180 fokkal elforgatjuk az ajtót,
					 *           akkor az eltolást mínusz irányba kell végezni
					 */
					
					var nAngle = Math.AngleFromVectors(E1,[e.clientX,e.clientY]);				
					
					if( E1[1] == E2[1]  )
					{
						if( nAngle > 0 && nAngle < 180 && !this.Tools.Door.flipped ){
							var isTransformation = true;
							this.Tools.Door.flipped = true;
						} 
						else 
						if( nAngle > 180 && nAngle < 360 && this.Tools.Door.flipped ){
							var isTransformation = true;
							this.Tools.Door.flipped = false;
						}
					}
					else if( E1[0] == E2[0]  )
					{
						if( nAngle > 90 && nAngle < 270 && !this.Tools.Door.flipped ){
							var isTransformation = true;
							this.Tools.Door.flipped = true;
						} 
						else 
						if( (nAngle < 90 || nAngle > 270) && this.Tools.Door.flipped ){
							var isTransformation = true;
							this.Tools.Door.flipped = false;
						}
					} 
					else 
					{
						
					
						if((nAngle > this.Tools.Door.dAngle) && (nAngle < (this.Tools.Door.dAngle+(180-this.Tools.Door.dAngle))) && !this.Tools.Door.flipped )
						{
							var isTransformation = true;
							this.Tools.Door.flipped = true;
						}
						else 
						if((nAngle < this.Tools.Door.dAngle) && (nAngle > (this.Tools.Door.dAngle-(180-this.Tools.Door.dAngle))) && this.Tools.Door.flipped )
						{
							var isTransformation = true;
							this.Tools.Door.flipped = false;
						}
						
					}
					
					
					if(isTransformation)
					{
						var trans = this.Tools.Door.getTransformsData();
						
						if( this.Tools.Door.flipped )
						{							
							trans.rotate[0] = parseInt(trans.rotate[0])+180;
							trans.translate[0] = -1 * (parseInt(trans.translate[0])+dWIDTH);
						} else {
							trans.rotate[0] = parseInt(trans.rotate[0])-180;
							trans.translate[0] = (-1 * parseInt(trans.translate[0]))-dWIDTH;
						}
						
						window.A.SVG.changeElement(this.Tools.Door.object,{
							'class' : this.Tools.Door.flipped ? 'flipped' : '',
							'transform' : 'rotate('+trans.rotate[0]+','+trans.rotate[1]+','+trans.rotate[2]+') translate('+trans.translate[0]+','+trans.translate[1]+')'
						});
						
					}
                    
                }
                
            },
			
			getTransformsData : function()
			{
				var obj = window.A.Tools.Door.object;
				var transforms = obj.getAttribute('transform').split(') ');
				
				var rotate = transforms[0].replace('rotate(','').split(',');
				
				var translate = transforms[1].replace('translate(','').replace(')','').split(',');
				
				return { 'rotate' : rotate, 'translate' : translate };
				
			},
			
			Stop: function()
			{
				this.eventDrag = window.A.SVG.Drag_n_Drop.Drag;
	            window.A.Tools.Door.object.addEventListener('mousedown', this.eventDrag, false);
					
	            window.A.Tools.Door.object = null;
	            window.A.Tools.Door.parentObject = null;			
				window.A.Tools.Door.dAngle = 0;
				window.A.Tools.Door.flipped = false;
				
			},
            
            getCoordinates: function(evt, parentObject){
                return centerOfLine({
                    x1: parseInt((parentObject ? parentObject : window.A.Tools.Door.parentObject).getAttribute('x1')),
                    y1: parseInt((parentObject ? parentObject : window.A.Tools.Door.parentObject).getAttribute('y1')),
                    x2: parseInt((parentObject ? parentObject : window.A.Tools.Door.parentObject).getAttribute('x2')),
                    y2: parseInt((parentObject ? parentObject : window.A.Tools.Door.parentObject).getAttribute('y2')),
                    x3: evt.clientX, //: window.A.Tools.Window.eX1,
                    y3: evt.clientY // window.A.Tools.Window.eY1
                });
            },
            
            Abort: function(){
            
            
            
            },
            
            onOver: function(){
                if (window.A.selectedTool == null) {
                    window.A.SVG.changeElement(this, {
                        stroke: 'blue'
                    }, true);
                    window.A.SVG.Resizer.addSizers(this);
                }
            },
            
            onOut: function(){
                if (this != window.A.SVG.Drag_n_Drop.object &&
                this != window.A.selectedElement) /* EMIATT VAN HOGY BERAGAD A HOVER */ {
                    window.A.SVG.changeElement(this, {
                        stroke: 'black'
                    }, true);
                    window.A.SVG.Resizer.removeSizers();
                }
            },
            
            Select: function(evt, t){
            
                if (window.A.selectedTool == null) {
                    /*if(window.A.selectedElement) {
                     window.A.selectedElement.setAttributeNS(null,'stroke','black');
                     window.A.SVG.Resizer.removeSizers();
                     }
                     */
                    window.A.selectedElement = evt.target;
                    //evt.target.setAttributeNS(null,'stroke','blue');
                    
                    //window.A.SVG.Resizer.addSizers(evt.target);
                    
                    // Információk megjelenítése az infóboxban
                    
                }
                
            },
            
            unSelect: function(evt, t){
            
                window.A.removeResizers();
                window.A.selectedElement.setAttributeNS(null, 'stroke', 'black');
                window.A.selectedElement = null;
                
            }
            
        },
        
        
        /*
         *   RECTANGLE TOOL
         *
         */
        Rectangle: {
        
            oX: null,
            oY: null,
            object: null,
            counter: 0,
			
            init: function(e, options, t){
            
                /* START */
                if (this.Tools.Rectangle.object == null) {
                    this.Tools.Rectangle.Start(e, t ? t : this, options);
                }
                /* STOP */
                else {
                    this.Tools.Rectangle.Stop(e, t ? t : this);
                }
                
            },
            
            Start: function(e, t, options){
            	
				window.A.States.previous = window.A.svg2json();					
				
                t.Tools.Rectangle.oX = e.clientX;
                t.Tools.Rectangle.oY = e.clientY;
                
                t.Tools.Rectangle.object = t.SVG.createElement('rect', {
					id: 'rectangle-'+t.Tools.Rectangle.counter,
                    x: e.clientX,
                    y: e.clientY,
                    width: 0,
                    height: 0,
                    'fill': 'white',
                    'stroke-width': 2,
                    'stroke': 'black',
                    'eName': Language.getString('element.names.rect')
                }, 'objectGroup');
                
				t.Tools.Rectangle.counter++;
				
                InformationBox.update(Tpl.get('IB_AT_RECT_DRAWING', {
                    'width': 0,
                    'height': 0
                }));
                InformationBox.show();
                
            },
            
            Drawing: function(e){
            
                if (this.Tools.Rectangle.object != null) {
                
                
                    var width = Math.abs(this.Tools.Rectangle.oX - e.clientX);
                    var height = Math.abs(this.Tools.Rectangle.oY - e.clientY);
                    
                    if (e.clientX > this.Tools.Rectangle.oX) {
                        var nX = this.Tools.Rectangle.oX;
                    }
                    else {
                        var nX = e.clientX;
                    }
                    
                    if (e.clientY > this.Tools.Rectangle.oY) {
                        var nY = this.Tools.Rectangle.oY;
                    }
                    else {
                        var nY = e.clientY;
                    }
                    
                    
                    var eWidth = window.A.calcRatio(width);
                    var eHeight = window.A.calcRatio(height);
                    
                    
                    /*
                     *   Alkalamzás
                     */
                    this.SVG.changeElement(this.Tools.Rectangle.object, {
                        x: nX,
                        y: nY,
                        width: width,
                        height: height,
                        'eWidth': eWidth,
                        'eHeight': eHeight
                    });
                    
                    
                    InformationBox.update(eWidth, 'span.width');
                    InformationBox.update(eHeight, 'span.height');
                    
                }
                
            },
            
            Stop: function(e, t){
            
                this.eventSelectRectangle = this.Select;
                this.object.addEventListener('mousedown', this.eventSelectRectangle, false);
                
                this.eventDrag = window.A.SVG.Drag_n_Drop.Drag;
                //this.eventDrop = window.A.SVG.Drag_n_Drop.Drop;				
                this.object.addEventListener('mousedown', this.eventDrag, false);
                
                //this.object.addEventListener('mouseup', this.eventDrop, false);			
                
                this.object.addEventListener('mouseover', this.onOver, false);
                this.object.addEventListener('mouseout', this.onOut, false);
                
                /*
                 window.A.SVG.changeElement(this.object,{
                 transform : 'rotate(20)'
                 });
                 */
                this.object = null;
                
                InformationBox.hide();
                InformationBox.update('');
                
                
            },
            
            Abort: function(){
            
            
            
            },
            
            onOver: function(){
                if (window.A.selectedTool == null) {
                    window.A.SVG.changeElement(this, {
                        stroke: 'blue'
                    });
                    window.A.SVG.Resizer.addSizers(this);
                }
            },
            
            onOut: function(){
                if (this != window.A.SVG.Drag_n_Drop.object &&
                this != window.A.selectedElement) /* EMIATT VAN HOGY BERAGAD A HOVER */ {
                    window.A.SVG.unselectElement();
                    window.A.SVG.Resizer.removeSizers();
                }
            },
            
            Select: function(evt, t){
            
                if (window.A.selectedTool == null) {
                    if (window.A.selectedElement) {
                        window.A.selectedElement.setAttributeNS(null, 'stroke', 'black');
                        window.A.SVG.Resizer.removeSizers();
                    }
                    
                    window.A.selectedElement = evt.target;
                    evt.target.setAttributeNS(null, 'stroke', 'blue');
                    
                    window.A.SVG.Resizer.addSizers(evt.target);                                       
                    
                }
                
            },
            
            unSelect: function(evt, t){
            
                window.A.removeResizers();
                window.A.selectedElement.setAttribudow.A.selectedElement.setAttributeNS(null, 'stroke', 'black');
                window.A.selectedElement = null;
                
            }
            
        },
		
		
		/*
         *   COMPASS TOOL
         *
         */
		
        Compass: {
        
            oX: null,
            oY: null,
			dAngle : null,
            object: null,
			counter: 0,
            
            init: function(e, options, t){
            
                /* START */
                if (this.Tools.Compass.object == null) {
                    this.Tools.Compass.Start(e, t ? t : this, options);
                }
                /* STOP */
                else {
                    this.Tools.Compass.Stop(e, t ? t : this);
                }
                
            },
            
            Start: function(e, t, options){            				
			
				window.A.States.previous = window.A.svg2json();	
				
                t.Tools.Compass.oX = e.clientX+32;
                t.Tools.Compass.oY = e.clientY+33;
                
				t.Tools.Compass.dAngle = Math.round( Math.AngleFromVectors( [t.Tools.Compass.oX,t.Tools.Compass.oY], [e.clientX,e.clientY] ) );
				
				if (!options) {
					t.Tools.Compass.object = t.SVG.createElement('image', {
						id: 'compass-'+t.Tools.Compass.counter,
						x: e.clientX,
						y: e.clientY,
						width: '64px',
						height: '66px',
						'xlink:href': 'templates/default/images/_objects/compass.png'
					}, 'objectGroup');
				} else {
					t.Tools.Compass.object = options.target;
				}
				
				t.Tools.Compass.counter++;				                                					
                
            },
            
            Drawing: function(e){
            
			
                if (this.Tools.Compass.object != null) {
                                
					var angle = Math.round( Math.AngleFromVectors( [this.Tools.Compass.oX,this.Tools.Compass.oY], [e.clientX,e.clientY] ) ) - this.Tools.Compass.dAngle;
					
                    /*
                     *   Alkalamzás
                     */
                    this.SVG.changeElement(this.Tools.Compass.object, {
                        'transform' : "rotate("+(-angle)+","+this.Tools.Compass.oX+","+this.Tools.Compass.oY+")"
                    });

                    
                }
                
            },
            
            Stop: function(e, t){
            
                this.eventSelectRectangle = this.Select;
                this.object.addEventListener('mousedown', this.eventSelectRectangle, false);
                
                this.eventDrag = window.A.SVG.Drag_n_Drop.Drag;			
                this.object.addEventListener('mousedown', this.eventDrag, false);                                			
                
                this.object.addEventListener('mouseover', this.onOver, false);
                this.object.addEventListener('mouseout', this.onOut, false);
                
				
                /*
                 window.A.SVG.changeElement(this.object,{
                 transform : 'rotate(20)'
                 });
                 */
                this.object = null;
                
                InformationBox.hide();
                InformationBox.update('');
                
                
            },
			
            Abort: function(){
            
            
            
            },
            
            onOver: function(){
                if (window.A.selectedTool == null) {
                    window.A.SVG.changeElement(this, {
                        stroke: 'blue'
                    });
                    window.A.SVG.Resizer.addSizers(this);
                }
            },
            
            onOut: function(){
                if (this != window.A.SVG.Drag_n_Drop.object &&
                this != window.A.selectedElement) /* EMIATT VAN HOGY BERAGAD A HOVER */ {
                    window.A.SVG.changeElement(this, {
                        stroke: 'black'
                    });
                    window.A.SVG.Resizer.removeSizers();
                }
            },
            
            Select: function(evt, t){
            
                if (window.A.selectedTool == null) {
                    if (window.A.selectedElement) {
                        window.A.SVG.unselectElement();
                        window.A.SVG.Resizer.removeSizers();
                    }
                    
                    window.A.selectedElement = evt.target;
                    evt.target.setAttributeNS(null, 'stroke', 'blue');
                    
                    window.A.SVG.Resizer.addSizers(evt.target);
                  
                }
                
            },
            
            unSelect: function(evt, t){
            
                window.A.removeResizers();
                window.A.selectedElement.setAttributeNS(null, 'stroke', 'black');
                window.A.selectedElement = null;
                
            }
            
        },
		
        
        /*
         *   TEXT TOOL
         *   @ ...
         *
         */
        Text: {
        
			ref_object: null,
            objectDiv: null,
            objectTextarea: null,
            counter: 0,
			
            init: function(e, options){
            
                /* START */
                if (this.Tools.Text.object == null) {
                    this.Tools.Text.Start(e, this, options);
                }
                /* STOP */
                else {
                    this.Tools.Text.Stop(e, this);
                }
                
            },
            
            Start: function(e, t, ref_obj){
            	
				window.A.States.previous = window.A.svg2json();	
				
				var t_left = $('object').offsetLeft;
				var t_top = $('object').offsetTop;
				
				if( !ref_obj )
				{
					var area_top = e.clientY + t_top;
					var area_left = e.clientX + t_left;
					var div_top = e.clientY + t_top;
					var div_left = e.clientX + t_left + 40;
				}
				else 
				{
					t.Tools.Text.ref_object = ref_obj;
										
					var area_top = parseInt(ref_obj.getAttribute('y')) + t_top - 17;
					var area_left = parseInt(ref_obj.getAttribute('x')) + t_left - 5;
					var div_top = parseInt(ref_obj.getAttribute('y')) + t_top;
					var div_left = parseInt(ref_obj.getAttribute('x')) + t_left;
					
				}
			
                var tArea = new Element('textarea', {
                    'id': 'tempTextArea',
                    'class': 'textObject'
                }).setStyle({
                    top: area_top + 'px',
                    left: area_left + 'px',
                    width: '1px'
                }).update('');
                
                var tDiv = new Element('div', {
                    'id': 'tempTextDiv',
                    'class': 'textObject'
                }).setStyle({
                    top: div_top + 'px',
                    left: div_left + 'px',
                    display: 'none'
                }).update('');
                
                $(document.body).insert(tArea);
                $(document.body).insert(tDiv);
                
                $('tempTextArea').focus();	
				
				if (ref_obj) {
					$('tempTextArea').update(ref_obj.childNodes[0].nodeValue);
					window.A.Tools.Text.ref_object.childNodes[0].nodeValue = '';					
					t.Tools.Text.Edit();
				}
                
                window.A.eventTextEdit = t.Tools.Text.Edit;
                window.A.eventTextEditStop = t.Tools.Text.Stop;
                
                $('tempTextArea').observe('keyup', window.A.eventTextEdit);
                $('tempTextArea').observe('blur', window.A.eventTextEditStop);
                
            },
            
            
            Edit: function(e){
				
				$('tempTextDiv').update($('tempTextArea').value);
				$('tempTextArea').setStyle({
					width: ($('tempTextDiv').getDimensions().width + 4) + 'px'
				});
				
            },
			
			
			reEdit : function(e)
			{
				if (window.A.selectedTool == null) {
					window.A.Tools.Text.Start(e, window.A, e.target);
				}
			}.bind(this),
			            
            
            Stop: function(e){
            	
				var t_left = $('object').offsetLeft;
				var t_top = $('object').offsetTop;
				
                $('tempTextArea').stopObserving('keyup', window.A.eventTextEdit);
                $('tempTextArea').stopObserving('blur', window.A.eventTextEditStop);
                $('tempTextArea').setStyle({
                    border: 0
                });
                
				
				if( !window.A.Tools.Text.ref_object ){
									
					var SVG_Text = window.A.SVG.createElement('text',{
						'id' : 'textobject-'+window.A.Tools.Text.counter,
						'class' : 'text',
						'font-family' : 'Verdana',
						'font-size' : '12px',
						'font-weight' : 'bold',
						'x' : $('tempTextArea').positionedOffset().left - t_left + 5,
						'y' : $('tempTextArea').positionedOffset().top - t_top + 17
					}, 'textGroup');
					
					window.A.Tools.Text.counter++;
					
					var textNode = window.A.SVG.document.createTextNode( $('tempTextArea').value );												
					SVG_Text.appendChild( textNode );								
					
					// EVENT-ek
					window.A.eventDrag = window.A.SVG.Drag_n_Drop.Drag;
					SVG_Text.addEventListener('mousedown',window.A.eventDrag,false);
					
					window.A.eventOver = window.A.Tools.Text.onOver;
					SVG_Text.addEventListener('mouseover',window.A.eventOver,false);
					
					window.A.eventOut = window.A.Tools.Text.onOut;
					SVG_Text.addEventListener('mouseout',window.A.eventOut,false);
					
					window.A.eventEdit = window.A.Tools.Text.reEdit;
					SVG_Text.addEventListener('dblclick',window.A.eventEdit,false);
					
					window.A.eventSelectText = window.A.Tools.Text.Select;
                	SVG_Text.addEventListener('mousedown', window.A.eventSelectText, false);
					
				} else {
					
					window.A.Tools.Text.ref_object.childNodes[0].nodeValue = $('tempTextArea').value;					
					
				}
        		
				window.A.Tools.Text.ref_object = null;
				$('tempTextDiv').remove();
                $('tempTextArea').remove();								
              
            },
			
			onOver: function(){
                if (window.A.selectedTool == null) {
                    window.A.SVG.body.setAttribute('cursor','move');
                }
            },
            
            onOut: function(){
                if (this != window.A.SVG.Drag_n_Drop.object &&
                this != window.A.selectedElement) /* EMIATT VAN HOGY BERAGAD A HOVER */ {
                  window.A.SVG.body.setAttribute('cursor','default');
                }
            },
			
			Select : function(evt)
			{
				if (window.A.selectedTool == null) {
					if (window.A.selectedElement) {
						window.A.SVG.unselectElement();
						window.A.SVG.Resizer.removeSizers();
					}
					window.A.selectedElement = evt.target;
				}
			}
            
        },
        
		
		
		/*
         *   ROTATE TOOL
         *   @ ...
         *
         */
        Rotate: {
        
			object : null,
            dAngle : null,
			oX : null,
			oY: null,
            
            init: function(e){
            
                /* START */
                if (this.Tools.Rotate.object == null) {
                    this.Tools.Rotate.Start(e, this);
                }
                /* STOP */
                else {
                    this.Tools.Rotate.Stop(e, this);
                }
                
            },
            
            Start: function(e, t){
            	
				if(e.target.getAttribute('id') && e.target.getAttribute('id').search('door') > -1 ){
					return false;
				}
				
				window.A.States.previous = window.A.svg2json();	
				
				if (!e.target.parentNode) {
					var second = true;
				}
				else {
				
					if (e.target.parentNode.getAttribute('class') != 'l_rect' &&
						e.target.parentNode.getAttribute('class') != 'u_rect') {
						t.Tools.Rotate.object = e.target;
						
						t.Tools.Rotate.oX = parseInt(e.target.getAttribute('x')) + Math.round(parseInt(e.target.getAttribute('width')) / 2);
						t.Tools.Rotate.oY = parseInt(e.target.getAttribute('y')) + Math.round(parseInt(e.target.getAttribute('height')) / 2);
					}
					else {
						var second = true;
					}
				}
				
				if(second) {
					t.Tools.Rotate.object = e.target.parentNode;
					
					var BOX = t.Tools.Rotate.object.getBBox();
					
					t.Tools.Rotate.oX = parseInt(e.target.parentNode.childNodes[0].getAttribute('x')) + Math.round(BOX.width/2);
					t.Tools.Rotate.oY = parseInt(e.target.parentNode.childNodes[1].getAttribute('y')) + Math.round(BOX.height/2);
				}
				////////////console.log( e.target );
				////////////console.log( t.Tools.Rotate.oX + ',' + t.Tools.Rotate.oY );
				
				t.SVG.Resizer.removeSizers();
				
				t.Tools.Rotate.dAngle = Math.round( Math.AngleFromVectors( [t.Tools.Rotate.oX,t.Tools.Rotate.oY], [e.clientX,e.clientY] ) );
				
                
            },
            
            
            doRotate: function(e){
				
				if( this.Tools.Rotate.object != null )
				{
					
					var angle = Math.round( Math.AngleFromVectors( [this.Tools.Rotate.oX,this.Tools.Rotate.oY], [e.clientX,e.clientY] ) ) - this.Tools.Rotate.dAngle;
				
                    /*
                     *   Alkalmazás
                     */
                    this.SVG.changeElement(this.Tools.Rotate.object, {
                        'transform' : "rotate("+(-angle)+","+this.Tools.Rotate.oX+","+this.Tools.Rotate.oY+")"
                    });
					
				}
				
            },
            
            Stop: function(e){
            
				window.A.Tools.Rotate.object = null;	
					
            }
            
        },
		
		
        /*
         *  "I" RECTANGLE TOOL (OBJECT)
         *
         */
        i_Rect: {
        
            oX: null,
            oY: null,
            object: null,
			counter:0,
            
            init: function(e, options, t){
            
                /* START */
                if (this.Tools.i_Rect.object == null) {
                    this.Tools.i_Rect.Start(e, t ? t : this, options);
                }
                /* STOP */
                else {
                    this.Tools.i_Rect.Stop(e, t ? t : this);
                }
                
            },
            
            Start: function(e, t, options){
            	
				window.A.States.previous = window.A.svg2json();	
				
                t.Tools.i_Rect.oX = e.clientX;
                t.Tools.i_Rect.oY = e.clientY;
                
                t.Tools.i_Rect.object = t.SVG.createElement('rect', {
					id: 'i_rect-'+t.Tools.i_Rect.counter,
                    x: e.clientX,
                    y: e.clientY,
                    width: 0,
                    height: 0,
                    'fill': 'rgb(240,240,210)',
                    'stroke-width': 1,
                    'stroke': 'black',
                    'eName': Language.getString('element.names.i_pult'),
                    'type': 'i_rect'
                }, 'objectGroup');
                
				t.Tools.i_Rect.counter++;
				
                InformationBox.update(Tpl.get('IB_AT_RECT_DRAWING', {
                    'width': 0,
                    'height': 0
                }));
                InformationBox.show();
                
            },
            
            Drawing: function(e){
            
                if (this.Tools.i_Rect.object != null) {
                
                
                    var width = Math.abs(this.Tools.i_Rect.oX - e.clientX);
                    var height = Math.abs(this.Tools.i_Rect.oY - e.clientY);
                    
                    
                    if (width > height) {
                    
                        var nH = 20;
                        var nW = width;
                        var eWidth = window.A.calcRatio(width);
                        var eHeight = window.A.calcRatio(16.2)
                        
                        
                        if (e.clientX > this.Tools.i_Rect.oX) {
                            var nX = this.Tools.i_Rect.oX;
                        }
                        else {
                            var nX = e.clientX;
                        }
                        
                        var nY = this.Tools.i_Rect.oY;
                        
                    }
                    else {
                    
                        var nH = height;
                        var nW = 20;
                        var eWidth = window.A.calcRatio(16.2);
                        var eHeight = window.A.calcRatio(height)
                        
                        
                        if (e.clientY > this.Tools.i_Rect.oY) {
                            var nY = this.Tools.i_Rect.oY;
                        }
                        else {
                            var nY = e.clientY;
                        }
                        
                        var nX = this.Tools.i_Rect.oX;
                        
                    }
                    
                    
                    /*
                     *   Alkalamzás
                     */
                    this.SVG.changeElement(this.Tools.i_Rect.object, {
                        x: nX,
                        y: nY,
                        width: nW,
                        height: nH,
                        'eWidth': eWidth,
                        'eHeight': eHeight
                    });
                    
                    
                    InformationBox.update(eWidth, 'span.width');
                    InformationBox.update(eHeight, 'span.height');
                    
                }
                
            },
            
            Stop: function(e, t){
            
                this.eventSelectRectangle = this.Select;
                this.object.addEventListener('mousedown', this.eventSelectRectangle, false);
                
                this.eventDrag = window.A.SVG.Drag_n_Drop.Drag;
                //this.eventDrop = window.A.SVG.Drag_n_Drop.Drop;				
                this.object.addEventListener('mousedown', this.eventDrag, false);
                
                //this.object.addEventListener('mouseup', this.eventDrop, false);			
                
                this.object.addEventListener('mouseover', this.onOver, false);
                this.object.addEventListener('mouseout', this.onOut, false);
                
                this.object = null;
                
                InformationBox.hide();
                InformationBox.update('');
                
                
            },
            
            Abort: function(){
            
            
            
            },
            
            onOver: function(){
                if (window.A.selectedTool == null) {
                    window.A.SVG.changeElement(this, {
                        stroke: 'blue'
                    });
                    window.A.SVG.Resizer.addSizers(this);
                }
            },
            
            onOut: function(){
                if (this != window.A.SVG.Drag_n_Drop.object &&
                this != window.A.selectedElement) /* EMIATT VAN HOGY BERAGAD A HOVER */ {
                    window.A.SVG.changeElement(this, {
                        stroke: 'black'
                    });
                    window.A.SVG.Resizer.removeSizers();
                }
            },
            
            Select: function(evt, t){

                if (window.A.selectedTool == null) {
                    if (window.A.selectedElement) {
                        window.A.SVG.unselectElement();
                        window.A.SVG.Resizer.removeSizers();
                    }
                    
                    window.A.selectedElement = evt.target;
                    evt.target.setAttributeNS(null, 'stroke', 'blue');
                    
                    window.A.SVG.Resizer.addSizers(evt.target);
                    
					if ( !$SVG_Trans(evt.target).rotate ) {
						window.A.SVG.Resizer.addSizers(evt.target);
					}
					
                    
                }
                
            },
            
            unSelect: function(evt, t){
            
                window.A.removeResizers();
                window.A.SVG.unselectElement();
                window.A.selectedElement = null;
                
            }
            
        },
		
		
		
		/*
         *  "L" RECTANGLE TOOL (OBJECT)
         *
         */
        l_Rect: {
        
            oX: null,
            oY: null,
            object: null,
			counter: 0,
            
            init: function(e, options, t){
            
                /* START */
                if (this.Tools.l_Rect.object == null) {
                    this.Tools.l_Rect.Start(e, t ? t : this, options);
                }
                /* STOP /
                else {
                    this.Tools.l_Rect.Stop(e, t ? t : this);
                }*/
                				
            },
            
            Start: function(e, t, options){
				
				window.A.States.previous = window.A.svg2json();	
				
                t.Tools.l_Rect.oX = e.clientX;
                t.Tools.l_Rect.oY = e.clientY;
                
                t.Tools.l_Rect.object = t.SVG.createElement('g', {
                   	id: 'l_rect-'+t.Tools.l_Rect.counter,
					'class' : 'l_rect'
                }, 'objectGroup');

			   	var CHILD_1 = t.SVG.createElement('rect', {
                   	x: e.clientX,
					y: e.clientY,
					width: 26,
					height : 20,
					'fill': 'rgb(240,240,210)',
					'stroke-width' : 1,
					'stroke' : 'black'
                }, t.Tools.l_Rect.object);
				
				var CHILD_2 = t.SVG.createElement('rect', {
                   	x: e.clientX,
					y: e.clientY,
					width: 20,
					height : 26,
					'fill': 'rgb(240,240,210)',
					'stroke-width' : 1,
					'stroke' : 'black'
                }, t.Tools.l_Rect.object);
				
				var CHILD_3 = t.SVG.createElement('rect', {
                   	x: e.clientX+19,
					y: e.clientY+1,
					width: 3,
					height : 18,
					'fill': 'rgb(240,240,210)',
                }, t.Tools.l_Rect.object);
				
				 t.Tools.l_Rect.Stop(e, t ? t : this);
				 
            },
            
            Drawing: function(e){
            
                if (this.Tools.l_Rect.object != null) {
                /*					
					this.SVG.changeElement(this.Tools.l_Rect.object.childNodes[0],{
						x: e.clientX,
						y: e.clientY
					});
					
					this.SVG.changeElement(this.Tools.l_Rect.object.childNodes[1],{
						x: e.clientX,
						y: e.clientY
					});
					
					this.SVG.changeElement(this.Tools.l_Rect.object.childNodes[2],{
						x: e.clientX+15,
						y: e.clientY+1
					});
                  */  
                }
                
            },
            
            Stop: function(e, t){
            
                this.eventSelectRectangle = this.Select;
                this.object.addEventListener('mousedown', this.eventSelectRectangle, false);
                
                this.eventDrag = window.A.SVG.Drag_n_Drop.Drag;
                this.object.addEventListener('mousedown', this.eventDrag, false);
                
                //this.object.addEventListener('mouseup', this.eventDrop, false);			
                
               	//this.object.addEventListener('mouseover', this.onOver, false);
                //this.object.addEventListener('mouseout', this.onOut, false);
                
                this.object = null;
                
                
            },
            
            Abort: function(){
            
            
            
            },
            
            onOver: function(){
                if (window.A.selectedTool == null) {
                    window.A.SVG.changeElement(this, {
                        stroke: 'blue'
                    });
                    window.A.SVG.Resizer.addSizers(this);
                }
            },
            
            onOut: function(){
                if (this != window.A.SVG.Drag_n_Drop.object &&
                this != window.A.selectedElement) /* EMIATT VAN HOGY BERAGAD A HOVER */ {
                    window.A.SVG.changeElement(this, {
                        stroke: 'black'
                    });
                    window.A.SVG.Resizer.removeSizers();
                }
            },
            
            Select: function(evt, t){
            
                if (window.A.selectedTool == null) {
					
                    if (window.A.selectedElement) {
                        window.A.SVG.unselectElement();
                        window.A.SVG.Resizer.removeSizers();
                    }
					
                    window.A.selectedElement = evt.target.parentNode;
					
                    evt.target.parentNode.childNodes[0].setAttributeNS(null, 'stroke', 'blue');
					evt.target.parentNode.childNodes[1].setAttributeNS(null, 'stroke', 'blue');
                    
                    if ( !$SVG_Trans(evt.target).rotate ) {
						window.A.SVG.Resizer.addSizers(evt.target);
					}
                    
                }
                
            },
            
            unSelect: function(evt, t){
            
                window.A.removeResizers();
                window.A.SVG.unselectElement();
                window.A.selectedElement = null;
                
            }
            
        },
		
		
		/*
         *  "U" RECTANGLE TOOL (OBJECT)
         *
         */
        u_Rect: {
        
            oX: null,
            oY: null,
            object: null,
			counter: 0,
            
            init: function(e, options, t){
            	
                /* START */
                if (this.Tools.u_Rect.object == null) {
                    this.Tools.u_Rect.Start(e, t ? t : this, options);
                }
                /* STOP /
                else {
                    this.Tools.l_Rect.Stop(e, t ? t : this);
                }*/
                				
            },
            
            Start: function(e, t, options){
				
				window.A.States.previous = window.A.svg2json();	
				
                t.Tools.u_Rect.oX = e.clientX;
                t.Tools.u_Rect.oY = e.clientY;
                
                t.Tools.u_Rect.object = t.SVG.createElement('g', {
                   	id: 'u_rect-'+t.Tools.u_Rect.counter,
					'class' : 'u_rect'
                }, 'objectGroup');
				
				t.Tools.u_Rect.counter++;
               
			   	var CHILD_1 = t.SVG.createElement('rect', {
                   	x: e.clientX,
					y: e.clientY,
					width: 20,
					height : 25,
					'fill': 'rgb(240,240,210)',
					'stroke-width' : 1,
					'stroke' : 'black'
                }, t.Tools.u_Rect.object);
				
				var CHILD_2 = t.SVG.createElement('rect', {
                   	x: e.clientX+31,
					y: e.clientY,
					width: 20,
					height : 25,
					'fill': 'rgb(240,240,210)',
					'stroke-width' : 1,
					'stroke' : 'black'
                }, t.Tools.u_Rect.object);
				
				var CHILD_3 = t.SVG.createElement('rect', {
                   	x: e.clientX,
					y: e.clientY,
					width: 51,
					height : 20,
					'fill': 'rgb(240,240,210)',
					'stroke-width' : 1,
					'stroke' : 'black'
                }, t.Tools.u_Rect.object);
				
				var CHILD_4 = t.SVG.createElement('rect', {
                   	x: e.clientX,
					y: e.clientY+19,
					width: 20,
					height : 3,
					'fill': 'rgb(240,240,210)',
                }, t.Tools.u_Rect.object);
				
				var CHILD_5 = t.SVG.createElement('rect', {
                   	x: e.clientX+31,
					y: e.clientY+19,
					width: 20,
					height : 3,
					'fill': 'rgb(240,240,210)',
                }, t.Tools.u_Rect.object);				
				
				
				t.Tools.u_Rect.Stop(e, t ? t : this);
				 
            },
            
            Drawing: function(e){
            
                if (this.Tools.u_Rect.object != null) {
                /*					
					this.SVG.changeElement(this.Tools.l_Rect.object.childNodes[0],{
						x: e.clientX,
						y: e.clientY
					});
					
					this.SVG.changeElement(this.Tools.l_Rect.object.childNodes[1],{
						x: e.clientX,
						y: e.clientY
					});
					
					this.SVG.changeElement(this.Tools.l_Rect.object.childNodes[2],{
						x: e.clientX+15,
						y: e.clientY+1
					});
                  */  
                }
                
            },
            
            Stop: function(e, t){
            
                this.eventSelectRectangle = this.Select;
                this.object.addEventListener('mousedown', this.eventSelectRectangle, false);
                
                this.eventDrag = window.A.SVG.Drag_n_Drop.Drag;
                this.object.addEventListener('mousedown', this.eventDrag, false);
                
                //this.object.addEventListener('mouseup', this.eventDrop, false);			
                
               	//this.object.addEventListener('mouseover', this.onOver, false);
                //this.object.addEventListener('mouseout', this.onOut, false);
                
                this.object = null;
                
                
            },
            
            Abort: function(){
            
            
            
            },
            
            onOver: function(){
                if (window.A.selectedTool == null) {
                    window.A.SVG.changeElement(this, {
                        stroke: 'blue'
                    });
                   // window.A.SVG.Resizer.addSizers(this);
                }
            },
            
            onOut: function(){
                if (this != window.A.SVG.Drag_n_Drop.object &&
                this != window.A.selectedElement) /* EMIATT VAN HOGY BERAGAD A HOVER */ {
                    window.A.SVG.changeElement(this, {
                        stroke: 'black'
                    });
                    window.A.SVG.Resizer.removeSizers();
                }
            },
            
            Select: function(evt, t){
            
                if (window.A.selectedTool == null) {
					
                    if (window.A.selectedElement) {
                        window.A.SVG.unselectElement();
                        window.A.SVG.Resizer.removeSizers();
                    }
					
                    window.A.selectedElement = evt.target.parentNode;
					
                    //evt.target.parentNode.childNodes[0].setAttributeNS(null, 'stroke', 'blue');
					//evt.target.parentNode.childNodes[1].setAttributeNS(null, 'stroke', 'blue');
   					
					//////console.log( window.A.selectedElement.getAttribute('transform') );
					
					if ( !window.A.selectedElement.getAttribute('transform') ) {
						////console.log('addsizers');
						window.A.SVG.Resizer.addSizers(evt.target);
					}
                   
                }
                
            },
            
            unSelect: function(evt, t){
            
                window.A.removeResizers();
                window.A.SVG.unselectElement();
                window.A.selectedElement = null;
                
            }
            
        }        
    
    },
    
    
    /* 
     *  OBJEKTUMOK
     *
     */
    Objects: {
    
        obj: null,
        counter : 0,
		
        Create: function(e, object, data){
        	
			window.A.States.previous = window.A.svg2json();
			
            this.obj = window.A.SVG.createElement('image', {
				id : 'object-'+this.counter,
                x: e.clientX - data.size[0],
                y: e.clientY - data.size[1],
                width: data.size[0] + 'px',
                height: data.size[1] + 'px',
                'xlink:href': 'templates/default/images/_objects/' + object + '.png',
                'oType': data.type,
                'eType': object,
                'title': Language.getString('element.names.' + object),
                'size': data.size,
                'stroke': 'blue',
                'stroke-width': 1
            }, 'objectGroup');
            this.counter++;
        },
        
        Move: function(e){
            var size = window.A.Objects.obj.getAttribute('size').split(',');
            
            window.A.SVG.changeElement(window.A.Objects.obj, {
                x: e.clientX - parseInt(size[0]),
                y: e.clientY - parseInt(size[1])
            });
        },
        
        Drop: function(){
        
            this.SVG.body.removeEventListener('click', this.canvasEventClick, false);
            this.SVG.body.removeEventListener('dblclick', this.canvasEventDoubleClick, false);
            this.SVG.body.removeEventListener('mousemove', this.canvasEventMouseMove, false);
            this.SVG.body.removeEventListener('mousedown', this.canvasEventMouseDown, false);
            this.SVG.body.removeEventListener('mouseup', this.canvasEventMouseUp, false);
            
            this.eventDrag = window.A.SVG.Drag_n_Drop.Drag;
            window.A.Objects.obj.addEventListener('mousedown', this.eventDrag, false);
            
            this.eventSelect = window.A.Objects.selectThis;
            window.A.Objects.obj.addEventListener('mousedown', this.eventSelect, false);
			
			this.eventMouseOver = window.A.Objects.onOver;
            window.A.Objects.obj.addEventListener('mouseover', this.eventMouseOver, false);
			
			this.eventMouseOut = window.A.Objects.onOut;
            window.A.Objects.obj.addEventListener('mouseout', this.eventMouseOut, false);
            
			var e = { clientX : window.mouseX+$('object').cumulativeOffset().left, clientY : window.mouseY+$('object').cumulativeOffset().top };
								
			Toolbar.select($('movetool'));
			ToolTip.set(e,'cursor');
			window.A.selectTool('cursor');			
			
        },
		
		onOver : function()
		{
			 window.A.SVG.body.setAttribute("cursor", "move");
		},
		
		onOut : function()
		{
			 window.A.SVG.body.setAttribute("cursor", "default");
		},
        
        selectThis: function(evt, o){
        
            if (window.A.selectedTool == null) {
                if (window.A.selectedElement) {
                    window.A.SVG.unselectElement();
                    window.A.SVG.Resizer.removeSizers();
                }
                
                window.A.selectedElement = o ? o : evt.target;
                
                /*
                window.A.SVG.createElement('rect', {
                    x: parseInt(window.A.selectedElement.getAttribute('x')) - 2,
                    y: parseInt(window.A.selectedElement.getAttribute('y')) - 2,
                    width: parseInt(window.A.selectedElement.getAttribute('width')) + 4,
                    height: parseInt(window.A.selectedElement.getAttribute('height')) + 4,
                    fill: 'none',
                    'stroke': 'blue',
                    'stroke-width': '1px'
                }, 'resizeGroup');
                
                
                var buildedHTML = Tpl.get('IB_ELEMENT_RECT_INFORMATION', {
                    name: window.A.selectedElement.getAttribute('eName'),
                    width: window.A.calcRatio(parseInt(window.A.selectedElement.getAttribute('width'))),
                    height: window.A.calcRatio(parseInt(window.A.selectedElement.getAttribute('height')))
                });
                
                InformationBox.update(buildedHTML);
                InformationBox.show();
                */
            }
            
        }
        
        
    },
    
    
    selectObject: function(event, object, data){
    
        this.selectedTool = 'Objects';
        this.Objects.Create(event, object, data);
        
        /* CANVAS-ra beállított eseménykezelők törlése */
        this.SVG.body.removeEventListener('click', this.canvasEventClick, false);
        this.SVG.body.removeEventListener('dblclick', this.canvasEventDoubleClick, false);
        this.SVG.body.removeEventListener('mousemove', this.canvasEventMouseMove, false);
        this.SVG.body.removeEventListener('mousedown', this.canvasEventMouseDown, false);
        this.SVG.body.removeEventListener('mouseup', this.canvasEventMouseUp, false);
        
        /* ÚJ ESEMÉNYKEZELŐK BEÁLLÍTÁSA */
        this.canvasEventClick = this.Objects.Drop.bindAsEventListener(this);
        this.canvasEventDoubleClick = function(){};
        this.canvasEventMouseMove = this.Objects.Move.bindAsEventListener(this);
        this.canvasEventMouseDown = function(){};
        this.canvasEventMouseUp = function(){};
        
        this.SVG.body.addEventListener('click', this.canvasEventClick, false);
        this.SVG.body.addEventListener('dblclick', this.canvasEventDoubleClick, false);
        this.SVG.body.addEventListener('mousemove', this.canvasEventMouseMove, false);
        this.SVG.body.addEventListener('mousedown', this.canvasEventMouseDown, false);
        this.SVG.body.addEventListener('mouseup', this.canvasEventMouseUp, false);
        
    },
    
    /* 
     *   ESZKÖZ KIVÁLASZTÁS
     *   @ ...
     *
     */
    selectTool: function(tool){
    
    
        /*
         * 	   Előző eseménykezelők leállítása
         */
        this.SVG.body.removeEventListener('click', this.canvasEventClick, false);
        this.SVG.body.removeEventListener('dblclick', this.canvasEventDoubleClick, false);
        this.SVG.body.removeEventListener('mousemove', this.canvasEventMouseMove, false);
        this.SVG.body.removeEventListener('mousedown', this.canvasEventMouseDown, false);
        this.SVG.body.removeEventListener('mouseup', this.canvasEventMouseUp, false);
        
        /*
         * 	   Eszköz kiválasztása, eseménykezelők beállítása
         */
        switch (tool) {
        
            /*
             * 	   VONAL
             */
            case 'line':
            case 'thin_line':
                
                this.selectedTool = 'Line';
                this.Tools.Line.type = tool;
                
                this.canvasEventClick = this.Tools.Line.init.bindAsEventListener(this);
                this.canvasEventDoubleClick = function(){};
                this.canvasEventMouseMove = this.Tools.Line.Drawing.bindAsEventListener(this);
                this.canvasEventMouseDown = function(){};
                this.canvasEventMouseUp = function(){};
                
                break;
                
                
            /*
             * 	   TÉGLALAP (NÉGYZET)
             */
            case 'rectangle':
                
                this.selectedTool = 'Rectangle';
                
                this.canvasEventClick = this.Tools.Rectangle.init.bindAsEventListener(this);
                this.canvasEventDoubleClick = function(){};
                this.canvasEventMouseMove = this.Tools.Rectangle.Drawing.bindAsEventListener(this);
                this.canvasEventMouseDown = function(){};
                this.canvasEventMouseUp = function(){};
                
                break;
                
            /*
             * 	   ABLAK
             */
            case 'window':
                
                this.selectedTool = 'Window';
                
                this.canvasEventClick = this.Tools.Window.init.bindAsEventListener(this);
                this.canvasEventDoubleClick = function(){};
                this.canvasEventMouseMove = this.Tools.Window.Drawing.bindAsEventListener(this);
                this.canvasEventMouseDown = function(){};
                this.canvasEventMouseUp = function(){};                
                
                break;
                
            /*
             * 	   AJTÓ(K)
             */
            case 'right_door':
			case 'left_door':
			case 'double_door':
                
                this.selectedTool = 'Door';
                this.Tools.Door.type = tool;
				
                this.canvasEventClick = this.Tools.Door.init.bindAsEventListener(this);
                this.canvasEventDoubleClick = function(){};
                this.canvasEventMouseMove = this.Tools.Door.onMove.bindAsEventListener(this);
                this.canvasEventMouseDown = function(){};
                this.canvasEventMouseUp = function(){};
                
                break;
                
            /*
             * 	   "I" konyhapult
             */
            case 'i_rect':
                
                this.selectedTool = 'I Rectangle';
                
                this.canvasEventClick = this.Tools.i_Rect.init.bindAsEventListener(this);
                this.canvasEventDoubleClick = function(){};
                this.canvasEventMouseMove = this.Tools.i_Rect.Drawing.bindAsEventListener(this);
                this.canvasEventMouseDown = function(){};
                this.canvasEventMouseUp = function(){};
                
                break;
                
				
            /*
             * 	   "L" konyhapult
             */
            case 'l_rect':
                
                this.selectedTool = 'L Rectangle';
                
                this.canvasEventClick = this.Tools.l_Rect.init.bindAsEventListener(this);
                this.canvasEventDoubleClick = function(){};
                this.canvasEventMouseMove = this.Tools.l_Rect.Drawing.bindAsEventListener(this);
                this.canvasEventMouseDown = function(){};
                this.canvasEventMouseUp = function(){};
                
				//this.Tools.l_Rect.init();
				
                break; 
			
			/*
             * 	   "U" konyhapult
             */
            case 'u_rect':
                
                this.selectedTool = 'U Rectangle';
                
                this.canvasEventClick = this.Tools.u_Rect.init.bindAsEventListener(this);
                this.canvasEventDoubleClick = function(){};
                this.canvasEventMouseMove = this.Tools.u_Rect.Drawing.bindAsEventListener(this);
                this.canvasEventMouseDown = function(){};
                this.canvasEventMouseUp = function(){};
                
				//this.Tools.l_Rect.init();
				
                break;    
               
		 	/*
             * 	   Iránytű
             */
            case 'compass':
                
                this.selectedTool = 'Compass';
                
                this.canvasEventClick = this.Tools.Compass.init.bindAsEventListener(this);
                this.canvasEventDoubleClick = function(){};
                this.canvasEventMouseMove = this.Tools.Compass.Drawing.bindAsEventListener(this);
                this.canvasEventMouseDown = function(){};
                this.canvasEventMouseUp = function(){};
                
                break; 
			
			/*
             * 	   Forgatás
             */
            case 'rotate':
                
                this.selectedTool = 'Rotate';
                
                this.canvasEventClick = this.Tools.Rotate.init.bindAsEventListener(this);
                this.canvasEventDoubleClick = function(){};
                this.canvasEventMouseMove = this.Tools.Rotate.doRotate.bindAsEventListener(this);
                this.canvasEventMouseDown = function(){};
                this.canvasEventMouseUp = function(){};
                
                break; 
				
            /*
             * 	   SZÖVEG
             */
            case 'text':
                
                this.selectedTool = 'Text';
                
                this.canvasEventClick = this.Tools.Text.init.bindAsEventListener(this);
                this.canvasEventDoubleClick = function(){
                };
                this.canvasEventMouseMove = function(){
                }; //this.Tools.Line.Drawing.bindAsEventListener(this);					
                this.canvasEventMouseDown = function(){
                };
                this.canvasEventMouseUp = function(){
                };
                
                break;
                
                
            /*
             * 	   ALAPÉRTELMEZETT
             */
            default:
                
                this.selectedTool = null;
                
                this.canvasEventClick = function(){
                };
                this.canvasEventDoubleClick = function(){
                };
                this.canvasEventMouseMove = function(){
                };
                this.canvasEventMouseDown = function(){
                };
                this.canvasEventMouseUp = function(){
                };
                
                break;
        }
        
        
        /*
         * 	   Eseménykezelők alkalmazása a tempCanvas-ra
         */
        this.SVG.body.addEventListener('click', this.canvasEventClick, false);
        this.SVG.body.addEventListener('dblclick', this.canvasEventDoubleClick, false);
        this.SVG.body.addEventListener('mousemove', this.canvasEventMouseMove, false);
        this.SVG.body.addEventListener('mousedown', this.canvasEventMouseDown, false);
        this.SVG.body.addEventListener('mouseup', this.canvasEventMouseUp, false);
        
        
    },
    
    
    /* 
     *   GYORSBILLENTYŰK
     *   @ ...
     *
     */
    Hotkeys: {
    
        aKey: '',
        array: Array(),
        specialKeys: [{
            code: 8,
            key: 'BACKSPACE',
            state: false
        }, {
            code: 9,
            key: 'TAB',
            state: false
        }, {
            code: 13,
            key: 'RETURN',
            state: false
        }, {
            code: 27,
            key: 'ESC',
            state: false
        }, {
            code: 37,
            key: 'LEFT',
            state: false
        }, {
            code: 38,
            key: 'UP',
            state: false
        }, {
            code: 39,
            key: 'RIGHT',
            state: false
        }, {
            code: 40,
            key: 'DOWN',
            state: false
        }, {
            code: 46,
            key: 'DELETE',
            state: false
        }, {
            code: 36,
            key: 'HOME',
            state: false
        }, {
            code: 35,
            key: 'END',
            state: false
        }, {
            code: 33,
            key: 'PAGEUP',
            state: false
        }, {
            code: 34,
            key: 'PAGEDOWN',
            state: false
        }, {
            code: 32,
            key: 'SPACE',
            state: false
        }, {
            code: 17,
            key: 'CTRL',
            state: false
        }, {
            code: 18,
            key: 'ALT',
            state: false
        }, {
            code: 16,
            key: 'SHIFT',
            state: false
        }, {
            code: 20,
            key: 'CAPSLOCK',
            state: false
        }, {
            code: 45,
            key: 'INSERT',
            state: false
        }, {
            code: 19,
            key: 'PAUSE',
            state: false
        }, {
            code: 112,
            key: 'F1',
            state: false
        }, // Minden böngészőben foglalt
        {
            code: 113,
            key: 'F2',
            state: false
        }, // Foglalt: Opera
        {
            code: 114,
            key: 'F3',
            state: false
        }, // Foglalt: Opera
        {
            code: 115,
            key: 'F4',
            state: false
        }, // Foglalt: Opera
        {
            code: 116,
            key: 'F5',
            state: false
        }, // Minden böngészőben foglalt
        {
            code: 117,
            key: 'F6',
            state: false
        }, {
            code: 118,
            key: 'F7',
            state: false
        }, // Foglalt: FireFox, Opera
        {
            code: 119,
            key: 'F8',
            state: false
        }, // Foglalt: Opera
        {
            code: 120,
            key: 'F9',
            state: false
        }, {
            code: 121,
            key: 'F10',
            state: false
        }, {
            code: 122,
            key: 'F11',
            state: false
        },// Minden böngészőben foglalt
        {
            code: 123,
            key: 'F12',
            state: false
        } // (Foglalt: FireFox - csak ha a FireBug kiterjesztés fent van)
]        ,
        
        init: function(A){
        
            window.A.SVG.body.addEventListener('keydown', this.CheckKey, false);
            window.A.SVG.body.addEventListener('keyup', this.DeleteKey, false);
            
        },
        
        Add: function(h){
            if (!h.statement) {
                h.statement = function(){
                    return true;
                }
            }
            window.A.Hotkeys.array[window.A.Hotkeys.array.length] = {
                hotkey: h.hotkey.toUpperCase(),
                action: h.action,
                statement: h.statement,
                enableInputs: h.enableInputs
            }
        },
        
        DeleteKey: function(event){
            var KEY = window.A.Hotkeys.GetKey(event.keyCode);
            var newString = '';
            window.A.Hotkeys.aKey.split('+').each(function(K){
                if (K != KEY) {
                    if (!newString) {
                        newString = K;
                    }
                    else {
                        newString += '+' + K;
                    }
                }
            });
            window.A.Hotkeys.aKey = newString;
        },
        
        GetKey: function(keyCode){
            var key;
            window.A.Hotkeys.specialKeys.each(function(k){
                if (keyCode == k.code) {
                    key = k.key;
                    k.state = true;
                }
            });
            if (!key) {
                key = String.fromCharCode(keyCode);
            }
            if (!key) {
                key = false;
            }
            return key;
        },
        
        Execute: function(hk){
            if (hk.statement()) {
                switch (typeof(hk.action)) {
                    case 'function':
                        hk.action();
                    case 'string':
                        window.eval(hk.action);
                }
            }
        },
        
        CheckKey: function(event){
        
        
            var KEY = window.A.Hotkeys.GetKey(event.keyCode);
            
            if (KEY == 'F1') {
                event.preventDefault(); // Csak FF alatt 
            }
            
            /* Ellenorzés, hogy a lenyomott billentyu szerepel-e már az 'aKey' string-ben */
            if (!window.A.Hotkeys.aKey) {
                window.A.Hotkeys.aKey = KEY;
            }
            else {
                var e = false;
                window.A.Hotkeys.aKey.split('+').each(function(K){
                    if (K == KEY) {
                        e = true;
                    }
                });
                if (!e) {
                    window.A.Hotkeys.aKey += '+' + KEY
                }
            }
            
            /* Ellenorzes, hogy a lenyomott billentyukombináció egy gyorsbillentyu-e. 
             Ha igen, végrehajtódik a hozzárendelt muvelet */
            window.A.Hotkeys.array.each(function(hk){
                var eqal = true;
                hk.hotkey.split('+').each(function(K){
                    var e = false;
                    /* Ha a lenyomott billentyuk száma különbözik a gyorsbillentyu elemeinek
                     számánál, akkor a gyorsbillentyu ellenorzése végre sem hajtódik */
                    if (window.A.Hotkeys.aKey.split('+').length == hk.hotkey.split('+').length) {
                        window.A.Hotkeys.aKey.split('+').each(function(A){
                            if (A == K) {
                                e = true;
                            }
                        });
                    }
                    if (!e) {
                        eqal = false;
                    }
                });
                if (eqal) {
                    window.A.Hotkeys.Execute(hk);
                }
            });
            
            return false;
        }
        
    }

});
