function scalePicWidth(id,imgid){
	var bild = new Image();
		bild.src='/inc/bild.galerie.php?'+id;
				width=0;
		height=0;
		max_width=180;
		bild.onload =function(){
			var scale=new Array();
			if(bild.width > max_width)
				scale=scaleImage(max_width,bild.height,bild.width,bild.height);
			else{
				scale[0]=bild.width;
				scale[1]=bild.height;
			}
			$(imgid).width=''+scale[0]+'';
			$(imgid).height=''+scale[1]+'';
		}
}	
		
function scaleImage(max_w,max_h,x1,y1){
      scaleSize=new Array();
      skalh=max_w/x1;
      skalv=max_h/y1;
      if (skalh < skalv) {
            y0=Math.round((max_h-y1*skalh)/2);
            x0=0;
            xw=max_w;
            yw=Math.round(y1*skalh);
            scaleSize[0]=xw;
			scaleSize[1]=yw;
      } else if (skalh > skalv) {
            x0=Math.round((max_w-x1*skalv)/2);
            y0=0;
            xw=Math.round(x1*skalv);
            yw=max_h;
            scaleSize[0]=xw;
			scaleSize[1]=yw;
            
      }else{
            scaleSize[0]=max_w;
			scaleSize[1]=max_h
		}
            
      return scaleSize;
}

function toggleSubNodes(t, id,deep,child){
	var vis= $(id).visible();
	var container = $(id);
	var newdeep=parseInt(deep)+1;
	var type=0;
	var flag=0;
	
	if (deep==0){
		$$('#'+id+' .deep_'+newdeep).each(
			function(e){
				if($(e).visible()){
					$(e).hide();
					t.src='/data/button_plus_small.gif';
				}else{
					$(e).show();
					t.src='/data/button_minus_small.gif';
					type=1;
				}
			}
		);
	}else{
		var aktDiv = $(t).up('div');
		var a = $(aktDiv).nextSiblings();
		$(a).each(function(e){
			if($(e).hasClassName('deep_'+newdeep) ){
				flag=1;
			}
			
			if($(e).hasClassName('deep_'+deep)){
				throw $break;
			}
			
			if (flag==1 && $(e).hasClassName('deep_'+newdeep)){
				if($(e).visible()){
					$(e).hide();
					t.src='/data/button_plus_small.gif';
				}else{
					$(e).show();
					t.src='/data/button_minus_small.gif';
					type=1;
				}
			}
		});
	
	}
	
	
	
	/*
	$$('#'+id+' .deep_'+newdeep).each(
		function(e){
			if($(e).visible()){
				$(e).hide();
				t.src='/data/button_plus_small.gif';
			}else{
				$(e).show();
				t.src='/data/button_minus_small.gif';
				type=1;
			}
		}
	);
	*/
	
	//now close all other deeps > deep+1
	if(type==0){
		var newdeep=parseInt(deep)+2;
		$$('#'+id+' > .deep_'+newdeep).each(function(e){
			$(e).hide();
		});
	}
}
