/* 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();
	$("a[rel^='prettyPopin']").prettyPopin();
	
//	$(".taBlock h2").wrap("<a href=\"#\"></a>").css("text-decoration","none");
	$(".taBlock h2").prepend("<img align=\"bottom\" src=\"/society/images/arrow_down.png\" width=\"10\" height=\"12\" alt=\"arrow\" /> ");
	$(".taBlock h2").click(function() {
		$(".taBlockContent").slideUp();
		if($(this).next(".taBlockContent").css('display') == 'none') {
			$(this).next(".taBlockContent").slideDown(function() {
				//$.scrollTo($(this));
			});
		}
	});
	
	// ============================================================
	// convert our taEmail class of links from a standard email link
	// to a non-clickable version. But on click, convert it back!
	$(".taEmail").each(function() {
		var newhref = this.href.replace(/%20at%20/,"@");
		//alert(newhref);
		$(this).attr("href",newhref);
	});
	$(".taEmail").click(function() {
		var newhref = this.href.replace(/%20at%20/,"@");
		//alert(newhref);
		$(this).attr("href",newhref).click();
	});

	// ============================================================
	// Font Resize methods. Provide 3 links with classes 
	// .resetFont, .increaseFont, decreaseFont. Size is saved in a 
	// Cookie (requires jqery.cookie.js as well as jquery.js)
	// Set size of body {} font
	// ------------------------------------------------------------
	var originalFontSize = $('body').css('font-size');
	var originalFontSizeNum = parseFloat(originalFontSize);

	var cookie_name = 'textsize';
/*	
	if($.cookie(cookie_name))
		$('body').css('font-size', $.cookie(cookie_name));
	else
		$('body').css('font-size', originalFontSize);
*/
	// ------------------------------------------------------------
	// Reset Cookie
	$(".resetFont").click(function() {
		$('body').css('font-size', originalFontSize);
		$.cookie(cookie_name, null);
	});
	
	// ------------------------------------------------------------
	// Increase Font Size
	$(".increaseFont").click(function(){
		var currentFontSize = $('body').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize);
		if(currentFontSizeNum < 20) {
			var newFontSize = currentFontSizeNum*1.2;
			$('body').css('font-size', newFontSize);
			$.cookie(cookie_name, newFontSize);
		}
		return false;
	});
	// ------------------------------------------------------------
	// Decrease Font Size
	$('.decreaseFont').click(function(){
		var currentFontSize = $('body').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		if(currentFontSizeNum > 8) {
			var newFontSize = currentFontSizeNum*0.8;
			$('body').css('font-size', newFontSize);
			$.cookie(cookie_name, newFontSize);
		}
		return false;
	});

	// ============================================================
	$("#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");
			});
		}
	});

});