$( document ).ready( function() {

	// -------------------- ЭЛЕМЕНТЫ УПРАВЛЕНИЯ ФОРМАМИ --------------------

	// фокус и потеря фокуса текстовых полей с подсказками

	$( '.autohiding' ).addClass(
		'pure'
	).focus( function() {
		if ( $( this ).hasClass( 'pure' ) )
			$( this ).attr( 'default', $(this).val() ).val( '' ).removeClass( 'pure' );
	}).blur( function() {
    	if ( trim( $( this ).val() ) == '' )
       		$( this ).val( $( this ).attr( 'default' ) ).addClass( 'pure' );
	});

	// очищаем формы от подсказок перед отправкой

	$( 'form' ).submit( function() {
		$( '.pure' ).val( '' );
	});

	// -------------------- МЕЛОЧИ --------------------

	$( '.developer .freelab' ).hover( function() {
		$( this ).siblings( 'a' ).addClass( 'hover' );
	}, function() {
		$( this ).siblings( 'a' ).removeClass( 'hover' );
	});

	// -------------------- СКРИПТЫ ДЛЯ IE6 --------------------

	if ( $.browser.msie && $.browser.version < 7 ) {

		// минимальная ширина страница

		window.attachEvent( 'onload', checkPageWidth );
		window.attachEvent( 'onresize', checkPageWidth );

		var minPageWidth = parseInt( $( '.site' ).get( 0 ).currentStyle[ 'min-width' ] );

		function checkPageWidth() {
			$( '.site' ).width( document.documentElement.clientWidth < minPageWidth ? minPageWidth + 'px' : '100%' );
		}

		// минимальная ширина элементов

		$( '.min-width' ).each( function() {
			var minWidth = $( this ).get( 0 ).currentStyle[ 'min-width' ].replace( 'px', '' );
			if ( $( this ).width() < minWidth )
				$( this ).width( minWidth );
		});

		// фикс уголков таблицы

		$( '.table' ).each( function() {
			if ( $( this ).width() % 2 ) {
				$( this ).find( '.table-rt, .table-rb' ).css( 'margin-right', '-1px' );
			}
			if ( $( this ).height() % 2 ) {
				$( this ).find( '.table-lb, .table-rb' ).css( 'margin-bottom', '-1px' );
			}
		});

	}

});


function ltrim( s )
{// очищает левую сторону строки от лишних символов

	var ptrn = /\s*((\S+\s*)*)/;
	return s.replace( ptrn, '$1' );
}


function rtrim( s )
{// очищает правую сторону строки от лишних символов

	var ptrn = /((\s*\S+)*)\s*/;
	return s.replace( ptrn, '$1' );
}


function trim( s )
{// очищает строку от лишних символов

	return ltrim( rtrim( s ) );
}

