/* Standard Macromedia functions for rollovers */

function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function swap_back() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swap() { //v3.0
  var i,j=0,x,a=swap.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/* ====================================================================================== */
/* jQuery document-is-ready function. Place all calls here */
jQuery(document).ready(function() {

	$("a[rel^='prettyPhoto']").prettyPhoto();

	//$(".taBlock h2").wrap("<a href=\"#\"></a>").css("text-decoration","none");
	//$(".taBlock .link").prepend("<img align=\"bottom\" src=\"/society/images/arrow_down.png\" width=\"10\" height=\"12\" alt=\"arrow\" /> ");
	
	$(".taBlock .link").click(function(e) {
		e.preventDefault();
		$(".taBlockContent").slideUp();
		if($(this).next(".taBlockContent").css('display') == 'none') {
			$(this).next(".taBlockContent").slideDown(function() {
				//$.scrollTo($(this));
			});
		}
	});

	if($("#mnet_photo img").size() > 0)
		$("td.profile_area").attr("width",$("#mnet_photo img").attr("width"));
	
	//if($("#mnet_logo").size() > 0) {
		//$("#mnet_logo").prepend("<div class=\"edit\"></div>");
		//$("#mnet_photo").prepend("<div class=\"edit\"></div>");
		//$("#profile_words").prepend("<div class=\"edit\"></div>");
		//$("#mnet_logo").append("<img src=\"/membership/images/b_edit.png\" width=\"16\" height=\"16\" alt=\"edit\" \>");
		//$("#mnet_photo").append("<img src=\"/membership/images/b_edit.png\" width=\"16\" height=\"16\" alt=\"edit\" \>");
		//$("#profile").append("<img src=\"/membership/images/b_edit.png\" width=\"16\" height=\"16\" alt=\"edit\" \>");
		//$("td.profile_area").attr("width",$("#mnet_photo img").attr("width"));
	//}
	
	// remove underline on images inside an a tag
	$("a:has(img)").css("text-decoration","none");
	
	// ************** MemberNet Profile ****************************************** */
	$('.edit_area').editable('http://www.thercs.org/membership/profile_save.php', {
	
		type		: 'textarea',
		rows		: 20,
		cols		: 20,
		cancel		: 'Cancel',
		submit		: 'OK',
		submitdata	: { _method: "put" },
		indicator	: '<img src="img/indicator.gif">',
		tooltip		: 'Click to edit your profile...',
		placeholder : 'Click to create a profile description'
		/*callback  : function(value, settings) {
			console.log(value + "Here");
		}*/
	});
	
	// ************** MemberNet Note ****************************************** */
	$('#notes .note .delete').click(function(e) {
		e.preventDefault();
		var answer = confirm("Delete your post?")
		if(answer) {
			$.post("/membership/mnet_process.php", {memberpost_delete:true}, function(result) {
				$("#notes .note").html(result);
			});
		}
	});

	$('#notes .note :not(.delete)').click(function() {
		$('#notes_edit').show("fast");
	});
	$('#note_cancel').click(function() {
		$('#notes_edit').hide("fast");
	});
	$("#membernet_post").submit(function(e){
		e.preventDefault();

		if(this.memberpost_title.value != "" && this.memberpost_content.value != "") {
			$.post("/membership/mnet_process.php", {memberpost_title:$("#memberpost_title").val(),memberpost_content:$("#memberpost_content").val()}, function(result) {
				$("#notes .note").html(result);
				$('#notes_edit').hide("fast");
			});
		}
	});
	// ************** MemberNet Message ****************************************** */
	$('#message .note').click(function(e) {
		e.preventDefault();
		$('#message_edit').toggle("fast");
	});
	$('#message_cancel').click(function(e) {
		e.preventDefault();
		$('#message_edit').hide("fast");
	});
	$("#membernet_message").submit(function(e){
		e.preventDefault();

		if(this.membermessage_subject.value != "" && this.membermessage_message.value != "") {
			$.post("/membership/mnet_process.php", {membermessage_subject:$("#membermessage_subject").val(),membermessage_message:$("#membermessage_message").val(),mid:$("#mid").val()}, function(result) {
				$("#message .note").html(result);
				$('#message_edit').hide("fast");
			});
		}
	});
	
	// ************************************************************************ */

	$('.edit_area_xxx').editable('http://www.thercs.org/membership/profile_save.php', {
	
		type		: 'textarea',
		rows		: 8,
		cols		: 80,
		cancel		: 'Cancel',
		submit		: 'OK',
		submitdata	: { _method: "put" },
		indicator	: '<img src="img/indicator.gif">',
		tooltip		: 'Click to edit your note...',
		placeholder : 'Click to create a MemberNet note'
		/*callback  : function(value, settings) {
			console.log(value + "Here");
		}*/
	});

	$(".ajaxupload_logo").editable("http://www.thercs.org/membership/profile_save.php", { 
		indicator	: "<img src='img/indicator.gif'>",
		type		: 'ajaxupload_logo',
		submit		: 'Upload',
		cancel		: 'Cancel',
		params		: 'field=logo',
		tooltip		: "Click to upload a logo"
	});
	$(".ajaxupload_photo").editable("http://www.thercs.org/membership/profile_save.php", { 
		indicator	: "<img src='img/indicator.gif'>",
		type		: 'ajaxupload',
		submit		: 'Upload',
		cancel		: 'Cancel',
		params		: 'field=photo',
		tooltip		: "Click to upload a photo"
	});


/*	$(".edit_area").editInPlace({
		url: "http://www.thercs.org/membership/profile_save.php",
		field_type: "textarea",
		textarea_rows: "20",
        textarea_cols: "35",
        params: "field=profile"
	});
*/

	//if($("#message_titles").size() != 0) {
	$("#message_titles li a").click(function(e) {
		e.preventDefault();
		var id = $(this).attr("id");
		$("#mv_"+id).toggle("fast");
		

/*		$.ajax({
			url: "member_get_message.php?mid="+id,
			async: false,
			success: function(results,status) {
				$("#message_viewer").html(results).show("fast");
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
				alert(textStatus);
			}
		})
*/

	/*	$.post("member_get_message.php", {mid:id}, function(result) {
			// format and output result. fadeTo(3000,1) simulates delay(), which isn't in jQuery
			$("#message_viewer").html(result).show("fast");//.fadeTo(3000,1).hide("fast");
			//$("#search_status").removeClass("ajax-loading");
		});*/
	});
	//}

	// ============================================================
	$("#signup").submit(function(e){
     				
		// stop normal link click
		e.preventDefault();

		// send request
		if(this.signup_email.value != "Email address" && this.signup_email.value != "" && this.signup_name.value != "First name" && this.signup_name.value != "") {
			$("#signup_status").empty().addClass("ajax-loading");
			
			$.post("newsletterSignup.php", {signup_email:$("#signup_email").val(),signup_name:$("#signup_name").val()}, function(result) {
				// format and output result. fadeTo(3000,1) simulates delay(), which isn't in jQuery
				$("#signup_status").html(result).show("fast").fadeTo(3000,1).hide("fast");
				$("#signup_status").removeClass("ajax-loading");
			});
		}
	});

	// ============================================================
	$("#__form_member_message").submit(function(e){
     				
		// stop normal link click
		e.preventDefault();

		// send request
		if(this.fmessage.value != "Click to leave me a message" && this.fmessage.value != "") {
			$("#message_status").empty().addClass("ajax-loading");
			$.post("member_send_message.php", {member_message:$("#fmessage").val()}, function(result) {
				// format and output result. fadeTo(3000,1) simulates delay(), which isn't in jQuery
				$("#message_status").html(result).show("fast");//.fadeTo(3000,1).hide("fast");
				$("#message_status").removeClass("ajax-loading");
			});
		}
	});

	// ============================================================
	$("#form_member_search").submit(function(e){
     				
		// stop normal link click
		e.preventDefault();

		// send request
		if(this.fsearch.value != "Search Membernet" && this.fsearch.value != "") {
			$("#search_status").empty().addClass("ajax-loading");
			//$("#search_status").css("border","1px solid #c00");
			$.post("member_search_results.php", {fsearch:$(".fsearch").val()}, function(result) {
				// format and output result. fadeTo(3000,1) simulates delay(), which isn't in jQuery
				$("#search_status").html(result).show("fast");//.fadeTo(3000,1).hide("fast");
				$("#search_status").removeClass("ajax-loading");
			});
		}
	});
	
	// =====================================================================
	// Get Member Info 
	// -----------------------------------------------------
	function xxxget_member_info() {
		
		$.ajax({
			url: "http://live.rcs.netxtra.net/custom/GetUserInfo.asp?m=",
			async: false,
			success: function(results,status) {
				// Hide the previous slide and show the new one
				if(t > pp) { // <<<<<<
					cs.animate({left:"-=300px"},{queue:false}).animate({"opacity":"hide"},function() {
						cs.css({left:"300px"}).html(results).animate({"left":"-=300px"},{queue:false}).animate({"opacity":"show"},updateControls(t));
					});
				} else if(t < pp) { // >>>>>>
					cs.animate({left:"+=300px"},{queue:false}).animate({"opacity":"hide"},function() {
						cs.css({left:"-300px"}).html(results).animate({"left":"+=300px"},{queue:false}).animate({"opacity":"show"},updateControls(t));
					});
				}
				pp = t;
				// Update the visual aspect of the 'this page' indicator
				$("#case_study_navigation_pages a").each(function() {
					var th = $(this);
					if(th.attr("id") <= t) {
						th.animate({opacity:.3},100,function() {
							th.css({"background-color":"#a73ba0","color":"#fff"});
							th.animate({opacity:1},100);
						});
					} else
						th.css({"background-color":"#fff","color":"#ccc"});
				});
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
				alert(textStatus);
			}
		})
	}
	
	// =====================================================================

});

// *************************************************************************
function checkQT() {
	if (navigator.plugins) {
		for (i=0; i < navigator.plugins.length; i++ ) {
			if (navigator.plugins[i].name.indexOf("QuickTime") >= 0) {
				haveqt = true;
			}
		}
	}
	if ((navigator.appVersion.indexOf("Mac") > 0) && (navigator.appName.substring(0,9) == "Microsoft") && (parseInt(navigator.appVersion) < 5) ) {
		haveqt = true;
	}
}

// *************************************************************************
