$(function(){
	initSidebar2();
});

function initSidebar2(){
	var _offset = 42;
//	$('#sidebar').css({
//		height: $('#content').height()
//	})
	var _picture = $('#sidebar .picture');
	var _link = $('#sidebar .title');
	var _minHeight = _picture.height()-_link.height()-_offset;
	var _height, _scroll;

	function fixLayout() {
		if($(window).height() < _minHeight) {
			$('#sidebar').addClass('small');
		} else {
			$('#sidebar').removeClass('small');
		}
		if($.browser.msie && $.browser.version < 7){
			_height = document.documentElement.clientHeight;
			_scroll = document.documentElement.scrollTop;
			_picture.css({
				postion: 'relative',
				paddingTop:  _scroll+'px'
			});
			if(_height < _picture.height()) {
				document.title = _picture.height()+ '   '+_height + "   "+_link.height()+"    "+_offset
				_link.css({
					top: ( _height+ _scroll -_link.height()-_offset ) +'px',
					position: 'absolute'
				});
			} else {
				_link.css({
					top: (_picture.height() + _scroll - _offset - _link.height()) +'px',
					position: 'absolute'
				});
			}
		}
	}
	$(window).resize(fixLayout);
	fixLayout();
	$(window).scroll(function(){
		if($.browser.msie && $.browser.version < 7){
			_height = document.documentElement.clientHeight;
			_scroll = document.documentElement.scrollTop;
			_picture.css({
				postion: 'relative',
				paddingTop:  _scroll+'px'
			})
			if(_height < _picture.height()) {
				_link.css({
					top: (_height + _scroll -_link.height()-_offset ) +'px',
					position: 'absolute'
				});
			} else {
				_link.css({
					top: (_picture.height() + _scroll - _offset - _link.height()) +'px',
					position: 'absolute'
				});
			}
		}
	});
}
