function initialize_menu() {
	$('ul#menu ul').hide();
	$('ul#menu ul:first').show();
	$('ul#menu li a').click(function () {
		var e = $(this).next();
		if (e.is('ul') && !e.is(':visible')) {
			$('ul#menu ul:visible').slideUp('fast');
			e.slideDown('fast');
			return false;
		}
	});
}

function initialize_links() {
	$('a[rel="external"]').click(function () {
		window.open(this.href);
		return false;
	});
}

function initialize_tabs() {
	$('.tab').hide();
	$('.tab:first').show();
	$('.tabs ul a:first').addClass('active');
	$('.tabs ul a').click(function() {
		$('.tabs ul a').removeClass('active');
		$(this).addClass('active');
		$('.tab').hide();
		$('.' + $(this).attr('rel')).show();
	});
}

function initialize_thumbs() {
	$('.thumbnail').hover(function() {
		$(this).find('.title').css({color:'#ff0000'});
	}, function() {
		$(this).find('.title').css({color:'#fff'});
	});
}

function server_time() {
	var time = null; 
	$.ajax({
		url: '/server_time.php', 
		async: false,
		dataType: 'text', 
		success: function (text) { 
			time = new Date(Date.parse(text)); 
		},
		error: function (http, message, exc) { 
			time = new Date();
		}
	});
	return time;
}

$.fn.tooltip = function () {
	var top, left;

	$(this).mousemove(function (e) {
		top = e.pageY + 15;
		left = e.pageX - ($('#tooltip').width() / 2);
		if (left + $('#tooltip').width() > $(window).width()) {
			left = $(window).width() - $('#tooltip').width();
		}
		$('#tooltip').css({position: 'absolute', top: top, left: left});
	}).hover(function (e) {
		$('body').append('<div id="tooltip"></div>');
		if ($(this).attr('alt')) {
			$('#tooltip').text($(this).attr('alt'));
		}
		if (left + $('#tooltip').width() > $(window).width()) {
			left = $(window).width() - $('#tooltip').width();
		}
		$('#tooltip').css({'top': top, 'left': left}).fadeIn();
	}, function () {
		$('#tooltip').remove();
	});
}