function reSizer() {
	winh = $(window).height();
	conh = $('#text').height()+450;
	if (conh > winh) {
		paddingb = '50px';							
	} else {
		paddingb = ((winh-conh)+10)+'px';
	};
	$('#container').css('padding-bottom', paddingb);
}

function checkTime() {
	$('#loader').fadeIn(500);
}


function initOKF() {	
	var winh = $(window).height();
	var conh = $('#text').height()+450;
	if (conh > winh) {
		paddingb = '50px';							
	} else {
		paddingb = ((winh-conh)+10)+'px';
	};
	$('#container').css('padding-bottom', paddingb);

	var winw = $(window).width();
	if (winw < 980) {
		posx = '490px';
	} else {
		posx = Math.round(winw/2) + 'px';
	}
	$('#loader').css('left', posx);

	// For IE 6
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		$('#header-left > a > img').attr('src', 'images/obro-head.gif');
	}

	$('.ceebox').ceebox({ overlayColor:'#2F2B02', overlayOpacity:0.8, boxColor:'#B49D4D' });

	$('a.nav').bind('click', function() {
		var winh = ($(window).height()-350)+'px';
		$('#container').css('padding-bottom', winh);
	
		var path = this.toString();
		var link = path.substr(((this.toString()).lastIndexOf('/'))+1);
		$('#text-content').animate({opacity: '0.0'}, 700);
		$('#text').animate({height: '0px'}, 1000,
			function() {
				var checkTimeID = setTimeout("checkTime()", 1200); 
	
				$('#text').load(link + ' #text-content', 
					function() {
						clearTimeout(checkTimeID);
						$('#loader').fadeOut(300);
						htext = ($('#text-content').height() +80)+ 'px';
						$('#text-content').css('opacity', '0.0');
						$('#text-content').animate({opacity: '1.0'}, 1500);
						$('#text').animate({height: htext}, 1200, function() {
							winh = $(window).height();
							conh = $('#text').height()+450;
							if (conh > winh) {
								paddingb = '50px';							
							} else {
								paddingb = ((winh-conh)+10)+'px';
							};
	
							$('#container').css('padding-bottom', paddingb);
							$('.ceebox').ceebox({ overlayColor:'#2F2B02', overlayOpacity:0.8, boxColor:'#B49D4D' });
						});
					});
			});
		return false;
	});		
}


$(window).load( function() {
	$('#loadingdiv').fadeOut(1500);
});

$(document).ready(function() {
	initOKF();
});

$(window).resize( function() {
	reSizer();
});
