try{
function bgAlign(){
	var bgOut = $('#bgOut'),
	bgIn = $('#bgIn'),
	imgs = bgOut.find('.im'),
	pT = $('#pT');
	if(!bgOut||!imgs)return false;
	var bgOutWidth = $('#pT').width();
	if(bgOutWidth<getClientWidth())bgOutWidth = getClientWidth();
	var bgOutHeight = $('#pT').height();
	if(bgOutHeight<getClientHeight())bgOutHeight = getClientHeight();
	bgIn.css({width:bgIn.attr('width')+'px',height:bgIn.attr('height')+'px',left:'-'+(bgIn.attr('width')-getClientWidth())/2+'px'});
	bgOut.css({width:bgOutWidth+'px',height:bgOutHeight+'px'});
	var width = getClientWidth(),
	height = getClientHeight();
	if(height<$('#pT').height())height = $('#pT').height();
	var fromX = (bgIn.attr('width') - width)/2,
	toX = fromX + width,
	fromY = 0,
	toY = fromY + height,
	width_used = 0,
	height_used = 0,
	width_in = bgIn.attr('width'),
	height_in = bgIn.attr('height')
	curX = 0,
	curY = 0,
	curWidth = 0,
	curHeight = 0;
	width = 10000;
	height = 10000;
	for(var i=0;i<imgs.length;i++){
		curX = parseInt(width_used);
		curY = parseInt(height_used);
		curWidth = parseInt($(imgs[i]).width());
		curHeight = parseInt($(imgs[i]).height());
		if(
				((fromX<=curX&&curX<=toX)||(fromX<=curX+curWidth&&curX+curWidth<=toX))
				&&
				((fromY<=curY&&curY<=toY)||(fromY<=curY+curHeight&&curY+curHeight<=toY))
		){
			$(imgs[i]).css('background-image','url(\''+$(imgs[i]).attr('background')+'\')');
		}
		//alert('fromX: '+fromX+', toX: '+toX+', curX: '+curX+', curXTO: '+(curX+curWidth)+'\nfromY: '+fromY+', toY: '+toY+', curY: '+curY+', curYTO: '+(curY+curHeight));
		width_used += parseInt($(imgs[i]).css('width'));
		if(width_used>=width_in){
			width_used = 0;
			height_used += parseInt($(imgs[i]).css('height'));
		}
		
	}
}

function pageAlign(){
	if(!cut)$('#pT').css({display:'block'});
	$('#pT').css({width:getClientWidth()+'px'});
	if(cut)$('#pT').css({height:getClientHeight()+'px'});
	$('#pT').css({display:'block'});
	var parent = $('.scrollVertical');
	parent.find('.uarr').hide();
	parent.find('.darr').hide();
	if(cut){
		var outerHeight = getClientHeight()-$('#head').height()-parent.find('.uarr').outerHeight()-parent.find('.darr').outerHeight()-75;
		if(outerHeight>parent.find('.inner').height())outerHeight = parent.find('.inner').height();
		parent.find('.outer').css({height:outerHeight+'px'});
		//if(parent.find('.outer').height()>=parent.find('.inner').height()){
		//}
		if(document.getElementById('rightCell'))
			$('#rightCell').attr('width','495').attr('height',outerHeight);
	}
}

function scrollVertical(type,el){
	switch(type){
		case 'start':
			el = $(el);
			if(!el)return false;
			var mod;
			if(el.hasClass('uarr'))
				mod = -1;
			else if(el.hasClass('darr'))
				mod = 1;
			else 
				return false;
			$.scrollVerticalEl = el;
			$.scrollVerticalMod = mod;
			$.scrollVerticalInterval = setInterval('scrollVertical(\'move\');',50);
		break;
		case 'stop':
			if($.scrollVerticalInterval)clearInterval($.scrollVerticalInterval);
		break;
		case 'move':
			var outer = $.scrollVerticalEl.parent().find('.outer'),
			inner = $.scrollVerticalEl.parent().find('.inner'),
			maxTop = inner.height()-outer.height(),
			curTop = parseInt(inner.css('margin-top'));
			if(maxTop<0)return false;
			if(isNaN(curTop))curTop = 0;
			curTop = - curTop;
			curTop = curTop + $.scrollVerticalMod * 5;
			if(curTop<0)curTop = 0;
			if(curTop>maxTop)curTop = maxTop;
			inner.css({marginTop:'-'+curTop+'px'});
		break;
		default:return false;break;
	}
}

function getClientWidth()
{  	
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
				document.documentElement ? document.documentElement.clientWidth : 0,
				document.body ? document.body.clientWidth : 0
			);
}

function checkVerticalScroll(){
	if(clientWidth>getClientWidth()){
		var dif = (clientWidth - getClientWidth()) / 2,
		mLeft = (getClientWidth() - $('#body').width())/2 + dif,
		mRight = (getClientWidth()-$('#body').width())/2 - dif;
		$('#head').css({marginLeft:mLeft+'px',marginRight:mRight+'px'});
		$('#body').css({marginLeft:mLeft+'px',marginRight:mRight+'px'});
	}
	mLeft = parseInt($('#body').css('margin-left'));
	if(isNaN(mLeft))mLeft = 0;
	if(mLeft>93){
		$('#body .top').css({marginLeft:'-93px'});
	}
	else{
		if(mLeft>60){
			$('#body .top').css({marginLeft:'-'+(mLeft-20)+'px'});
			$('a.left_link').css('margin-right',(mLeft-60)+'px');
		}
		else{
			$('#body .top').css({marginLeft:'-20px'});
			$('a.left_link').css('margin-right','20px');
		}
	}
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function getClientHeight()
{  	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
				document.documentElement ? document.documentElement.clientHeight : 0,
				document.body ? document.body.clientHeight : 0
			);
}

function tooltip(){
	var els = $('.tooltip'),
	i;
	if(!els)return false;
	for(i=0;i<els.length;i++){
		if($(els[i]).attr('titlet')){
			$(els[i]).mouseover(function(){
				$('#tooltip').html($(this).attr('titlet')).css({left:$(this).position().left-$('#tooltip').width()/4+'px',top:$(this).position().top-20+'px',display:'block'});
			});
			$(els[i]).mouseout(function(){
				$('#tooltip').css({display:'none'});
			});
		}
	}
}

$(document).ready(function(){
	pageAlign();
	bgAlign();
	tooltip();
	checkVerticalScroll();
});
}catch(e){}