$(document).ready(function()
{
	// Disable default link.
	$('li#opEnquiry a, a#sendEnquiryButton').click(function(e)
	{
		e.preventDefault();
	});
	
	// Set up print button.
	$('li#opPrint a').click(function(e)
	{
		e.preventDefault();
		
		window.print();
	});
	
	// Event Handler for tabs.
	$('div#schoolTabs ul.tabs a').click(function(e)
	{
		e.preventDefault();
		
		// Change tab presentation.
		
		// Remove current from all.
		$('div#schoolTabs ul.tabs li').removeClass('current');
		
		// Add current to clicked element.
		$(this).parent().addClass('current');
		
		// Change forms.
		
		// Get form id.
		var tabID = $(this).attr('href').substr(1);
		
		// Switch forms.
		$('div.tab').css('display', 'none');
		$('div#tab' + tabID).css('display', 'block');
	});
	
	// Set "I like this School" form's action.
	if($('div#peopleLikeThisSchool form')[0] != undefined)
	{
		//$('div#peopleLikeThisSchool form')[0].setAttribute('action', 'ajax/addILikeCount.asp');
		
		// Event Handler for "I like this School".
		$('div#peopleLikeThisSchool form').submit(function()
		{
			// Disable button by hiding.
			$('div#peopleLikeThisSchool form input.image').css('display', 'none');
			
			// Increment Counter on client side.
			var counter = $('div#peopleLikeThisSchool span.counter').html();
			if(!isNaN(counter))
				counter = parseInt(counter) + 1;
			$('div#peopleLikeThisSchool span.counter').html(counter);
		});
		$('div#peopleLikeThisSchool form').ajaxForm(function()
		{
			
		});
	}
	
	// Lightbox the Gallery.
	if($('div#schoolGallery')[0] != undefined)
	{
		$('div#schoolGallery a').lightBox(
		{
			imageBtnClose: rootFolder + '/js/lightbox/' + 'images/lightbox-btn-close.gif', 
			imageBtnPrev: rootFolder + '/js/lightbox/' + 'images/lightbox-btn-prev.gif', 
			imageBtnNext: rootFolder + '/js/lightbox/' + 'images/lightbox-btn-next.gif', 
			imageLoading: rootFolder + '/js/lightbox/' + 'images/lightbox-ico-loading.gif'
		});
	}
	
	// Initialise Map.
	initialize();
	
	// Add School Marker.
	createSchoolMarker();
});

$(document).unload(function()
{
	// Unload google maps.
	GUnload();
});

function initialize()
{
	if(GBrowserIsCompatible()) 
	{
		map = new GMap2(document.getElementById("googlemap"));
		map.setCenter(new GLatLng(-38.1101910, 145.1425120), 13);
		
		map.addControl(new GMapTypeControl());
		map.addControl(new GSmallMapControl());
	}
}

function createSchoolMarker()
{
	var latitude       = $('input#schoolLatitude').attr('value');
	var longitude      = $('input#schoolLongitude').attr('value');
	var mapIcon        =  new GIcon(G_DEFAULT_ICON);
	mapIcon.image      = 'http://www.schoolselect.com.au/images/icons/schoolMarker.png';
	mapIcon.iconSize   = new GSize(40, 40);
	mapIcon.iconAnchor = new GPoint(0, 0);
	mapIcon.shadow     = null;
	
	var markerLocation = new GLatLng(latitude, longitude)
	var currMarker = new GMarker(markerLocation, mapIcon);
	
	// Position and show.
	map.setCenter(markerLocation, 15);
	map.addOverlay(currMarker);
}
