/* Interner Bereich */
function removeFileInp(element){
	jQuery(element).parent().remove();
}

function refreshTab(tab){
	jQuery(tab).click();
}

jQuery(document).ready(function(){
	jQuery(".tab").click(function(){
		jQuery(".tab").attr("class", "tab");
		jQuery(".tabcontent").hide();
		var id = jQuery(this).attr('rel');
		
		jQuery(this).attr("class", "tab active");
		jQuery("#"+id).show();
	});	
});

function changeCat(element){
	var value = jQuery('.jsinp', jQuery(element)).val();
	var win = window.confirm('Kategorie wirklich ändern?');
	if(win==true){
		return true;
	} else {
		return false;
	}
}

function removeCat(element){
	var value = jQuery('.jsinp', jQuery(element)).val();
	var win = window.confirm('Kategorie: "'+value+'" wirklich löschen?');
	if(win==true){
		return true;
	} else {
		return false;
	}
}





( function ( $ ) {
	
	jQuery(document).ready( function () {
		
		var lagns = '.lagintern';
		
		$( 'td div.useradminform' ).hide();
		$( 'td div.useradminform.edited' ).show();
		
		$( 'tr.useradminrow td' ).click( function () {
			$form = $( 'div.useradminform', $( this ).parent().next() );
			
			$( 'div.useradminform', $( this ).parent().parent() ).not( $form ).slideUp( 'slow' );
			
			$form.slideToggle( 'fast' );
		} );
		

		$( 'div.internfile' ).each( function () {
			var $this = $( this );
			
			var $btn_download = $( 'a.btn_download', $this ); 
			var $title = $( '.data .title', $this ); 
			var $edit = $( 'a.edit', $this ); 
			var $abortedit = $( 'a.abortedit', $this ); 
			var $readmore = $( 'a.readmore', $this ); 
			var $readless = $( 'a.readless', $this ); 
			var $description = $( '.data .description', $this ); 
			var $inputs = $( '.inputs', $this ); 
			var $inputbuttons = $( '.inputbuttons', $this ); 
			var $tags = $( '.data .tags', $this ); 
			
			$edit.click( function () {
				if ($description.height() > 0 ) {
					$description.stop().slideUp( function () {
						$description.hide().css('height','auto');
					} );
				}
				if ($tags.height() > 0 ) {
					$tags.stop().slideUp( function () {
						$tags.hide().css('height','auto');
					} );
				}
				$inputs.stop().hide().css('height','auto');
				$readmore.hide();
				$readless.hide();
				$edit.hide();
				$abortedit.show();
				
				$inputs.slideDown( function () {
					$inputbuttons.show();
				} );
				
				$this.addClass( 'edit' );
				
				return false;
			} );
			
			$abortedit.click( function () {
				$tags.stop().hide().css('height','auto');
				$inputs.stop().show().css('height','auto');
				$readmore.show();
				$readless.hide();
				$edit.show();
				$abortedit.hide();
				
				$tags.slideDown();
				
				$inputbuttons.hide();
				$inputs.slideUp();
				
				$this.removeClass( 'edit' );
				
				return false;
			} );
			
			$readmore.click( function () {
				$description.stop().hide().css('height','auto');
				$readmore.hide();
				$readless.show();
				
				$description.slideDown();

				$this.addClass( 'open' );
				return false;
			} );
			
			$readless.click( function () {
				$description.stop().show().css('height','auto');
				$readmore.show();
				$readless.hide();
				
				$description.slideUp();
				
				$this.removeClass( 'open' );
				return false;
			} );
			
			$title.css('cursor','pointer').click( function ( event ) {
				location.href = $btn_download.attr( 'href' );
			} );
			
			
			var $internfile = $this;
			
			$( '.inputline.info-filename', $inputs ).each( function () {
				var $this = $( this );
				var $panel = $( document.createElement( 'div' ) ).css( {
					'position'	: 'absolute',
					'right'		: '-15px',
					'z-index'	: '1000'
				} );
				var $icon = $( document.createElement( 'div' ) ).css( {
				} ).html( '[?]' );
				var $text = $( document.createElement( 'div' ) ).css( {
					'display'	: 'none',
					'padding'	: '3px 15px',
					'background': '#ffc',
					'border'	: '1px solid #000'
				} ).html( 'Der <b>Dateiname</b> ist relativ wichtig, da dieser beim Download bestimmt, wie die Datei auf dem Zielcomputer heißt.' );
				
				$panel.append($icon, $text);
				$this.append( $panel );
				
				$panel.mouseenter( function () {
					$icon.hide();
					$text.stop().hide().css('opacity','1');
					$text.fadeIn( 'fast' );
				} );
				$panel.mouseleave( function () {
					$text.stop().css('opacity','1');
					$text.fadeOut( 'fast', function() { $icon.show(); } );
				} );
			} );
			
			$( '.inputline.info-filetype', $inputs ).each( function () {
				var $this = $( this );
				var $panel = $( document.createElement( 'div' ) ).css( {
					'position'	: 'absolute',
					'right'		: '-15px',
					'z-index'	: '1000',
				} );
				var $icon = $( document.createElement( 'div' ) ).css( {
				} ).html( '[?]' );
				var $text = $( document.createElement( 'div' ) ).css( {
					'display'	: 'none',
					'padding'	: '3px 15px',
					'background': '#ffc',
					'border'	: '1px solid #000'
				} ).html( 'Der <b>Dateityp</b> muss <i>unbedingt</i> angegeben werden, da sonst der Besucher die Datei ggf. nicht korrekt anzeigen kann.<br/>Zur Auswahl stehen aktuell diese Typen:<br/><a href="#" rel="txt">txt</a>, <a href="#" rel="html">html</a>, <a href="#" rel="jpg">jpg</a>, <a href="#" rel="bmp">bmp</a>, <a href="#" rel="png">png</a>, <a href="#" rel="svg">svg</a>, <a href="#" rel="pdf">pdf</a>, <a href="#" rel="doc">doc</a>, <a href="#" rel="xls">xls</a>, <a href="#" rel="rtf">rtf</a>, <a href="#" rel="mp3">mp3</a>, <a href="#" rel="wav">wav</a>, <a href="#" rel="mpeg">mpeg</a>, <a href="#" rel="mov">mov</a>, <a href="#" rel="zip">zip</a>, <a href="#" rel="odt">odt</a>' );
				
				$( 'a', $text ).click( function () {
					var $a = $( this );
					$( 'input', $this ).val( $a.attr( 'rel' ) );
					$panel.mouseleave();
					return false;
				} );
				
				$panel.append($icon, $text);
				$this.append( $panel );
				
				$panel.mouseenter( function () {
					$icon.hide();
					$text.stop().hide().css('opacity','1');
					$text.fadeIn( 'fast' );
				} );
				$panel.mouseleave( function () {
					$text.stop().css('opacity','1');
					$text.fadeOut( 'fast', function() { $icon.show(); } );
				} );
			} );
			
			$( '.inputline.info-filetitle', $inputs ).each( function () {
				var $this = $( this );
				var $panel = $( document.createElement( 'div' ) ).css( {
					'position'	: 'absolute',
					'right'		: '-15px',
					'z-index'	: '1000',
				} );
				var $icon = $( document.createElement( 'div' ) ).css( {
				} ).html( '[?]' );
				var $text = $( document.createElement( 'div' ) ).css( {
					'display'	: 'none',
					'padding'	: '3px 15px',
					'background': '#ffc',
					'border'	: '1px solid #000'
				} ).html( 'Der <b>Dateititel</b> ist optional. Er dient lediglich der besseren Les- und Auffindbarkeit. Häufig ist hat er den gleichen Wert wie der <a href="#" rel="filename">Dateiname</a>' );
				
				$( 'a', $text ).click( function () {
					var $a = $( this );
					if ( $a.attr( 'rel' ) != '' ) {
						$( 'input', $this ).val( $( '.'+$a.attr( 'rel' ), $internfile ).val() );
						$panel.mouseleave();
					}
					return false;
				} );
				
				$panel.append($icon, $text);
				$this.append( $panel );
				
				$panel.mouseenter( function () {
					$icon.hide();
					$text.stop().hide().css('opacity','1');
					$text.fadeIn( 'fast' );
				} );
				$panel.mouseleave( function () {
					$text.stop().css('opacity','1');
					$text.fadeOut( 'fast', function() { $icon.show(); } );
				} );
			} );
			
			
			$( '.inputline.info-fileposition', $inputs ).each( function () {
				var $this = $( this );
				var $panel = $( document.createElement( 'div' ) ).css( {
					'position'	: 'absolute',
					'right'		: '-15px',
					'z-index'	: '1000',
				} );
				var $icon = $( document.createElement( 'div' ) ).css( {
				} ).html( '[?]' );
				var $text = $( document.createElement( 'div' ) ).css( {
					'display'	: 'none',
					'padding'	: '3px 15px',
					'background': '#ffc',
					'border'	: '1px solid #000'
				} ).html( 'Die <b>Dateiposition</b> dient der Sortierung in der Ausgabereihenfolge der Dateien. Dateien mit höherem Positionswert erscheinen weiter vorn.' );
				
				$( 'a', $text ).click( function () {
					var $a = $( this );
					if ( $a.attr( 'rel' ) != '' ) {
						$( 'input', $this ).val( $( '.'+$a.attr( 'rel' ), $internfile ).val() );
						$panel.mouseleave();
					}
					return false;
				} );
				
				$panel.append($icon, $text);
				$this.append( $panel );
				
				$panel.mouseenter( function () {
					$icon.hide();
					$text.stop().hide().css('opacity','1');
					$text.fadeIn( 'fast' );
				} );
				$panel.mouseleave( function () {
					$text.stop().css('opacity','1');
					$text.fadeOut( 'fast', function() { $icon.show(); } );
				} );
			} );
			
			
			$( '.inputline.info-filekat', $inputs ).each( function () {
				var $this = $( this );
				var $panel = $( document.createElement( 'div' ) ).css( {
					'position'	: 'absolute',
					'right'		: '-15px',
					'z-index'	: '1000'
				} );
				var $icon = $( document.createElement( 'div' ) ).css( {
				} ).html( '[?]' );
				var $text = $( document.createElement( 'div' ) ).css( {
					'display'	: 'none',
					'padding'	: '3px 15px',
					'background': '#ffc',
					'border'	: '1px solid #000'
				} ).html( 'Die <b>Kategorien</b> einer Datei sind ein wesentliches Merkmal zur einfachen Verwaltung und einer sinnvollen Suche. Eine Datei kann keine, eine oder beliebig viele Kategorien haben. Die Mehrfachauswahl ist auf den meisten Systemen mit der Taste <i>STRG</i> möglich.' );
				
				$panel.append($icon, $text);
				$this.append( $panel );
				
				$panel.mouseenter( function () {
					$icon.hide();
					$text.stop().hide().css('opacity','1');
					$text.fadeIn( 'fast' );
				} );
				$panel.mouseleave( function () {
					$text.stop().css('opacity','1');
					$text.fadeOut( 'fast', function() { $icon.show(); } );
				} );
			} );
			
			
			
			$( '.inputline.info-filetext', $inputs ).each( function () {
				var $this = $( this );
				var $panel = $( document.createElement( 'div' ) ).css( {
					'position'	: 'absolute',
					'right'		: '-15px',
					'z-index'	: '1000'
				} );
				var $icon = $( document.createElement( 'div' ) ).css( {
				} ).html( '[?]' );
				var $text = $( document.createElement( 'div' ) ).css( {
					'display'	: 'none',
					'padding'	: '3px 15px',
					'background': '#ffc',
					'border'	: '1px solid #000'
				} ).html( 'Die <b>Beschreibung</b> einer Datei ist optional. Hier können für die Benutzer weiterführende Informationen hinterlegt werden. Wenn eine Beschreibung vorhanden ist, sehen die Benutzer den Link &raquo;mehr&laquo;, mit welchem diese Beschreibung angezeigt werden kann. In der normalen Ansicht, ist die Beschreibung ausgeblendet.' );
				
				$panel.append($icon, $text);
				$this.append( $panel );
				
				$panel.mouseenter( function () {
					$icon.hide();
					$text.stop().hide().css('opacity','1');
					$text.fadeIn( 'fast' );
				} );
				$panel.mouseleave( function () {
					$text.stop().css('opacity','1');
					$text.fadeOut( 'fast', function() { $icon.show(); } );
				} );
			} );
			
			
			$( '.inputline.info-filepath', $inputs ).each( function () {
				var $this = $( this );
				var $panel = $( document.createElement( 'div' ) ).css( {
					'position'	: 'absolute',
					'right'		: '-15px',
					'z-index'	: '1000'
				} );
				var $icon = $( document.createElement( 'div' ) ).css( {
				} ).html( '[?]' );
				var $text = $( document.createElement( 'div' ) ).css( {
					'display'	: 'none',
					'padding'	: '3px 15px',
					'background': '#ffc',
					'border'	: '1px solid #000'
				} ).html( 'Der <b>Speicherort</b> dient ist ein Hinweis darauf, wie die eigentliche Datei auf dem System heißt. Dieser Name kann erheblich vom Dateinamen abweichen. Anhand des Speicherortes kann man sichergehen, dass man mit anderen Programmen (z.B. via FTP) die richtige Datei bearbeitet.' );
				
				$panel.append($icon, $text);
				$this.append( $panel );
				
				$panel.mouseenter( function () {
					$icon.hide();
					$text.stop().hide().css('opacity','1');
					$text.fadeIn( 'fast' );
				} );
				$panel.mouseleave( function () {
					$text.stop().css('opacity','1');
					$text.fadeOut( 'fast', function() { $icon.show(); } );
				} );
			} );
			
			
			$( '.inputline.info-fileuser', $inputs ).each( function () {
				var $this = $( this );
				var $panel = $( document.createElement( 'div' ) ).css( {
					'position'	: 'absolute',
					'right'		: '-15px',
					'z-index'	: '1000'
				} );
				var $icon = $( document.createElement( 'div' ) ).css( {
				} ).html( '[?]' );
				var $text = $( document.createElement( 'div' ) ).css( {
					'display'	: 'none',
					'padding'	: '3px 15px',
					'background': '#ffc',
					'border'	: '1px solid #000'
				} ).html( 'Der <b>Benutzer</b> ist ein Hinweis darauf, wer diese Datei hochgeladen hat. Ist man nicht selbst dieser Benutzer, so kann man diesem über den Link eine E-Mail senden.' );
				
				$panel.append($icon, $text);
				$this.append( $panel );
				
				$panel.mouseenter( function () {
					$icon.hide();
					$text.stop().hide().css('opacity','1');
					$text.fadeIn( 'fast' );
				} );
				$panel.mouseleave( function () {
					$text.stop().css('opacity','1');
					$text.fadeOut( 'fast', function() { $icon.show(); } );
				} );
			} );
			
			
			$( '.remline', $this ).each( function () {
				var $rem = $( this );
				
				var $close = $( document.createElement( 'a' ) ).html('&times;').css( {
					'font-weight'		: 'bold',
					'color'				: '#aaa',
					'position'			: 'absolute',
					'right'				: '0px',
					'display'			: 'block',
					'padding'			: '2px',
					'border'			: '1px solid #aaa',
					'line-height'		: '12px',
					'width'				: '12px',
					'height'			: '12px',
					'cursor'			: 'pointer',
					'text-align'		: 'center',
					'text-decoration'	: 'none',
					'font-size'			: '17px'
				} ).attr( 'title', 'Meldung entfernen' ).click( function () {
					$rem.fadeOut( function () {
						$rem.remove();
					} );
				} );
				
				$rem.prepend( $close );
			} );
			
			
		} );

		
		
		$( '.uploadform' ).each( function () {
			var $form = $( this );
			
			
			
			
			$( '.inputline .info-uploadfiles', $form ).each( function () {
				var $this = $( this );
				var $panel = $( document.createElement( 'div' ) ).css( {
					'position'	: 'absolute',
					'right'		: '-15px',
					'z-index'	: '1000'
				} );
				var $icon = $( document.createElement( 'div' ) ).css( {
				} ).html( '[?]' );
				var $text = $( document.createElement( 'div' ) ).css( {
					'display'	: 'none',
					'padding'	: '3px 15px',
					'background': '#ffc',
					'border'	: '1px solid #000'
				} ).html( 'Wählen Sie hier die <b>Dateien</b>, welche hochgeladen werden sollen. Mit den Buttons <i>+1</i> und <i>+5</i> kann ein (oder fünf) Feld(er) zur Dateiübertragung hinzugefügt werden.<br/><br/>Überflüssige Felder können mit dem Schließen-Kreuz rechts entfernt werden.' );
				
				$panel.append($icon, $text);
				$this.prepend( $panel );
				
				$panel.mouseenter( function () {
					$icon.hide();
					$text.stop().hide().css('opacity','1');
					$text.fadeIn( 'fast' );
				} );
				$panel.mouseleave( function () {
					$text.stop().css('opacity','1');
					$text.fadeOut( 'fast', function() { $icon.show(); } );
				} );
			} );
			
			
			
			$( '.inputline .info-uploadkats', $form ).each( function () {
				var $this = $( this );
				var $panel = $( document.createElement( 'div' ) ).css( {
					'position'	: 'absolute',
					'right'		: '-15px',
					'z-index'	: '1000'
				} );
				var $icon = $( document.createElement( 'div' ) ).css( {
				} ).html( '[?]' );
				var $text = $( document.createElement( 'div' ) ).css( {
					'display'	: 'none',
					'padding'	: '3px 15px',
					'background': '#ffc',
					'border'	: '1px solid #000'
				} ).html( 'Die <b>Kategorien</b> einer Datei sind ein wesentliches Merkmal zur einfachen Verwaltung und einer sinnvollen Suche. Eine Datei kann keine, eine oder beliebig viele Kategorien haben. Die Mehrfachauswahl ist auf den meisten Systemen mit der Taste <i>STRG</i> möglich.<br/><br/>Wählen Sie hier für alle zu übertragenden Dateien die Kategorien aus. Die Auswahl kann anschließend geändert/bearbeitet werden.' );
				
				$panel.append($icon, $text);
				$this.prepend( $panel );
				
				$panel.mouseenter( function () {
					$icon.hide();
					$text.stop().hide().css('opacity','1');
					$text.fadeIn( 'fast' );
				} );
				$panel.mouseleave( function () {
					$text.stop().css('opacity','1');
					$text.fadeOut( 'fast', function() { $icon.show(); } );
				} );
			} );
			
			
			
			
			$( '.remove', $form ).html('&times;').css( {
				'font-weight'		: 'bold',
				'color'				: '#aaa',
				'position'			: 'absolute',
				'top'				: '0px',
				'right'				: '0px',
				'display'			: 'block',
				'padding'			: '2px',
				'border'			: '1px solid #aaa',
				'line-height'		: '12px',
				'width'				: '12px',
				'height'			: '12px',
				'cursor'			: 'pointer',
				'text-align'		: 'center',
				'text-decoration'	: 'none',
				'font-size'			: '17px'
			} );
			
			
			var code = $( 'div.fileinput', $form ).eq( 0 ).parent().html();
			$form.data( lagns, code );
			
			$( 'div.fileinput', $form ).live( 'click'+lagns, function () {
				var $div = $( this );
				var $input = $( 'input', $div ).eq( 0 );
				
				$input.change( function () {
					$( 'a.add1', $form ).click();
					$( this ).attr( 'name', 'files[]' );
				} );
			} );
			
			$( 'a.add1', $form ).click( function () {
				var $inputs = $( 'div.inputs', $form );
				$inputs.append( code );
			} );
			$( 'a.add5', $form ).click( function () {
				var $inputs = $( 'div.inputs', $form );
				$inputs.append( code );
				$inputs.append( code );
				$inputs.append( code );
				$inputs.append( code );
				$inputs.append( code );
				$form.each();
			} );
			
			$( 'a.remove', $form ).live( 'click'+lagns, function () {
				$( this ).parent().remove();
			} );
		} );
		
		
		
	} );
	
	
} )( jQuery );
