$(document).ready(function() {

//initialize anchors
if($('.scroll').length) {
	$(".scroll").localScroll();
	}

if($('#login').length) {
//initialize login on "enter" key
$("#login").keydown(function(e){
	if(e.which==13) $("#login").submit();
	});

//login accessibility helpers
$("#Username, #Fake").addClass("light");
$("#Fake").show();
$("#Password").hide();
$("#Username").focus(function() {
	if($(this).val() == "Username") {
		$(this).val("").removeClass("light");
		}
	});
$("#Username").blur(function() {
	if ($(this).val() == "") $(this).val("Username").addClass("light");
	});
$("#Fake").focus(function() {
	$(this).hide();
	$("#Password").show().focus();
	});
$("#Password").blur(function() {
	if ($(this).val() == "") {
		$(this).hide();
		$("#Fake").show();
		}
	});
}

//initialize contact form
    var options = { 
        target:        '#output',
        beforeSubmit:	validate,
        success:       showResponse
    };
    if($('#contact').length) {
		$('#contact').ajaxForm(options); 
		$('#contact input[name=no_spam]').val("check");
		}

//private forms
    var p = { 
        target:        '#output',
        success:       editResponse
    };
    $("#private form").ajaxForm(p);
    $("#passwordform input[name=no_spam]").val("check");

//cancel button - go back
if($("#Cancel").length) {
	$("#Cancel").click(function(e) {
		e.preventDefault();
		window.history.back();
		});
	}

//tabs on private area
if($("#private ul").length) {
	$("#private").tabs({
			cookie: {expires: 1}
		});
	}

// pagination
if($("#pagination").length) {
	var page = 0;
	var per_page = 3;
	var pages = Math.ceil(($("#pagination div:not(#nav,#arrowLeft,#arrowRight)").length)/per_page);
	function refresh() {
		$("#pagination div:not(#nav,#arrowLeft,#arrowRight)").hide();
		for(var i=(page*per_page)+1;i<=(page*per_page+per_page);i++) {
			$("#pagination div:nth-child("+i+")").show();
			}
		}
	refresh();
	$("#arrowLeft").click(function(e) {
		e.preventDefault();
		if(page>0) {
			page--;
			} else {
			page=pages-1;
			}
		refresh();
		});
	$("#arrowRight").click(function(e) {
		e.preventDefault();
		if((page+1)<pages) {
			page++;
			} else {
			page=0;
			}
		refresh();
		});
	}
	


//end document ready
});


jQuery(window).load(function(){
//landing images
if($("#feature").length) {
	$("#feature img:nth-child(3)").show().delay(1600).fadeOut("slow");
	$("#feature img:nth-child(2)").show().delay(3600).fadeOut("slow");
	$("#feature img:nth-child(1)").show().delay(6400);
	}
});


function showResponse(responseText, statusText, xhr, $form)  {  
	$("#Send").hide(); 
	$("#output").hide().fadeIn("slow");
}

function editResponse(responseText, statusText, xhr, $form)  {
	$("#output").hide().fadeIn("slow").delay(2000).fadeOut("slow");
}

function validate(formData, jqForm, options) { 
    var form = jqForm[0]; 
    if (!form.name.value) { 
        alert('Please fill out your name.'); 
        return false; 
    } else if (!form.email.value) {
        alert('Please fill out your email.'); 
        return false; 
    }
}

