var ROOT = "";

function fish_dropMenu()
{
	$("#navigation ul ul ").css({display: "none"});
	$("#navigation ul li").hover(
			function()
			{
				$(this).find('ul:first').css({visibility: "visible",display: "none"}).slideDown();
			},
			function()
			{
				$(this).find('ul:first').css({visibility: "hidden"});
			}
	);
}
 
$(document).ready(function(){					
	fish_dropMenu();
	
	if($("#courseselector").length > 0)	
		$("#courseselector").jScrollPane({scrollbarWidth:16, showArrows:true, arrowSize: 16});
});


function toggleDiv(divId)
{
	$("#" + divId).toggle();
}
function showDiv(divId, type)
{
	document.getElementById(divId).style.display = type;
}
function hideDiv(divId)
{
	document.getElementById(divId).style.display = "none";
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


function updateToolTip()
{
	if(tooltip)
		setTimeout("tooltip.init()", 500);
}

function redirectBooking(dateText, instr)
{
	var selected = new Date(dateText);
	
	for (i = 0; i < availableDates.length; i++)
	{
		if (selected.getFullYear() == availableDates[i][3])
		{
			if(selected.getMonth() == (availableDates[i][2] - 1) && selected.getDate() == availableDates[i][1])
			{
				coursedateId = availableDates[i][0];
				
				var arrayPageSize = getPageSize();
				$("#wait").css("height", arrayPageSize[1] + "px");
				$("#wait").show();
				$("#wait_animation").show();	
				
				document.location = ROOT + "/booking/" + coursedateId + "/";
				
			}
		}
	}

}

function availability(date)
{
	for (i = 0; i < availableDates.length; i++)
	{
		//$("#debug").html($("#debug").html() + "<br />" + date.getFullYear());
		if (date.getFullYear() == availableDates[i][3])
		{
			if(date.getMonth() == (availableDates[i][2] - 1) && date.getDate() == availableDates[i][1])
			{
				//tool = availableDates[i][3] + " Available Tickets<br />";
				//tool += "&pound;50 per 100 tickets";
				//tooltip.init();
				toolTipDisplayDate = availableDates[i][4];
				//alert(toolTipDisplayDate);
				return [true, 'available', toolTipDisplayDate];
			}
		}
	}
	return [false, ''];
}		

function meetingRoomBooked(date)
{
	for (i = 0; i < bookedDates.length; i++)
	{
		//$("#debug").html($("#debug").html() + "<br />" + date.getFullYear());
		if (date.getFullYear() == bookedDates[i][3])
		{
			if(date.getMonth() == (bookedDates[i][2] - 1) && date.getDate() == bookedDates[i][1])
			{
				//tool = availableDates[i][3] + " Available Tickets<br />";
				//tool += "&pound;50 per 100 tickets";
				//tooltip.init();
				toolTipDisplayDate = bookedDates[i][4];
				//alert(toolTipDisplayDate);
				return [true, 'booked', toolTipDisplayDate];
			}
		}
	}
	return [false, ''];
}				