$(document).ready(function(){

	// $('#login_id').hide();


	if($('#map').length > 0) { // if map div exists
		myMap = new GMap2(document.getElementById('map'));
		myMap.setMapType(G_PHYSICAL_MAP);
		
		// controls
		var topRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,10));
		myMap.addControl(new GSmallZoomControl(), topRight);

		var center_point = new GLatLng(49.037868,-31.640625);
		myMap.setCenter(center_point, 2);
		
		// add controls
		// set markers
		
		set_markers();
		
	}
	
	if($('#profile #info div').length > 0) {
		$('#profile #info div').hide();
		$('#profile #info div.open').show();
		
		$('#profile #info h4 a').click(function(){
			var theDiv = $(this).parent('h4').next('div');
			if(theDiv.hasClass('open')) {
				theDiv.removeClass('open').hide();
			} else {
				$('#profile #info div').hide().removeClass('open');
				theDiv.addClass('open').show();
			}
			return false;
		});
	}

	
	// $(this).css("height", $(this).height()+"px");


	
	var slideDuration = 250;

	if($('div.section').length > 0) {
		$('div.section div.content').each(function() {
			$(this).css("height", $(this).height()+"px").hide();
		});
		
		// open first?
		// $('div.section:first').addClass('open').children('div.content').show();
		
		$('div.section h4 a').click(function(){
			var theDiv = $(this).parent('h4').parent('div.section');
			if(theDiv.hasClass('open')) {
				theDiv.removeClass('open').children('div.content').slideUp(slideDuration);
			} else {
				// only one at a time?
				// $('div.section').removeClass('open').children('div.content').slideUp(slideDuration);
				theDiv.addClass('open').children('div.content').slideDown(slideDuration);
			}
			return false;
		});
	}


	if($('#timeline').length > 0) {
	
		var rand_start = Math.floor(Math.random() * parseInt($('#timeline_images img').length))
	
		$('#timeline_images').cycle({ 
			fx: 'scrollHorz',
			prev:   'a#timeline_prev', 
			next:   'a#timeline_next', 
			startingSlide: rand_start,
			timeout: 0,
			speed: 700,
			before: function(){
				var tid = parseInt($(this).attr('id').substr(2));
				$('#ti_year').html(tis[tid].year);
				$('#ti_title').html(tis[tid].title);
				$('#ti_description').html(tis[tid].description);
			}
		});
	}
	
});


