// JavaScript Document

$(document).ready(function() {


//FEEDBACK FORM -----------------------------------------------------------------------//
var feedback_form = 0;

//Toggle feedback w/sidetab
$("#feedback").click(function() {
	if (feedback_form == 0) {
		$("#feedback_form").fadeIn();
		$("#comments").focus();
		feedback_form = 1;
	} else {
		$("#feedback_form").fadeOut();
		feedback_form = 0;
	}
})

//Close feedback w/iconf
$("#feedback_close_icon").click(function() {
	$("#feedback_form").fadeOut();
	feedback_form = 0;
})

//BLOG PAGE ---------------------------------------------------------------------------//
$(".blogExcerpt").hover(function() {
	$(this).find("a").toggleClass("colorWhite");
})

$
$(".blogExcerpt").click(function() {
	location.href = $(this).find("a").attr("href");
})

$(".blogListItem").hover(function() {
	$(this).find("a").toggleClass("colorWhite");
})

$
$(".blogListItem").click(function() {
	location.href = $(this).find("a").attr("href");
})

$("#featuredPost .blogExcerpt:last").css("border-bottom","none");

//METHODOLOGY PAGE -------------------------------------------------------------------//
$("#methods_holder0").addClass("method_current");

$(".methods_holder").hover(function() {
	$(this).find("a").toggleClass("colorWhite");
})

$(".blogExcerpt").click(function() {
	location.href = $(this).find("a").attr("href");
})

$(".methods_holder").click(function() {
	methodology_select( $(this) );
	methodology_desc_select( $(this) );
})

function methodology_select(x) {
	if ( $(x).hasClass("method_current") ) {
		//do nothing
	} else {
		$(".methods_holder").removeClass("method_current");
		$(".methodologies").slideUp("fast");
		$(x).find(".methodologies").addClass("method_open").slideDown("fast");
		$(x).addClass("method_current");
	}
}

function methodology_desc_select(x) {
	if ( $(x).attr("id") == "methods_holder0" ) {
		methodology_close();
		$("#method_description0").fadeIn();
	} else if ( $(x).attr("id") == "methods_holder1" ) {
		methodology_close();
		$("#method_description1").fadeIn();	
	} else if ( $(x).attr("id") == "methods_holder2" ) {
		methodology_close();
		$("#method_description2").fadeIn();
	} else if ( $(x).attr("id") == "methods_holder3" ) {
		methodology_close();
		$("#method_description3").fadeIn();
	} else if ( $(x).attr("id") == "methods_holder4" ) {
		methodology_close();
		$("#method_description4").fadeIn();
	} else if ( $(x).attr("id") == "methods_holder5" ) {
		methodology_close();
		$("#method_description5").fadeIn();
	} else if ( $(x).attr("id") == "methods_holder6" ) {
		methodology_close();
		$("#method_description6").fadeIn();
	} else if ( $(x).attr("id") == "methods_holder7" ) {
		methodology_close();
		$("#method_description7").fadeIn();
	}
}

function methodology_close() {
	$(".method_description").hide();	
}

//PHP AJAX Mailer
// The relative URL of the submit.php script.
    // You will probably have to change it.
    var submitURL = 'submit.php';

    // Caching the feedback object:
    var feedback = $('#feedback_form');

    $('#feedback_form a.submit').live('click',function(){
        var button = $(this);
        var textarea = feedback.find("#commentArea");
		var emailaddy = feedback.find("#email");
		var sendersname = feedback.find("#name");

        // We use the working class not only for styling the submit button,
        // but also as kind of a "lock" to prevent multiple submissions.

        if(button.hasClass('working') || textarea.val().length < 5){
            return false;
        }

        // Locking the form and changing the button style:
        button.addClass('working');

        $.ajax({
            url     : submitURL,
            type    : 'post',
            data    : { message : textarea.val(), email : emailaddy.val(), sender : sendersname.val()},
            complete    : function(xhr){

                var text = xhr.responseText;

                // This will help users troubleshoot their form:
                if(xhr.status == 404){
                    text = 'Your path to submit.php is incorrect.';
                }

                // Hiding the button and the textarea, after which
                // we are showing the received response from submit.php

                button.fadeOut();
				
                $('#feedback_items').fadeOut(function(){
                    var span = $('<span>',{
                        className    : 'response',
                        html        : text
                    })
                    .hide()
                    .appendTo(feedback.find('.section'))
                    .show();
                }).val('');
            }
        });

        return false;
    });
	
//FOOTER FEATURE HEIGHT -------------------------------------------------------------------//
var featureHt = $(".feature").first().height();
$(".feature").each(function() {
	if ( $(this).height() > featureHt) {
		featureHt = $(this).height();
	}
})
$("#footer_features .feature").css("height",featureHt);

//DUAL FEATURES HEIGHT
var dualFeatureHt = $(".dual_feature").first().height();
$(".dual_feature").each(function() {
	if ( $(this).height() > dualFeatureHt) {
		dualFeatureHt = $(this).height();
		$(".dual_feature").each(function() {
			$(this).height(dualFeatureHt);								 
		})
	} else {
		$(this).height(dualFeatureHt);
	}
})

})
