
// --------------------------------------------------------------------------------
// Script for berlin list hover info

  $(document).ready(function() {
	$('.berlin_list_link').hover(
	function() {
		// Hover
		var info_id = $(this).attr('id');
		info_id += "_info";

		$('#' + info_id).show();
	},

	function() {
		// Un-hover
		var info_id = $(this).attr('id');
		info_id += "_info";

		$('#' + info_id).hide();
	});
});


// --------------------------------------------------------------------------------
// Script for upload indicator on participate page

  $(document).ready(function() {
	$('#participate_form').submit(function() {
//		if($('#image_upload').hasClass('active_tab')) {
			$('.upload_screen').show();
//		}
	});
});


// --------------------------------------------------------------------------------
// Script for archive

  $(document).ready(function() {
	// All years start closed
	$('.year_list').hide();
	$('.year_list').filter(':first').show();
	$('.year').filter(':first').addClass('expanded');

	// All months start closed
	$('.month_list').hide();

	// Click to toggle a year
	$('.year').click(function() {
		$(this).toggleClass('expanded');
		$(this).next('.year_list').slideToggle('fast');
	});

	// Click to toggle a month
	$('.month').click(function() {
		$(this).next('.month_list').slideToggle('fast');
	});
});


// --------------------------------------------------------------------------------
// Script for show/hide FAQ questions

  $(document).ready(function() {
	  // All answers start closed
	  $('.faq_a').hide();

	  // Click question to toggle answer
	  $('.faq_q').click(function(){
		  // Toggle the clicked question's answer with class='open'
		  var click_q = $(this).next('.faq_a');
		  $('.faq_a').removeClass('open');
		  $(click_q).toggleClass('open');

		  // Close un-open answers and slide toggle open answers
		  $(".faq_a").each(function() {
			  if($(this).hasClass('open')) {
				  $(this).slideToggle('fast');
			  }
			  else {
				  $(this).hide();
			  }
		  });

	  });
  });


// --------------------------------------------------------------------------------
// Script for postcards' rollover

  $(document).ready(function() {
		  // Postcard rollover flip
	  $('.flip').each(function(){
		  $(this).hover(function(){
			  $(this).children('.wrap').css("top", "-340px");
		  }, function(){
			  $(this).children('.wrap').css("top", "0px");
		  });
	  });
	  $('.flip_med').each(function(){
		  $(this).hover(function(){
			  $(this).children('.wrap').css("top", "-165px");
		  }, function(){
			  $(this).children('.wrap').css("top", "0px");
		  });
	  });
  });


// --------------------------------------------------------------------------------
// Script to close message handler

  $(document).ready(function() {
	  // Message handler: Click to close
	  $(".close_message_bar").click(function() {
		  $("#message_bar").slideUp('fast');
	  });
  });


// --------------------------------------------------------------------------------
// Script for tabs

  $(document).ready(function() {
	  // Close tabs initially
	  $(".tab").hide();

	  // Open the first tab flagged as active
	  $(".tab_toggle.active_tab").each(function() {
		  var clicked_tab_id = $(this).attr('id');
		  clicked_tab_id += "_tab";
		  $('#' + clicked_tab_id).show();
	  });

	  // Click to change tab divs
	  $(".tab_toggle").click(function() {
		  // Set all tab toggles as inactive
		  $(".tab_toggle").removeClass('active_tab');

		  // Set the clicked tab toggle as active
		  $(this).addClass('active_tab');

		  // Store current tab in hidden field
		  var clicked_tab_id = $(this).attr('id');
		  $(".current_tab").val(clicked_tab_id);

		  // Open clicked tab div, hide others
		  clicked_tab_id += "_tab";
		  $(".tab").each(function() {
			  if($(this).attr('id') == clicked_tab_id) {
				  $(this).show();
			  }
			  else {
				  $(this).hide();
			  }
		  });
	  });
  });

// --------------------------------------------------------------------------------
// Script for login / register / mailing list menu

  $(document).ready(function() {
	  // Pop open the active toggle div
	  $("div.toggle_content .active").show();

	  // Submenu: Click to pop open participation divs
	  $(".toggle_trigger").click(function() {
			var toggle_div_id = $(this).attr('id');

			// Set the class 'expanded' on the tab just clicked, remove it from the others
			$(".toggle_trigger").each(function() {
				if($(this).attr('id') == toggle_div_id) {
					$(this).toggleClass('expanded');
				}
				else {
					$(this).removeClass('expanded');
				}
			});

			toggle_div_id += "_popup";

			// Toggle divs
			$(".toggle_content").toggleClass('active', $(this).attr('id') == toggle_div_id);
			$(".toggle_content:not(#" + toggle_div_id + ")").hide();
			$("#" + toggle_div_id).slideToggle('fast');

			// Set the focus to the first input field in the clicked div
			// (This sets the focus effectively, but it causes a weird screen flicker - hence commented out.)
//			$("#login-form :input:visible:first").focus();

			return false;
	  });

	  // Popup menu close buttons
	  $("#signup-cancel").click(function() {
		  $("#newsletter_popup").slideUp('fast');
		  $("#newsletter_popup").removeClass('active');
		  $("#newsletter").removeClass('expanded');
		});
	  $("#register-cancel").click(function() {
		  $("#register_popup").slideUp('fast');
		  $("#register_popup").removeClass('active');
		  $("#register").removeClass('expanded');
	  });
	  $("#login-cancel").click(function() {
		  $("#login_popup").slideUp('fast');
		  $("#login_popup").removeClass('active');
		  $("#login").removeClass('expanded');
	  });
  });

// --------------------------------------------------------------------------------
// Script to send the user up to the login / register popups

  $(document).ready(function() {
  $('a#must-login').click(function() {
		$("#login").click();
	});
  $('a#must-register').click(function() {
	  $("#register").click();
	  });
  });


// --------------------------------------------------------------------------------
// Script for the stamping / tags section in the single postcard page

  $(document).ready(function() {
	  // Things hidden by default
	  $(".post_stamps_text").hide();
	  $(".post_stamps_button.hover").hide();

	  // Hover stamp icon
	  $(".post_stamps_button").mouseover(function() {
		  $(".post_stamps_button").hide();
		  $(".post_stamps_button.hover").show();
	  });

	  // Unhover stamp icon
	  $(".post_stamps_button").mouseout(function() {
		  if(!$(this).hasClass("clicked")) {
			  $(".post_stamps_button").show();
			  $(".post_stamps_button.hover").hide();
		  }
	  });

	  // Click stamp icon
	  $(".post_stamps_button.clickable").click(function() {
		  $(this).addClass("clicked");
		  $(".post_stamps_text").show();
		  $(".post_tags").hide();
	  });

	  // Click cancel button
	  $("#stamp-cancel").click(function() {
		  $(".post_stamps_button").removeClass("clicked");
		  $(".post_stamps_button").show();
		  $(".post_stamps_button.hover").hide();
		  $(".post_stamps_text").hide();
		  $(".post_tags").show();
	  });
  });


// --------------------------------------------------------------------------------
// Script for flag as junk mail

  $(document).ready(function() {
	  // Things hidden by default
	  $(".junk_mail_confirm").hide();

	  // Click flag as junk mail button
	  $("#junk-popup").click(function() {
		  $(".junk_mail_confirm").show();
	  });

	  // Click cancel button
	  $("#junk-cancel").click(function() {
		  $(".junk_mail_confirm").hide();
	  });
  });

