function getCal(div_id, calendar_id, size, type, month, year, event_types, calendar_id) {
	if (event_types == null || event_types == 'undefined') event_types = 'null';
	
	var cal_scroller = getEle('cal_scroll_'+calendar_id);
	if (cal_scroller) {
		document.getElementById('cal_scroll_'+calendar_id).getCalendar(month, year);
	}
	
	var url = '/app/modules/cal/xml/calendar.php';

	var myRequest = new ajaxObject(url);
	myRequest.callback = function(responseText, responseStatus, responseXML) {
		if (responseStatus==200) {
			
			var calendarDiv = document.getElementById(div_id);
			calendarDiv.innerHTML = responseText;
			
			var scripts = calendarDiv.getElementsByTagName("script");
			for (var i=0; i<scripts.length; i++) { eval(scripts[i].text); }
			
			//setTips();
		}
	}
	var qs = 'size='+size+'&type='+type+'&m='+month+'&y='+year+'&calid='+calendar_id+'&event_types='+event_types;
	myRequest.update(qs);
}

//variables
var mouseposition;
var offset_top = 15;
var offset_left = 30;
var cal_fade_in_speed = 300;
var cal_fade_out_speed = 300;
var maskOpacity = 0.7;

jQuery(document).ready(function(){
	//get the mouses position
	jQuery(document).mousemove(function(e){
		mouseposition = e;
	});
	
	//setup window scrolling for the calendar pop up
	jQuery(window).scroll(function(){
		checkPopUp();
	});
	
	//get the template
	jQuery.get('/app/modules/cal/tpl/popup.layout.php',function(data){
		//append the pop up stuff
		jQuery(document.body).append(data);
		
		//set the mask to full width and height
		jQuery("#calendar_pop_up_mask").css({ 'width':jQuery(window).width(), 'height':maskHeight });
	});
	
	//get mask height
	var maskHeight = (jQuery(document.body).height() > jQuery(window).height()) ? jQuery(document.body).height() : jQuery(window).height();
	
	//set the mask width and height
	jQuery("#calendar_pop_up_mask").live('click',function(){
		//hide the cal pop up
		hideCalPop();				 	
	});
});

function showToolTip(anchor_id){
	//get the elements
	var anchor_ele = jQuery('#tip_'+anchor_id);
	var ele = jQuery("#"+anchor_id);
	
	//set the top and left
	var top = (mouseposition.pageY+offset_top);
	var left = (mouseposition.pageX+offset_left);
	
	//if the anchor is not in the body put it there
	if(anchor_ele.parent().attr('tagName').toLowerCase() != 'body'){
		jQuery(document.body).append(anchor_ele);
	}
	
	//set the css
	anchor_ele.css({ 'top':top, 'left':left}).show();
}

function hideToolTip(anchor_id){
	//hide the tool tip
	var ele = jQuery('#tip_'+anchor_id);
	ele.hide();
	
	//put it back in its place
	jQuery("#"+anchor_id).parent().append(ele);
}

function showCalPop(year,month,day){
	//if its animated return false
	if(jQuery("#calendar_pop_up").is(":animated") || jQuery("#calendar_pop_up_mask").is(":animated")) return false;
	
	//get the elements
	var pop_up = jQuery("#calendar_pop_up");
	var pop_up_mask = jQuery("#calendar_pop_up_mask");
	
	//get the position
	var top = getTop(pop_up);
	var left = getLeft(pop_up);
	
	//set the popup position
	pop_up.css({ 'top':top,'left':left });
	
	//fade in the pop up and mask
	pop_up.find('#cal_pop_data').load('/app/modules/cal/xml/popup.php?y='+year+'&m='+month+'&d='+day,function(){
		pop_up.find('#cal_pop_top').html('Events for '+month+'/'+day+'/'+year);
		pop_up.fadeIn(cal_fade_in_speed);
	});
	
	pop_up_mask.css({'opacity':0}).show().fadeTo(cal_fade_in_speed,maskOpacity);
}

function hideCalPop(){
	//if its animated return false;
	if(jQuery("#calendar_pop_up").is(":animated") || jQuery("#calendar_pop_up_mask").is(":animated")) return false;
	
	//fade out the calendar
	jQuery("#calendar_pop_up").fadeOut(cal_fade_out_speed,function(){ jQuery(this).hide() });
	jQuery("#calendar_pop_up_mask").fadeOut(cal_fade_out_speed,function(){ jQuery(this).hide() });
}

function checkPopUp(){
	//get the element
	var ele = jQuery("#calendar_pop_up");
	
	//get the position
	var top = getTop(ele);
	var left = getLeft(ele);
	
	//if the element is animated stop
	if(ele.is(":animated")) ele.stop();
	
	ele.animate({ 'top':top, 'left':left });
}

function getTop(ele){
	return (jQuery(window).scrollTop() + (jQuery(window).height()/2))-ele.height()/2;
}

function getLeft(ele){
	return (jQuery(window).scrollLeft() + (jQuery(window).width()/2))-ele.width()/2;
}
