// 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 f=0;
var featureTimer;
var edit
$(document).ready(function() {
	featureTimer = setTimeout("feature()",2000)
	$(".feature_numbers a").click(function(){
		clearTimeout(featureTimer)
		$(".feature_numbers a").removeClass("highlight")
		$(this).addClass("highlight")
		var index = $(".feature_numbers a").index(this)
		$(".features li").hide()
		$(".features li:eq("+index+")").show()		
	})
	$(".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{
			$(".article").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();
				$(".article").removeClass("processing")

			})
		}
	})
/*	$("#twitter").getTwitter({
		userName: "andrewpitt88",
		numTweets: 3,
		loaderText: "Loading tweets...",
		slideIn: true,
		slideDuration: 750,
		showHeading: true,
		headingText: "",
		showProfileLink: false,
		showTimestamp: true
	});*/

	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);

	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')
				}
		})
		function getUrl(u)    {
		     return u + '.html';
		}
		function loadURL(u)   {
		     $.get(getUrl(u), function(r){
		               $('#main').html(r);
		          }
		     );
		}
		//allows bookmarking
		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/"))
		
			}
		}
	

});
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 feature(){
	f++;
	$(".features li:eq("+f+")").fadeIn(function(){
		$(".feature_numbers a").removeClass("highlight")
		$(".feature_numbers a:eq("+f+")").addClass("highlight")
	})
	if (f==4){
		$(".features li:eq(1)").hide()
		$(".features li:eq(2)").hide()
		$(".features li:eq(3)").fadeOut(function(){
			$(".feature_numbers a").removeClass("highlight")
			$(".feature_numbers a:eq(0)").addClass("highlight")
		})
		f=0
	}
	featureTimer = setTimeout("feature()",3000)
}


