/**
 * @author Zane DeBusk (PLS Creative Solutions)
 * 
 */

jQuery(document).ready(function($){
	// set target for footer expansion
    var targetOffset = $("#footer-container").offset().top;
	// enable footer activation button
    $("#sitemap-nubbin").removeClass("disabled");
	// hide footer
    $("#footer-container").css("display", "none");
	// footer expansion button click handler
    $("#sitemap-nubbin").click(function(){
        $(this).toggleClass("on");
        $("#footer-container").slideToggle(400);
        $("html,body").animate({
            scrollTop: targetOffset
        }, 400);
    });

	// activate javascript slideshow
	$("#content-mast").removeClass("static");
	
	// replace form buttons with styled links -- submission via javascript
    $("button").hide();
    $(".button").show();
	
	// register global button link event handler to submit forms
	$(".button").click(function() {
		$(this).parents("form").trigger("submit");
	});
	
    function ajaxLogin(action, inputs){
        jQuery.ajax({
            type: "GET",
            url: action,
            timeout: 2000,
            dataType: "html",
            data: "ajax=1&" + inputs,
            error: function(){
                alert("FAILURE");
            },
            success: function(resp){
				resp = $.trim(resp);
                if (resp == "failed") {
					$("#user-tag").animate({
						marginTop: "-10px"
					}, "fast", function() {
						$("#user-tag").html("Login Failed");
						$("#user-tag").animate({
							marginTop: "5px"
						}, "fast");
					});
				} else {
					$("#user-block").fadeOut("1500", function(){
                        $("#user-block").html(resp);
                        $("#user-block").fadeIn("fast");
                    });
				}
            }
        });
    }
	
	$("#login-form").submit(function() {
		ajaxLogin(this.action, $("#login-form").serialize());
		return false;
	});
});
