var promo_loop;
function menu_expand(sel) {

	if ( $('#sm'+sel).hasClass( 'sub-menu-expanded' ) ) {
			$('#sm'+sel).animate({
				height: '0px'
			}, function() {
			$('#sm'+sel).removeClass('sub-menu-expanded');
			} );
			return false;
	}
	$('.sub-menu-expanded').each( function() {
			$(this).animate({
				height: '0px'
			}, function() {
			$(this).removeClass('sub-menu-expanded');
			} );
	});
	$('#menu-extra').html($('#mm' + sel).html());
	$('#menu-extra .sub-menu').css('height', 'auto');
	$('#menu-extra .sub-menu').addClass('sub-menu-expanded');
	var auto_height = $('#menu-extra .sub-menu').height();
	$('#sm'+sel).addClass('sub-menu-expanded');
	$('#sm' + sel).animate({
		height : auto_height
	}, function(){ 
	});
	return false;
}

function promo_box_rotate(count) {
	for( var i = 1; i < count; i++ ) {
		if ( $('#box' + i).css('display') == 'block' ) {
			$('#box' + i).slideUp('slow', function() {
				promo_loop = setTimeout( 'promo_box_rotate(' + count + ')', 10000 );
				return;
			});
			return;
		}
	}
	$('#box1').slideDown('slow', function() {
			promo_loop = setTimeout( 'promo_box_rotate(' + count + ')', 10000 );
			for( var i = 2; i < count; i++ ) {
				$('#box' + i).show();
			}
	});
}

function promo_select(num) {
	clearTimeout( promo_loop );
	for( var i = 1; i <= num; i++ ) {
		$('#box'+i).hide();
	}
	$('#box'+num).fadeIn('slow');
	return false;
}

function display_news(start) {
	$.ajax({
		url: 'ajax_news.php?from=' + start,
		success: function(data) {
			$('#more-news .the-news').html(data);
		}
	});
	return false;
}

function display_calendar() {
	var d = new Date();
	$.ajax({
		url: 'ajax_calendar.php?mon=' + (d.getMonth() + 1) + '&year=' + d.getFullYear(),
		success: function(data) {
			$('#calendar .the-calendar').html(data);
		}
	});
	return false;
}

function calendar_mon(month,year) {
	$.ajax({
		url: 'ajax_calendar.php?mon=' + month + '&year=' + year,
		success: function(data) {
			$('#calendar .the-calendar').html(data);
		}
	});
	return false;
}

function show_overlay(title,text) {
	if ( $('#calendar-overlay').data('overlay') ) {
		$("#calendar-overlay").data("overlay").load();
	}
	$("#calendar-overlay").overlay({

		// custom top position
		top: 100,

		// some mask tweaks suitable for facebox-looking dialogs
		mask: {

			// you might also consider a "transparent" color for the mask
			color: '#fff',

			// load mask a little faster
			loadSpeed: 200,

			// very transparent
			opacity: 0.5
		},

		// disable this for modal dialog-type of overlays
		closeOnClick: true,

		// load it immediately after the construction
		load: true,
		fixed: false

	});
	$('#calendar-overlay h2').html( title );
	$('#calendar-overlay p').html( text );
	
	return false;
}

function doc_ready() {
	$('#menu').css('min-height', Math.max( $('#content').height(), window.innerHeight ) + 'px' );
}

