// JavaScript Document
function isValidEmail(str) { 
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (!filter.test(str)){
		return false
	}else{
		return true
	}
}
var edit;
var fadex=-1;
function fade(){
	fadex++;
	var fadey = 4-fadex
	$(".fadeshow img:eq("+fadey+")").fadeOut(function(){
		if (fadex==3){			
			fadex=-1;
			$(".fadeshow img").show();
		}
		setTimeout("fade()",4000)
	});
}
$(document).ready(function() {
	$(document).pngFix(); 
	$("#twitter").getTwitter({
		userName: "david4lyne",
		numTweets: 1,
		loaderText: "Loading tweets...",
		slideIn: true,
		slideDuration: 750,
		showHeading: true,
		headingText: "",
		showProfileLink: false,
		showTimestamp: true
	});
	$(".support a").mouseover(function(){
		$(this).css("opacity","1")
	});
	$(".support a").mouseout(function(){
		$(this).css("opacity","0.6")
	});
	$(".support a").css("opacity","0.6")
	$(".thumbs div img").css("opacity", 0.7)
	$(".thumbs div img").mouseover(function(){
		$(this).css("opacity", 1)
	})
	$(".thumbs div img").mouseout(function(){
		$(this).css("opacity", 0.7)
	})
	$(".thumbs div img").click(function(){
		var self = this
		if ($(this).hasClass("link")){

		}else{
			$("div.article.gallery").addClass("processing")
			$(".main").fadeOut("fast", function(){
				$("a.mainlink").attr("href",$(self).attr("src").replace("/92/","/"))
				$(".main").attr("src","")

				$(".main").attr("src",$(self).attr("src").replace("/92/","/550/"))
				$(".main").fadeIn();
				$("div.article.gallery").removeClass("processing")

			})
		}
	})
	var options = { 
		target:        '.mailing_list',   // target element(s) to be updated with server response 
		beforeSubmit:  showRequest,  // pre-submit callback 
		success:       showResponse  // post-submit callback 
	};
	$('.mailing_list').ajaxForm(options);
	var options2 = { 
		target:        'form.contact',   // target element(s) to be updated with server response 
		beforeSubmit:  showContactRequest  // pre-submit callback 
	}; 
	$('form.contact').ajaxForm(options2);
	var options3 = { 
		target:        'form.volunteer',   // target element(s) to be updated with server response 
		beforeSubmit:  showVolRequest  // pre-submit callback 
	}; 
	$('form.volunteer').ajaxForm(options3);
	if (edit){
		$("input[type='text'],input[type='password'],textarea").addClass('changed')
	}
	$("input[type='text'],input[type='password'],textarea").focus(function(){
		$(this).addClass("highlighted")
		if (!$(this).hasClass('changed')){

			$(this).addClass('changed')
			if (!edit){
				var index = $("input[type='text'],input[type='password'],textarea").index(this);
				window["input"+index] = $(this).val();
				$(this).val("")

			}
		}

	})
	$("input[type='text'],input[type='password'],textarea").blur(function(){
		$(this).removeClass("highlighted")
		if ($(this).val()==""){
			if (!edit){
				var index = $("input[type='text'],input[type='password'],textarea").index(this);		
				$(this).val(window["input"+index])
			}
			$(this).removeClass('changed')
		}
	})
	var hash = new String(document.location).indexOf("#");
	if(hash > 0)
	{
		page = new String(document.location).substring(hash + 1);

		if(page.length > 0){
			
			$("a.mainlink").attr("href",$("#img_"+page).attr("src").replace("/92/","/"))
			$(".main").attr("src","#")
			$(".main").attr("src",$("#img_"+page).attr("src").replace("/92/","/550/"))
		}
	}

	fade()

});
function showRequest(){
	if ($("input[name=name]").val()==""||$("input[name=name]").val()=="Your Name"){
		$("input[name=name]").focus()
		alert('Please correct your name')
		return false;
	}
	if (!isValidEmail($("input[name=email]").val())){
		$("input[name=email]").focus()
		alert('Please correct your email address')
		return false;
	}
	$("form.mailing_list").html("<p>Please wait...</p>")

}
function showResponse(){

}
function showContactRequest(){
	if ($("input[name=contact_name]").val()==""){
		$("input[name=contact_name]").focus()
		alert('Please correct your name')
		return false;
	}
	if (!isValidEmail($("input[name=contact_email]").val())){
		$("input[name=contact_email]").focus()
		alert('Please correct your email address')
		return false;
	}
}

function showVolRequest(){
	if ($("input[name=volunteer_name]").val()==""){
		$("input[name=volunteer_name]").focus()
		alert('Please correct your name')
		return false;
	}
}

