// JavaScript Document

/* $(document).ready(function(){
	$('.bubbleInfo').css('opacity','0');
	var top = ($('.bubbleInfo').offset().top);
	
	$('.bubbleInfo').animate({top: top-207, opacity: 0}, 1);
		
	$('.bubbleInfo').hover(function() {
		$('.bubbleInfo').animate({top: '-=10', opacity: 1}, 250, 'swing');
	},
	function() {
		$('.bubbleInfo').animate({top: '-=10', opacity: 0}, 250, 'swing');
		$('.bubbleInfo').animate({top: '+=20', opacity: 0}, 1);
	});
	checkKey(e);	
}); */

$(document).ready(function(){
	$('.bubbleInfo').css('opacity','0');
	var top = ($('.bubbleInfo').offset().top);
		
	$('.bubbleInfo').hover(function() {
		$('.bubbleInfo').animate({top: '-=10', opacity: 1}, 250, 'swing');
	},
	function() {
		$('.bubbleInfo').animate({top: '-=10', opacity: 0}, 250, 'swing');
		$('.bubbleInfo').animate({top: '+=20', opacity: 0}, 1);
	});
	checkKey(e);	
});

function loadPost() {
	var date = $('#wp_date').val();
	if(date == "") { date = null };
	var postID = $('#wp_id').val();
	if(postID <= 0) { postID = null };
	$('.main').fadeOut('slow');
	$('#ajax_wrapper').load('/wp-content/themes/fellowship_journal/ajax.php',
		{'date':date,'postID':postID},
		function() {
			$('.main').fadeIn('slow');
			bubbleFun();
			$('#calendar table').unwrap();
			myChange();
			Cufon.refresh();
			$('#wp_date').val('');
			$('#wp_id').val('');
		});
	//alert('1');
}

function nextPost(id) {
	$('#wp_id').val(id);
	loadPost();
}

function checkKey(e){
	var prev = $('#prev_post').val();
	var next = $('#next_post').val();
     switch (e.keyCode) {
        case 37:
            if(prev > 0) {
				nextPost(prev);	
			}
			else {}
            break;
        case 39:
			if(next > 0) {
				nextPost(next);	
			}
			else{}
            break;
        default:}      
}

if ($.browser.mozilla) {
    $(document).keypress (checkKey);
} else {
    $(document).keydown (checkKey);
}
function bubbleFun() {
	var top = ($('.bubbleInfo').offset().top);
	
	//$('.bubbleInfo').animate({top: top-207, opacity: 0}, 1);
		
	$('.bubbleInfo').css('opacity','0');
	$('.bubbleInfo').hover(function() {
		$('.bubbleInfo').animate({top: '-=10', opacity: 1}, 250, 'swing');
	},
	function() {
		$('.bubbleInfo').animate({top: '-=10', opacity: 0}, 250, 'swing');
		$('.bubbleInfo').animate({top: '+=20', opacity: 0}, 1);
	});
}
function myChange() {
	Cufon.refresh('.datepick-month-header');
	$('#calendar table').wrap('<div id="calendar_table"></div>');
	$('.datepick-cmd-next').text('');
	$('.datepick-cmd-prev').text('');
}

function dateSelect(date) {
	$('#wp_date').val(date);
	$('.datepick-today').css('background','none');
	myChange();
	loadPost();
}

function myChangeClicked() {
	Cufon.refresh('.datepick-month-header');
	$('#calendar table').wrap('<div id="calendar_table"></div>');
	$('.datepick-cmd-next').text('');
	$('.datepick-cmd-prev').text('');
}
