$(document).ready( function()
	{
		$('.upload-info').hide();
		$('#fields-form-button').hide();
		$('#upload_type_1_label').text( $('#upload-type-choose-link1').text() );
		$('#upload_type_2_label').text( $('#upload-type-choose-link2').text() );
		$('#upload_type_1').removeAttr( 'disabled' );
		$('#upload_type_2').removeAttr( 'disabled' );
		
		$( 'p.upload-more-options a' ).click(
			function()
			{
				$( 'div#more-options' + $(this).attr( 'id' ).substr( 17 ) ).slideToggle();
				return false;
			}
		);
		
		$( 'div.upload' ).hover(
			function()
			{
				$(this).find( 'p.upload-info' ).slideDown();
			},
			function()
			{
				$(this).find( 'p.upload-info' ).slideUp();
			}
		);
		
		$('#fields').change( function()
			{
				$('#fields option').each( function()
					{
						var optVal = parseInt( $(this).val() );
						
						if( optVal <= $('#fields option:selected').val() )
						{
							$('#upload-form-numb_fields-' + optVal ).slideDown();
						}
						else
						{
							$('#upload-form-numb_fields-' + optVal ).slideUp();
						}
					}
				);
				$('#upload-form-fields').replaceWith( '<input type="hidden" name="upload07" id="upload-form-fields" value="' + $('#fields option:selected').val() + '" />' );
			}
		);
		
		$('#upload_type_1').click( function()
			{
				$('.file').show();
				$('.url').hide();
			}
		);
		$('#upload_type_2').click( function()
			{
				$('.file').hide();
				$('.url').show();
			}
		);
		
		$('.upload05').change( function()
			{
				var id = $(this).attr( 'id' ).substr( 13 );
				if( $('#upload05_feld' + id + ':checked').length == 1)
				{
					$('#upload06_feld' + id).removeAttr( 'checked' );
					$('#upload06_feld' + id).attr( 'disabled', 'disabled' );
				}
				else
				{
					$('#upload06_feld' + id + '').removeAttr( 'disabled' );
				}
			}
		);
		
		$( '.upload06' ).change( function() 
			{
				var id = $(this).attr( 'id' ).substr( 13 );
				if( $('#upload06_feld' + id + ':checked').length == 1)
				{
					$('#upload05_feld' + id).removeAttr( 'checked' );
					$('#upload05_feld' + id).attr( 'disabled', 'disabled' );
				}
				else
				{
					$('#upload05_feld' + id).removeAttr( 'disabled' );
				}
			}
		);
		
		
		$('#upload-form-button').click( function()
			{
				$(this).hide();
				$('#upload-form-uploading').show();
			}
		);
		
		$('#verlink-link').attr( 'href', '#verlink-link' );
		$('#verlink-link').click( function()
			{
				$('#file-link-alter').slideToggle();
			}
		);
		
		$('div#bewerten ul#sterne li a.bw-link').click( function()
			{
				$.get( $(this).attr( 'href' ) + "/ajax", function( data )
					{
						var werte = data.split(",");
						var breite = Math.round( ( parseInt( werte[0] ) / parseInt( werte[1] ) ) * 22 );
						$('div#bewerten div#bewertung').css( 'width', breite + "px" );
						$('div#bewerten div#bewertung span').text( werte[1] + " Votes" );
					}
				);
				$('div#bewerten ul#sterne li a').fadeOut();
				
				return false;
			}
		);
		
		$('div#content div#content-container div.file-img div#img-top-box').hide();
		$('div#content div#content-container div.file-img div#img-area').hover( function()
			{
				$('div#content div#content-container div.file-img div#img-top-box').fadeIn();
			}, function()
			{
				$('div#content div#content-container div.file-img div#img-top-box').fadeOut();
			}
		);
		
		$('a#link-infos').click( function()
			{
				$('div#img-info-box').fadeIn();
				return false;
			}
		);
		$('a#link-verlinken').click( function()
			{
				$('div#img-link-box').fadeIn();
				return false;
			}
		);
		$('a#img-info-box-close').click( function()
			{
				$('div#img-info-box').fadeOut();
				return false;
			}
		);
		$('a#img-link-box-close').click( function()
			{
				$('div#img-link-box').fadeOut();
				return false;
			}
		);
		$('a#link-melden').click( function()
			{
				$.get( window.location, { report: "1", return_value: "1" }, 
					function( data )
					{
						$( "<p class=\"fbig center\"><strong>Vielen Dank!</strong> Du hast uns das Bild erfolgreich gemeldet!</p>" ).prependTo(  'div#content div#content-container' ).hide().slideDown();
						$('a#link-melden').fadeOut();
					}
				);
				return false;
			}
		);
		$('a.commentreport-link').click( function()
			{
				var commentID = parseInt( $(this).attr( 'id' ).substr( 13 ) );
				$.get( window.location, { commentreport: commentID, return_value: "1" }, 
					function( data )
					{
						$( "<p class=\"fbig center\"><strong>Vielen Dank!</strong> Du hast uns den Kommentar erfolgreich gemeldet!</p>" ).prependTo(  'div#content div#content-container div#comment-area-comments' ).hide().slideDown();
						$( 'a#commentreport' + commentID ).fadeOut();
					}
				);
				return false;
			}
		);
		$('form#melden').submit( function()
			{
				$.post( window.location, { action_x: "1", return_value: "1" },
					function( data )
					{
						$( "<p class=\"fbig center\"><strong>Vielen Dank!</strong> Du hast uns das Bild erfolgreich gemeldet!</p>" ).prependTo(  'div#content div#content-container' ).hide().slideDown();
						$( 'form#melden' ).fadeOut();
					}
				);
				return false;
			}
		);
	}
);
