
$(document).ready(function () {

    // SERVICE BOXES
    var max_height = 0;
    $("div.service.box").each(function () {
        if ($(this).height() > max_height) { max_height = $(this).height(); }
    });
    $("div.service.box").height(max_height);

    $(".service-box-icon").fadeTo(0, 0.7);

    $(".service-box").hover(
	function () {
	    $(this).find($(".service-box-icon")).stop(true, true).fadeTo(200, 1.0);
	},
	function () {
	    $(this).find($(".service-box-icon")).stop(true, true).fadeTo(100, 0.5);
	});

    $(".service-box").click(
	function () {
	    var isflipped = $(this).attr("isflipped");

	    if (isflipped == "Y") {

	        $(this).flip({
	            direction: "rl",
	            color: "#E3EAF2",
	            speed: 150,
	            onBefore: toggleSB($(this), "on")
	        });

	        $(this).attr("isflipped", "N");

	    } else {

	        $(this).flip({
	            direction: "lr",
	            color: "#D6DDE5",
	            speed: 150,
	            onEnd: toggleSB($(this), "off")
	        });

	        $(this).attr("isflipped", "Y");

	    }

	});

});

function toggleSB(box, mode) {
    if (mode == "on") {
        box.children(".service-box-on").css("display", "none");
        box.children(".service-box-off").css("display", "block");
    } else {
        box.children(".service-box-on").css("display", "block");
        box.children(".service-box-off").css("display", "none");
    }
}

