$(document).ready(function() {
	initMenu();
	processLeftMenu();
	processNewsList();
});
$(window).load(function() {
	setColumnHeights();
});

function setColumnHeights()
{
	var l = $("#leftColumn");
	var c = $("#centerColumn");
	var r = $("#rightColumn");
	var h = Math.max(
		l.outerHeight(),
		Math.max(
			c.outerHeight(),
			r.outerHeight()
		)
	);
	
	//alert(h);
	
	l.height(h - (l.outerHeight() - l.innerHeight()));
	c.height(h - (c.outerHeight() - c.innerHeight()));
	r.height(h - (r.outerHeight() - r.innerHeight()));
}

function initMenu()
{
	$("#topMenu li a").each(function() {
		var t = $(this);
		var menuItem = t.attr("name");
		var title = t.text();
		var isActive = t.hasClass("active");
		var active = isActive ? "on" : "";
		var imgSrc = "" + t.find("img").attr("src");
		var imgType = imgSrc.endsWith("gif") ? "gif" : "png";
		var img = $('<img src="images/menu/' + menuItem + active + '.' + imgType + '" alt="' + title + '" />');
		if(!isActive) {
			img.hover(
				function() {
					$(this).attr("src", "images/menu/" + menuItem +"on." + imgType + "");
				},
				function() {
					$(this).attr("src", "images/menu/" + menuItem +"." + imgType + "");
				});
		}
/*
		var img = $('<img src="images/menu/' + menuItem + active + '.png" alt="' + title + '" />');
		if(!isActive) {
			img.hover(
				function() {
					$(this).attr("src", "images/menu/" + menuItem +"on.png");
				},
				function() {
					$(this).attr("src", "images/menu/" + menuItem +".png");
				});
		}
*/
		t.html(img);
	});
}

function processLeftMenu()
{
	$("div.leftMenu a").each(function() {
									  $(this).html("<b>&bull;</b> " + $(this).html());
									  });
}
function processNewsList()
{
	$("#leftColumn div.newsList div.newsItem").each(function() {
		var u = $(this).find("div.head a");
		$(this).click(function() {
						 location.href = u.attr("href");
						 });
		$(this).attr("title", u.text());
	});
}
String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/g, "");
}
String.prototype.ltrim = function(trimStr)
{
	if (!trimStr)
	{
		return this.replace(/^\s+/, "");
	}
	else
	{
		var re = new RegExp("^" + trimStr);
		return this.replace(re, "");
	}
}
String.prototype.rtrim = function(trimStr)
{
	if (!trimStr)
	{
		return this.replace(/\s+$/, "");
	}
	else
	{
		var re = new RegExp(trimStr + "$");
		return this.replace(re, "");
	}
}
String.prototype.startsWith = function(startStr)
{
	return this.match("^" + startStr);
}
String.prototype.endsWith = function(endStr)
{
	return this.match(endStr + "$");
}

