// File: /wp-content/themes/ainkani/scripts.js
// Description:
//    Javascript functions for the ainkani WP theme.


// === Variables and function to control image swapping on the home page. ===

var currentPic = 1;
var maxPic = 14;

function changeImage() {
  $("#pic" + currentPic + " img").fadeOut("slow", function() {
    (currentPic == maxPic) ? currentPic = 1 : currentPic++;
    $("#pic" + currentPic + " img").fadeIn("slow");
  });
  return currentPic;
}

$(function() {

  // === Home Page: Main image swapping.  ===
  $("#pic" + currentPic + " img").fadeIn("fast");
  var x = window.setInterval("changeImage(currentPic);", 4000);
	
	
	// === Navigation: Sub-navigation menus ===
	$("#about-nav").mouseover(         function() { $("#about-subnav").show(); } );
	$("#about-nav .subnav").mouseover( function() { $("#about-subnav").show(); } );
	$("#about-nav").mouseout(          function() { $("#about-subnav").hide(); } );
  $("#about-nav .subnav").mouseout(  function() { $("#about-subnav").hide(); } );
	
  $("#profile-nav").mouseover(         function() { $("#profile-subnav").show(); } );
  $("#profile-nav .subnav").mouseover( function() { $("#profile-subnav").show(); } );
  $("#profile-nav").mouseout(          function() { $("#profile-subnav").hide(); } );
  $("#profile-nav .subnav").mouseout(  function() { $("#profile-subnav").hide(); } );
	
	
	// === Registration: Re-order form fields. ===
	if ($("#post-99").length) {
		var str;
		
		// Set up intro text and additional info elements.
		str  = "<p>Ain-Kani.org profiles are a great way to connect with other people from Ain Kani, and for people to connect with you! Get started today by filling out the form below! You can fill out as little or as much information as you would like; however any starred fields are required.</p>\n";
    str += "<p class='smaller'><b>Privacy and Terms of Service:</b> The Ain Kani Development Society is committed to your privacy.  We will never sell your personal information or use it for any purposes outside of the scope of this website and its services.  By creating a profile on the AKDS website, you agree to allow your information to be visible and available to other users of this site.  Please <a href='mailto:jhalabi.fastmail.net'>e-mail the webmaster</a> if you have any questions or concerns.</p>\n";
		
		str += "<h3>Account Information</h3>\n  <div id='register-basic-info'></div> \n";
	  str += "<h3>User Information</h3>   \n  <div id='register-user-info'></div>  \n";
    str += "<h3>Submit Information</h3> \n  <div id='register-submit'></div>     \n";
	
	  $(str).prependTo("#registerform");
		
		// Tab order for fields.
		$("#mngl_custom\\[4\\]").attr("tabindex", "8");
		$("#mngl_custom\\[5\\]").attr("tabindex", "9");
		$("#mngl_custom\\[6\\]").attr("tabindex", "10");
		
		// Move fields around.
		$("#user_login").parent().parent().appendTo("#register-basic-info");
		$("#user_email").parent().parent().appendTo("#register-basic-info");
		$("#mngl_user_password").parent().parent().appendTo("#register-basic-info");
		$("#mngl_user_password_confirm").parent().parent().appendTo("#register-basic-info");
		
		$("#user_first_name").parent().parent().appendTo("#register-user-info");
		$("#user_last_name").parent().parent().appendTo("#register-user-info");
		$("#mngl_user_location").parent().parent().appendTo("#register-user-info");
    $("#mngl_custom\\[4\\]").parent().parent().appendTo("#register-user-info");
    $("#mngl_custom\\[6\\]").parent().parent().appendTo("#register-user-info");
    $("#mngl_custom\\[7\\]").parent().parent().appendTo("#register-user-info");
    $("#mngl_user_bio").parent().parent().appendTo("#register-user-info");
		
    $("#security_code").parent().parent().appendTo("#register-submit");
	}
	
	
	// === Profile Directory: Hide logged out text. ===
	$(".logged-in #post-96 #logged-out-text").hide();
	$("#directory-intro-text").insertAfter("#post-96 h3.storytitle");
	
	if ( $("#post-96 td").html() == "") {
		$("#post-96 td").html("&nbsp;");
	}
	
	
	// === My Profile: Re-order form fields. ===
	if ($("#post-102").length) {
		var str;
		
		// Set up contact and additional info tables.
		str  = "<h3>Contact Information:</h3>\n";
		str += "<table class='profile-edit-contact-table'>\n";
		str += "</table>\n";
		
		str += "<h3>Additional Profile Information:</h3>\n";
    str += "<table class='profile-edit-additional-table'>\n";
    str += "</table>\n";
		
		$(str).insertAfter(".profile-edit-table:first");
		
		// Move fields around.
		$(".profile-edit-table td").each(function() {
			
			switch ($(this).html()) {
				case "City:":
          $(this).parent().appendTo(".profile-edit-contact-table");
          break;
				
				case "State / Province:":
          $(this).parent().appendTo(".profile-edit-contact-table");
          break;
				
				case "Country:":
				  $(this).parent().appendTo(".profile-edit-contact-table");
					break;
					
			  case "Phone Number:":
          $(this).parent().appendTo(".profile-edit-contact-table");
          break;
					
				case "Bio:":
				  $(this).html("Bio Information:");
          $(this).parent().appendTo(".profile-edit-additional-table");
          break;
					
				case "Birthday:":
          $(this).parent().appendTo(".profile-edit-additional-table");
          break;
					
				case "URL:":
				  $(this).html("My Website:");
          $(this).parent().appendTo(".profile-edit-additional-table");
          break;
					
				case "Avatar:":
          $(this).parent().appendTo(".profile-edit-additional-table");
          break;
			}
		
		});
	}
});