function isEmail(str)
{
 	var supported = 0;

 	if (window.RegExp)
	{
   		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
  	}

	if (!supported) 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);

	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,5}|[0-9]{1,3})(\\]?)$");
	
	var valid = (!r1.test(str) && r2.test(str));
	
	if (valid == false)
		alert("'"+str+"'" + " is not a valid Email address");

	return valid;

}

function switchEmail(emailClient) {
	tables = document.getElementsByTagName('table');

	for (var i = 0; i < tables.length; i++) {
		if (tables[i].id != '') {
			tables[i].style.display = 'none';
		}
	}
	document.getElementById(emailClient).style.display = "block";
}


jQuery(function() {

	$("#pastissues select").change(function(){
		if (this.options[this.selectedIndex].value!="")
			document.location = '/'+this.options[this.selectedIndex].value;
	});
	
	$("#backtodpr select").change(function(){
		if (this.options[this.selectedIndex].value!="")
			window.open(this.options[this.selectedIndex].value), '';
	});
	
	$("#formsubscribe input.type_text").click(function(){ 
		if ($(this).attr("value")==$(this).attr("title"))
			$(this).attr("value","");
	});
	$("#formsubscribe input.type_text").blur(function(){ 
		if ($(this).attr("value")=="")
			$(this).attr("value",$(this).attr("title"));
	});
	
	$("#formsubscribe").submit(function(){
		return isEmail($("#jtgjd-jtgjd").attr("value"));
	});

	/* Page tools */
	
	$("#print").click(function(){
		print();
		return false;
	});
	
	$("#email").click(function(){
		location.href="mailto:?SUBJECT="+document.title+"&BODY="+escape(location.href); 
		return false;
	});
	
	$("#bookmark").click(function(){
		if ($.browser.msie)
			window.external.AddFavorite(location.href,document.title);
		else if ($.browser.opera)
			alert("To bookmark this page, first click OK and then hit \"CTRL+T\".");
		else if ($.browser.safari)
			alert("To bookmark this page, first click OK and then hit \"CMD+D\" (or \"Ctrl+D\" if you are using Windows).");
		else
			alert("To bookmark this page, first click OK and then hit \"CTRL+D\".");
		return false;
	});
		
	$("div.link").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});
		
	$("div.link").click(function(){
		document.location = $(this).find("a:eq(0)").attr("href");
	});
	
	$("a[rel*=external]").attr("target","_blank");

	$("#slideshow").slides({
		generateNextPrev: true,
		generatePagination: false,
		effect: "fade",
		crossfade: true
	});
	
	$('#bythenumbers .text').children().hide();
	$('#bythenumbers h4').css('z-index', '999');
	
	$("#bythenumbers").slides({
		generateNextPrev: false,
		generatePagination: false,
		effect: "fade",
		crossfade: false,
		container: "slides",
		play: 9000,
		fadeSpeed: 1250,
		autoHeight: true,
		animationStart: function(current){
			//$('#bythenumbers h4').css('z-index', '999');
		},
		animationComplete: function(current){
			//$('#bythenumbers h4').css('z-index', '999');
			animateSlideTransition(current-1);
		},
		slidesLoaded: function() {
			//$('#bythenumbers h4').css('z-index', '999');
			animateSlideTransition(0);
		}
	});
	
	function animateSlideTransition(slideIndex) {
		$('#bythenumbers .slides .slide:not(:eq('+slideIndex+')) .text').children().hide();
		$('#bythenumbers .slides .slide:eq('+slideIndex+')').find('.text p.top').delay(500).fadeIn(1500);
		$('#bythenumbers .slides .slide:eq('+slideIndex+')').find('.text .number').delay(1250).fadeIn(1500);
		$('#bythenumbers .slides .slide:eq('+slideIndex+')').find('.text p').delay(1750).fadeIn(1500);
	}
	
	$('textarea.autosize').autoResize().trigger('change');
	$('a.fancybox').fancybox();
	$(".comments .pagination a").click(function(){
		$(this).attr('href', $(this).attr('href') + "#comments");
	});
});
