$(document).ready(function(){
 	$('#rightFixtures').datepicker({
		inline: true
	});
	
	checkFixtures();
	$(".ui-has-fixtures").unbind("click");
	
	$("#closeButton").mouseover(function(){
		$("#headerImg").attr("src","/docs/bubble/headon.png");
	}).mouseout(function(){
		$("#headerImg").attr("src","/docs/bubble/headoff.png");		
	}).click(function(){
		$("#bubbleBox").fadeOut("normal");
		$("#bubbleBox #contentbox").html("");
		$("#bubbleBox #contentbox").html("");
		return false;
	})
})

function checkFixtures(){
	var curMonth = $(".ui-datepicker-month").attr("curmonth");
	var curYear = $(".ui-datepicker-year").html();

	$(".ui-has-fixtures").removeClass("ui-has-fixtures");
	
	$.post("/dyn/.gf.php",{ currentmonth: curMonth },function(data){
		if (data.success){
			$.each(data.boxes, function(rowid,boxid){
				$("#" + boxid).addClass("ui-has-fixtures");
			});
			
			
			$(".ui-has-fixtures").click(function(){
				var curDay = $(this).html();

				$("#bubbleBox").fadeIn("fast",function(){
					$.post("/dyn/.fi.php", { year: curYear, month: curMonth, day: curDay }, function(data){
						if (data.success){
							for (x in data.title){
								if (data.maplink[x]){
									$("#bubbleBox #contentbox").append("<h3>" + data.cat[x] + "</h3><h2>" + data.title[x] + "</h2><p>" + data.date[x] + " - <a href=\"" + data.maplink[x] + "\" target=\"_blank\" style=\"font-size:10px;\">View Map</a></p>");
								} else {
									$("#bubbleBox #contentbox").append("<h3>" + data.cat[x] + "</h3><h2>" + data.title[x] + "</h2><p>" + data.date[x] + "</p>");
								}
							}
						}
					},"json");
				});

				return false; // important > this removes the 'click' functionality of the date.
			})
		}
	},"json");
}