// JavaScript Document

	function tooltip_open( info ) {
		$('tooltip').style.left = ( mouseX + 10 ) + 'px';
		$('tooltip').style.top = ( mouseY + 10 ) + 'px';
		$('tooltip').innerHTML = info;
		$('tooltip').style.display = '';
	}
	
	function tooltip_close( ) {
		$('tooltip').style.display = 'none';
	}

	function alf_display_image( url ) {
	
		var img = new Image();
		alf_loading();
		
			$('light_content').innerHTML = '<img onClick="alf_light_close()" style="cursor:pointer;  border:1px solid #000000;" src="' + url + '" id="light_image" onLoad="alf_light()" onError="alf_loading_hide(); alert(\'Bild nicht verf&uuml;gbar\')" />';
		/*img.src = url;
		
		img.onload = function() {
			alf_loading_stop();
			$('light_content').innerHTML = '<img onClick="alf_light_close()" style="cursor:pointer;  border:1px solid #000000;" src="' + url + '" id="light_image" />';
			alf_light();
		}
		
		img.onerror = function() {
			alf_loading_stop();
			alert('Bild nicht verf&uuml;gbar.');
		}*/
		
	}
	
	function alf_loading() {
		alf_blackbox();
		$('alf_loading').style.display='';
	}
	
	function alf_loading_hide() {
		alf_blackbox_hide();
		$('alf_loading').style.display='none';
	}
	
	function alf_blackbox() {
		$('alf_blackbox').style.opacity = '0.5';
		$('alf_blackbox').style.filter = 'alpha(opacity=50)';
		$('alf_blackbox').style.display = '';
	}
	
	function alf_blackbox_hide() {
		$('alf_blackbox').style.display = 'none';
	}

	var light_box_open = false;

	function alf_light() {
		
		if( light_box_open ) {
			return false;
		}
		
		if( window.hide_inputs ) {
			hide_inputs();
		}
		
		$( 'light_button_back' ).style.display = 'none';
		light_box_open = true;
	
		alf_loading_hide();
		alf_blackbox();
		
		$('light_center').style.display = '';
		
		$('alf_lightbox').style.display = 'none';
		$('alf_lightbox').style.opacity = '1';
		$('alf_lightbox').style.filter = 'alpha(opacity=100)';
		
		$('alf_lightbox').style.left = '-' + ( $('alf_lightbox').getWidth() / 2 ) + 'px';
		//$('alf_lightbox').style.top = '-' + ( $('alf_lightbox').getHeight() / 2 ) + 'px';
		//$('light_header').style.height = '0px';
		
		new Effect.Grow('alf_lightbox');
		setTimeout( 'alf_show_light_header()', 1000 );
		setTimeout( 'alf_show_light_content()', 2000 );

	}
	
	function alf_show_light_content() {
		new Effect.Opacity('light_content', { from: 0, to: 1 });
	}
	
	function alf_show_light_header() {
		new Effect.Opacity('light_header', { from: 0, to: 1 });
		//new Effect.Opacity('light_feeter', { from: 0, to: 1 });
	}
	
	function alf_light_close() {
	
		new Effect.Opacity('light_header', { from: 1, to: 0 });
		//new Effect.Opacity('light_feeter', { from: 1, to: 0 });
		new Effect.Opacity('light_content', { from: 1, to: 0 });
		new Effect.Opacity('alf_lightbox', { from: 1, to: 0 });
		new Effect.Opacity('alf_blackbox', { from: 0.5, to: 0 });
		setTimeout( "$('alf_blackbox').style.display='none'", 1000 );
		setTimeout( "$('light_center').style.display='none'", 1000 );
	
		if( window.show_inputs ) {
			show_inputs();
		}
		light_box_open = false;
	
	}
	
	var int_pos = 0;
	var ziel = 0;
	var scroll_dif = 80;
	function scroll_to( num, dif, start ) {
	
		scroll_div = dif;
		ziel = start + ( num - 5 ) * scroll_div;
		if( ziel < 0 ) {
			ziel = 0;
		}
		
		$('selected_img').style.left = ( num * scroll_div ) + 'px';
		
		if( scrolltimer == '' ) {
			scrolltimer = setInterval( "scroll_it()", 50 );
		}
	
	}
	
	var scrolltimer = '';
	function scroll_it() {
		
		if( int_pos == ziel ) {
		
			clearInterval( scrolltimer );
			scrolltimer = '';
		
		}
		
		var dif = ziel - int_pos;
		
		if( Math.abs( dif ) < 2 ) {
			int_pos = ziel;
		} else {
			int_pos = int_pos + Math.floor( dif / 8 );
		}
		
		if( document.getElementById( 'gallery_list_driver' ) )
			document.getElementById( 'gallery_list_driver' ).style.left = - int_pos + 'px';
	
	}

/**********************************************/

	var objDrag = null;     // Element, über dem Maus bewegt wurde
	var objDrag2 = null;     // sizer
	var objDrag2b = null;     // main
	var objDrag3 = null;     // Pic

  var mouseX   = 0;       // X-Koordinate der Maus
  var mouseY   = 0;       // Y-Koordinate der Maus

  var offX = 0;           // X-Offset der Maus zur linken oberen Ecke des Elements
  var offY = 0;           // Y-Offset der Maus zur linken oberen Ecke des Elements

  // Browserweiche
  IE = document.all&&!window.opera;
  DOM = document.getElementById&&!IE;

  // Initialisierungs-Funktion
  function init(){
    // Initialisierung der Überwachung der Events
    document.onmousemove = doDrag;  // Bei Mausbewegung die Fkt. doDrag aufrufen
    document.onmouseup = stopDrag;  // Bei Loslassen der Maustaste die Fkt. stopDrag aufrufen
  }
  
  var normX;
  var normY;
  var stateX;
  function init_drag3( width, height ) {
	  normX = width;
	  normY = height;
	  stateX = normX;
  }

	function init_drag2( obj, objm ) {
		obj.style.left = ( parseInt( objm.style.width ) - 3 ) + 'px';
		obj.style.top = '-3px';
	}

	var maxWidth;
	var maxHeight;
	var curWidth;
	var curHeight;
  // Wird aufgerufen, wenn die Maus über einer Box gedrückt wird
  function startDrag( objElem, maxW, maxH, curW, curH ) {
    // Objekt der globalen Variabel zuweisen -> hierdurch wird Bewegung möglich
    objDrag = objElem;

    // Offsets im zu bewegenden Element ermitteln
    offX = mouseX - objDrag.clientLeft - parseInt(objDrag.style.left);
    offY = mouseY - objDrag.clientTop - parseInt(objDrag.style.top);
	 
	maxWidth = maxW;
	maxHeight = maxH;
	curWidth = curW;
	curHeight = curH;
	
  }
  var startX;
  var startY;
  var maxX = 810;
  function startDrag2(objElem,objMain) {
    // Objekt der globalen Variabel zuweisen -> hierdurch wird Bewegung möglich
    objDrag2 = objElem;
    objDrag2m = objMain;

    // Offsets im zu bewegenden Element ermitteln
	 offX = mouseX - objDrag2.clientLeft - parseInt(objDrag2.style.left);
    offY = mouseY - objDrag2.clientTop - 1;
	 startX = parseInt(objMain.style.width);
	 startY = parseInt(objMain.style.height);
  }
  
  function startDrag3( objPic ) {
    // Objekt der globalen Variabel zuweisen -> hierdurch wird Bewegung möglich
    objDrag3 = objPic;

    // Offsets im zu bewegenden Element ermitteln
	 offX = mouseX; // - objPic.clientLeft;
  }

  // Wird ausgeführt, wenn die Maus bewegt wird
  function doDrag(ereignis) {
    // Aktuelle Mauskoordinaten bei Mausbewegung ermitteln
    mouseX = (IE) ? window.event.clientX : ereignis.pageX;
    mouseY = (IE) ? window.event.clientY : ereignis.pageY;

    // Wurde die Maus über einem Element gedrück, erfolgt eine Bewegung
    if (objDrag != null) {
      // Element neue Koordinaten zuweisen
		divX = mouseX - offX;
		divY = mouseY - offY;
		if( divX < ( curWidth * -1 ) + 8 ) {
			divX = ( curWidth * -1 ) + 8;
		} else if( divX > maxWidth - 8 ) {
			divX = maxWidth - 8;
		}
		if( divY < ( curHeight * -1 ) + 8 ) {
			divY = ( curHeight * -1 ) + 8;
		} else if( divY > maxHeight - 8 ) {
			divY = maxHeight - 8;
		}
      objDrag.style.left = divX + "px";
      objDrag.style.top = divY + "px";
		//$('header_footer').innerHTML = divX + ' - '+ divY;
      // Position in Statusleiste ausgeben
      //window.status = "Box-Position: " + objDrag.style.left + ", " + objDrag.style.top;
    }
    // Wurde die Maus über einem Element gedrück, erfolgt eine Bewegung
    if (objDrag2 != null) {
		 newX = (mouseX - offX);
		 newY = startY + (mouseY - offY);
		 if( newX < 10 ) newX = 10;
		 if( newY < 10 ) newY = 10;
		 if( newX > maxX ) newX = maxX;
      // Element neue Koordinaten zuweisen
      objDrag2.style.left = newX - 3 + "px";
      //objDrag2.style.top = (mouseY - offY - 2) + "px";
		objDrag2m.style.width = newX + "px";
		objDrag2m.style.height = newY + "px";

      // Position in Statusleiste ausgeben
      //window.status = "Box-Position: " + objDrag.style.left + ", " + objDrag.style.top;
    }
    if (objDrag3 != null) {
		 newX = stateX + Math.round( mouseX - offX );
		 
		 if( newX < 10 ) newX = 10;
		 if( newX > 1500 ) newX = 1500;
		 
		 newY = Math.round( newX / normX * normY );
      // Element neue Koordinaten zuweisen
      //objDrag2.style.top = (mouseY - offY - 2) + "px";
		objDrag3.width = newX;
		objDrag3.height = newY;

      // Position in Statusleiste ausgeben
      //$('header_footer').innerHTML = newX + ' = ' + stateX + " + Math.round( " +mouseX+ " - " +offX+ " );";
    }
  }

  // Wird ausgeführt, wenn die Maustaste losgelassen wird
  function stopDrag(ereignis) {
    // Objekt löschen -> beim Bewegen der Maus wird Element nicht mehr verschoben
	 if (objDrag != null) {
		 
		 nleft = parseInt( objDrag.style.left );
		 ntop = parseInt( objDrag.style.top );
		 
		if( nleft > 0 && nleft < 8 ) {
      	objDrag.style.left = "0px";
		} else {
			nleftDiv = curWidth - maxWidth + nleft;
			if( nleftDiv < 0 && nleftDiv > -8 ) {
      		objDrag.style.left = ( maxWidth - curWidth ) + "px";
			}
		}
		if( ntop > 0 && ntop < 8 ) {
      	objDrag.style.top = "0px";
		} else {
			ntopDiv = curHeight - maxHeight + ntop;
			if( ntopDiv < 0 && ntopDiv > -8 ) {
      		objDrag.style.top = ( maxHeight - curHeight ) + "px";
			}
		}
	 }
	 
	  if (objDrag3 != null) {
	 		stateX = stateX + Math.round( (mouseX - offX) / 1 );
	  }
    objDrag = null;
    objDrag2 = null;
    objDrag3 = null;
  }
