// JavaScript Document
var browser = navigator.userAgent

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;

function getMouseXY(e) 
{
	if (IE) 
	{ 
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	} else { 
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}  
	return true;
}

function display(date)
{
	$.get("includes/getDay.php",{date:date},function(content){
		$("#cal-icon-text").html(content.day);
		$("#display-date").html(content.date);
		$("#display-now").html(content.events);
		$("td").removeClass("today");
		$("#"+date).addClass("today");
		imagePreview();
	}, "json");
}

function popup(ID)
{
	if ($("#popup").css("display") == "none")
	{
		$.get("includes/getEvent.php",{ID:ID},function(events){												  	
			$("#popup").html(events);
			$("#popup").css("top",(tempY-150));
			$("#popup").css("left",(tempX-150));
			$("#popup").fadeIn("fast");
		});
	}
}

function hide()
{
	$("#popup").css("display","none");
}


function stopIt(event) 
{
	if (!event) var event = window.event;
	event.cancelBubble = true;
	if (event.stopPropagation) event.stopPropagation(); 
}

function nextWeek(cal) 
{
	/*
	$("#calendar").hide("slide", { direction: "left" }, 750);
	window.setTimeout('getNextMonth(\''+cal+'\')', 600);
	*/
	getNextWeek(cal);
};

function getNextWeek(cal) 
{
	$.get("includes/getWeek.php", { week: cal }, function(data){
		$("#weekcal").html(data);
		//$("#calendar").show("slide", { direction: "right" }, 750);
	});
}

function nextMonth(cal) 
{
	/*
	$("#calendar").hide("slide", { direction: "right" }, 750);
	window.setTimeout('getPreviousMonth(\''+cal+'\')', 600);
	*/
	getNextMonth(cal);
};

function getNextMonth(cal) 
{
	$.get("includes/getCalendar.php", { month: cal }, function(data){
		$("#calendar").html(data);
		//$("#calendar").show("slide", { direction: "left" }, 750);
	});
}

/* rollover popup */ 
this.imagePreview = function(){	
		
		xOffset = 150;
		yOffset = 30;
		
	$("div.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? this.t : "";
		$("body").append("<div id='popup'></div>");
		$.get("includes/getEvent.php",{ID:c},function(events){
			$("#popup").html(events);
		});
		$("#popup")														
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
		function(){
			this.title = this.t;
			var x = setTimeout('$("#popup").fadeOut("fast")',10);
			$("#popup").mouseenter(function(){
				clearTimeout(x);
			});
			$("#popup").mouseleave(function(){
				$("#popup").fadeOut("fast");
			});
		});

};

// starting the script on page load
$(document).ready(function(){
	imagePreview();
});
