//var palatino = '.leftcol p, #news h2, #serv-main h2, #serv-main .whbox li, #serv-side p, #cont-side address, #cont-side p, #team p, #gall-main .whbox p, #gall-side h3, #gall-side p.more a';

var palatino = '#news h2, #serv-main h2, #gall-side h3';

Cufon.replace(palatino, { fontFamily: 'Palatino-Linotype' });

$(function(){
	bodyBg();
	$(window).resize(bodyBg);
	if ($.browser.msie){
		navBp = 'background-position-y';
	}
	else {
		navBp = 'backgroundPosition';
	}
	$('#nav a').hover(
		function(){
			bp = $(this).parent().css(navBp);
			hoverbp = $(this).parent().css(navBp).replace(/0px/, '-55px');
			$(this).parent().css(navBp, hoverbp);
		},
		function(){
			$(this).parent().css(navBp, bp);
		}
	);
	activateNav();
	$('#gall-side li').each(function(){
		num = $('#gall-side li').index(this);
		if(num%2 == 1){
			$(this).css('paddingRight', '0px');
		}
	});
	$('.main, .side').equalizeHeight();
});

function bodyBg(){
	var bWidth = $('body').width();
	var wWidth = $('#wrap').width();
	var marginLeft = Math.round((bWidth-wWidth)/2);
	$('body').css('backgroundPosition', marginLeft + 'px 0px')
	$('#wrap').css('margin', '0px 0px 0px ' + marginLeft + 'px');
}

function activateNav(){
	var on = false;
	var loc = window.location.pathname.replace(/.*\/([^\/]+)$/g, '$1');
	$('#nav a').each(function(){
		var href = $(this).attr('href').replace(/.*\/([^\/]+)$/g, '$1');
		if(loc == href){
			on = true;
			var bp = $(this).parent().css(navBp).replace(/0px/g, '-55px');
			$(this).parent().css(navBp, bp).end().remove();
		}
	});
	if (!on){
		var bp = $('#nav a').eq(0).parent().css(navBp).replace(/0px/g, '-55px');
		$('#nav a').eq(0).parent().css(navBp, bp).end().remove();
	}
}

(function($) {
	$.fn.equalizeHeight = function(){
		var ht = 0;
		this.each(function(){
			$(this).height('auto');
			if (ht < $(this).outerHeight()){
				ht = $(this).outerHeight();
			}
			$(this).data('pad', $(this).outerHeight() - $(this).height());
		});
		return this.each(function(){
			newHt = ht - $(this).data('pad');
			$(this).height(newHt);
		});
	}
})(jQuery);
