/* Add all functions that need to load after page finishes loading */
	$(document).ready(function()
	{
		onLoad(); // for timeline
		onResize(); // for timeline
		biographiesToggle();
		donationForm(); // toggle donation amount = other upon selection of other amount
		future(); // turn off future features for now
	});
	
/* Biographies Starts */
	function biographiesToggle()
	{
		if (($('.biographies')) || ($('.sources')))
		{
			// if any li has a class of closed when page is loaded, toggle it off
			$('ul.biographies li, ul.sources li').toggleClass('closed');
			
			// toggle open and closed on click when on the bio page
			$('ul.biographies li a.woman, ul.sources li h2').click(function()
			{
				$(this).parent().toggleClass('closed'); //mark selected item that was clicked
			});
			
			// open and close toggle all bios with one click
			$('a.openAll').toggle(
			function()
			{
				$('ul.biographies li').toggleClass('closed');
				$('a.openAll').text('Hide all biography descriptions');
				return false;
			},
			function()
			{
				$('ul.biographies li, ul.sources li').toggleClass('closed');
				$('a.openAll').text('View all biography descriptions');
				return false;
			});
			
			// open and close from view link
			$('a.toggle').toggle(
			function()
			{
				var thisSection = $(this).attr('href');
				//thisSection = thisSection.replace("/^#/","");
				$(thisSection).toggleClass('closed');
				$(thisSection + " a.toggle").text('Hide');				
				return false;
			},
			function()
			{
				var thisSection = $(this).attr('href');
				//thisSection = thisSection.replace("/^#/","");
				$(thisSection).toggleClass('closed');
				$(thisSection + " a.toggle").text('View');
				return false;
			});
			
			// go to specific bio from a link on a different page and toggle it open
			if (($('body#pageID_bios')) || ($('body#pageID_learn')))
			{
				//var thisBio = '#' + jQuery.url.attr('anchor');
				var thisBio = document.location.hash;
				$(thisBio).removeClass('closed');
			}
		}
	}
	
/* Biographies Ends */
	
/* Timeline Starts */
	var tl;
	function onLoad()
	{
		if ($('div#womens-timeline').html() != null)
		{
		  var eventSource = new Timeline.DefaultEventSource();
	
		  var theme = Timeline.ClassicTheme.create();
		  Timeline.ThemeName = 'with-theme';
		  
		  var bandInfos = [
		    Timeline.createHotZoneBandInfo(
			{
				// bandInfos0
				zones: [],
		        eventSource:    eventSource,
		        date:           "1686",
		        width:          "80%", 
		        intervalUnit:   Timeline.DateTime.YEAR,
		        intervalPixels: 200
		    }),
			Timeline.createHotZoneBandInfo(
			{
				// bandInfos1
				overview:       true,
				zones:  [],
		        eventSource:    eventSource,
		        date:           "1600",
		        width:          "20%", 
		        intervalUnit:   Timeline.DateTime.CENTURY,
		        intervalPixels: 50
		    })
		  ];
		  
		  bandInfos[1].syncWith = 0;
		  bandInfos[1].highlight = true; 
		  
		  tl = Timeline.create(document.getElementById("womens-timeline"), bandInfos, Timeline.HORIZONTAL);
		  tl.loadXML("../timeline/data.xml", function(xml, url)
		  {
		  	eventSource.loadXML(xml, url);
			$('div.timeline-event-icon').next('div.timeline-event-label').addClass('durationFalse');
		  });
		  
		  tl.getBand(0).addOnScrollListener(function(band)
		  {
		       var icon = $('div.timeline-event-icon');
			   var iconLabel = icon.next('div.timeline-event-label');	
		       if (icon)
			   {		          
					iconLabel.addClass('durationFalse');
		       }
		  });
		}
		
		
	}
	
	var resizeTimerID = null;
	function onResize()
	{
		if (!$('#womens-timeline'))
		{
		    if (resizeTimerID == null)
			{
		        resizeTimerID = window.setTimeout(function()
				{
		            resizeTimerID = null;
		            tl.layout();
		        }, 500);
			}
		}
	}
/* Timeline Ends */

/* Donation Form starts */	
	function donationForm()
	{
		var donationAmt;
		var buttonId = $('#button_id');
		
		$('select#passAmount').change(function()
		{	
			donationAmt = $('select#passAmount option:selected').val();
		
			switch(donationAmt)
			{
				case "5000":
					buttonId.val("3722605");
					break;
				case "2500":
					buttonId.val("3722685");
					break;
				case "1000":
					buttonId.val("3722719");
					break;
				case "500":
					buttonId.val("3722741");
					break;
				case "100":
					buttonId.val("3722762");
					break;
				default:
					buttonId.val("3626870"); // button created with no fixed amount
					break;			
			}
	
			$('#amount').val(donationAmt + ".00");		  
		});
	}
/* Donation Form ends */	
	
/* future features hidden for now */
	function future()
	{
		$('.map').click(function(){return false;});	
	}