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"});
			}
	);
}

var iRotateTimmer = null; 

$(document).ready(function () {
    fish_dropMenu();

    $('#ad-holder').cycle({
        fx: 'fade'
    });

    //$('.awards-logo').rotate3Di(180, 3000);	
    $('.awards-logo img').css("width", "98px");
    $('.awards-logo img').css("height", "72px");

    rotateImage();

    //if($("#courseselector").length > 0)	
    //$("#courseselector").jScrollPane({scrollbarWidth:16, showArrows:true, arrowSize: 16});


    $('#marqueecontainer marquee').marquee('pointer').mouseover(function () {
        $(this).trigger('stop');
    }).mouseout(function () {
        $(this).trigger('start');
    });
});

function rotateImage() {
    clearTimeout(iRotateTimmer);

    $('.awards-logo img').animate({ width: "0px", height: "72px", marginLeft: "49px" }, 1300, function () {
        $(this).addClass("flipped");

        $(this).animate({ width: "98px", height: "72px", marginLeft: "0px" }, 1300, function () {

            $(this).animate({ width: "0px", height: "72px", marginLeft: "49px" }, 1300, function () {

                $(this).removeClass("flipped");

                $(this).animate({ width: "98px", height: "72px", marginLeft: "0px" }, 1300, function () {
                    iRotateTimmer = setTimeout(function () { rotateImage(); }, 10000);
                });
            });
        });
    });
}

function getCourseList(categoryId, root)
{
	$.post(root + '/ajax/get-course-list.asp', {categoryId:categoryId}, function(data) {
	  	eval(data);
	});	

}

function stopVideo(id)
{
	try
	{
		player = document.getElementById(id);
		player.pauseVideo();
	}
	catch(err){}
}

function showAwardOverlay()
{
	$("#wait").show();
	$("#awardfooter_overlay").show();	
	return false;
}

function closeAwardOverlay()
{
	$("#awardfooter_overlay").hide();
	$("#wait").hide();
	return false;
}


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) {
    var toolTipDisplayDate = "";

	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();
			    //alert(toolTipDisplayDate);

			    toolTipDisplayDate += availableDates[i][4] + "<br />";
			}
		}
    }

    if (toolTipDisplayDate != "") {
        return [true, 'available', toolTipDisplayDate];
    } else {
        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, ''];
}


function optionChanged(obj) {
    var $obj = $(obj);

    if ($obj.val() == "Other (please state)") {
        $("#hearAboutUs_other").show();
    } else {
        $("#hearAboutUs_other").hide();
    }
}
