current_mouse_y = 0;
current_mouse_x = 0;
current_offset_x = 0;
current_offset_y = 0;
CT_drag_flag = false;

function start_drag(name){
	store_offset(name);
	CT_drag_flag = name;
	//alert(name);
	//document.onmousemove = current_mouse_pos();
	//document.getElementById(name).addEventListener("mousemove", current_mouse_pos, true);
}

function stop_drag(){
	CT_drag_flag = false;
	//alert('stop');
	current_offset_x = 0;
	current_offset_y = 0;
}

function store_offset(name){
	pos = get_layer_pos(name);
	//alert(pos['x'] + ' ' + pos['y']);
	current_offset_x = pos['x'] - current_mouse_x;
	current_offset_y = pos['y'] - current_mouse_y;
}

NN = document.layers;
IE = document.all;
N6 = false;
if(!IE){N6 = document.getElementById;}


function CT_find_obj(n, d){
	var p,i,x;  
	
	if(!d){
		d = document; 
	}

/*	
	if((p = n.indexOf("?") ) > 0 && parent.frames.length){
		d = parent.frames[n.substring(p+1)].document; n = n.substring(0,p);
	}
*/	
	if(!(x = d[n]) && d.all){ 
		x = d.all[n]; 
	}
	
	if(!(x = d[n]) && d.getElementById){ 
		x = d.getElementById(n);
	}
	
	for (i=0; !x && i < d.forms.length; i++){ 
		x = d.forms[i][n];
	}
	
	for(i=0; !x && d.layers && i< d.layers.length; i++){ 
		x = CT_find_obj(n,d.layers[i].document);
	}
	
	return x;
}


function CT_set_attribute(id,node,name,value){
	obj = CT_find_obj(id);
	d = document;

	if(d.layers){
		string = 'obj.' + name + ' = "' + value + '"'; 
		eval(string);
	}
	else if(d.all || d.getElementById) {
		string = 'obj.' + node + '.' + name + ' = "' + value + '"'; 
		eval(string);
	}	
}

function CT_get_attribute(id,node,name){
	obj = CT_find_obj(id);
	d = document;

	if(d.layers){
		string = 'val = obj.' + name; 
		eval(string);
	}
	else if(d.all || d.getElementById) {
		string = 'val = obj.' + node + '.' + name; 
		eval(string);
	}
	return val;	
}

function CT_show_layer(name,mode){
	d = document;
	if(d.layers){
		t = (mode)?'show':'hide';
		CT_set_attribute(name,null,'visibility',t);	
	}
	else{
		t = (mode)?'visible':'hidden';
		CT_set_attribute(name,'style','visibility',t);	
	}
}

function CT_move_layer(name,x,y){
	CT_set_attribute(name,'style','top',y);	
	CT_set_attribute(name,'style','left',x);	
}


function get_layer_pos(name){
	tmp = new Array();
	
	tmp['x'] =  CT_get_attribute(name,'style','left');
	tmp['y'] =  CT_get_attribute(name,'style','top');

	tmp['x'] = parseInt(tmp['x']); 
	tmp['y'] = parseInt(tmp['y']); 
	
	return (tmp);
}

/*
capturen der aktuellen mausposition
*/
//mausepos 
function current_mouse_pos(capt){
	if (document.layers) {
		current_mouse_x = capt.pageX; 
		current_mouse_y = capt.pageY;
	}
	else if (window.netscape) {
		current_mouse_x = capt.pageX; 
		current_mouse_y = capt.pageY;
	}
	else if (document.all) {
		current_mouse_x = window.event.x + document.body.scrollLeft;
		current_mouse_y = window.event.y + document.body.scrollTop;
	}
	
	//gibts was zu ziehen ??
	if(CT_drag_flag != false){ 
		x = current_mouse_x + current_offset_x;
		y = current_mouse_y + current_offset_y;
		CT_move_layer(CT_drag_flag,x,y);	
	}
}
//eventhandler für netscape einschalten
if(!document.all){
	window.captureEvents(Event.MOUSEMOVE);
	window.onmousemove = current_mouse_pos;
}
else{
	handler = '<scri'+'pt type="text/javas'+'cript" for="document" event="onmousemove" language="JavaScript">'
	+ 'current_mouse_pos();'
	+ '</scr' + 'ipt>';
	document.write(handler);
}


