$(document).ready(function() {
	
	$('body').addClass('jsEnabled');
	
	$('a.new-window').each(function(index) {
		if (this.title != "") this.title += ' ';
		this.title += '(opens in a new window)';
		
		this.onclick = function() {
			window.open(this.href);
			return false;
		};
	});

	/*	 Calculating width for gallery image */
	//calculateGalleryWidth();

	/* IE fixes */
	if ($.browser.msie && $.browser.version > 6) {
		$('body#home-home div.post:nth-child(3n+3)').css('margin-right', 0);
	}
	if ($.browser.msie && $.browser.version <= 6) {
		
		$('div#sidebar').hover(function() {
			$(this).addClass('sidebar_hover');
		}, function() {
			$(this).removeClass('sidebar_hover');
		});

	}
});

/*	 Calculating width for gallery image */
	function calculateGalleryWidth () {
		if ($('div.gallery')) {

			var $panels = $('div.gallery ul.gallery li');
		    var $container = $('ul.gallery');

			var maxHeight = 0;
			var panelWidth = 0;

			$panels.find('img').each(function(index) {
				if (this.height > maxHeight) maxHeight = this.height;
			});

			$panels.each(function(i) {
				panelWidth = panelWidth + $panels[i].offsetWidth + parseInt($($panels[i]).css('margin-right'));
			});

			// calculate a new width for the container (so it holds all panels)
		    $container.css({
				'width' : (panelWidth),
				'height' : maxHeight
			});

		};
	}
