﻿var Blogposition = 0;
var BlogElementWidth = 225;
window.addEvent('domready', function () {
    AddHooks();

    $$(".MaritimeSecurity").setStyle('opacity', '0.1');
    $$(".homeMooContentItem").setStyle('opacity','0');
    $$(".homeMooContentItem:nth-child(first)").setStyle('opacity', '1');
    var thumbs = $$("#menu li");
    thumbs.each(function (e, i) {
        e.addEvent("mouseenter", function () {
            $('HomeMooContent').getChildren().each(function (e2, i2) {
                if (i == i2) {
                    e2.morph({ 'opacity': '1' });

                }
                else {
                    e2.morph({ 'opacity': '0' });
                }
            });
        });
    });



    // Call me Back Form Starts here
    $("YourMessage").addEvent("focus", function () {
        if ($("YourMessage").getProperty("value") == "") {
            $("YourMessage").setProperty("value", "");
            $$(".messageValidate").morph({ left: "-79px", "background-color": "#9C1F31" });

            if ($("telephone").getProperty("value") != "") {
                $$(".messageValidate").setStyle("z-index", "-1");
            }
            if ($("telephone").getProperty("value") == "") {
                $$(".messageValidate").setStyle("z-index", "1");
            }
        }
    });

    $$('.messageValidate').addEvent("click", function () {

        $$(".messageValidate").morph({ left: "-85px" });
        $("YourMessage").focus();
    });

    $("YourMessage").addEvent("blur", function () {
        if ($("YourMessage").getProperty("value") == "") {
            $("YourMessage").setProperty("value", "");
            $$(".messageValidate").morph({ left: "5px", "background-color": "#000000" });
        }
    });

    $('YourMessage').addEvent("click", function () {

        $$(".telephoneValidate").setStyle("z-index", "1");

        if ($("telephone").getProperty("value") != "") {
            $$(".telephoneValidate").setStyle("z-index", "-1");
        }
    });
    $$('.addressValidate').addEvent("click", function () {

        $$(".addressValidate").morph({ left: "-44px" });
        $("YourMessage").focus();
    });

    $("telephone").addEvent("focus", function () {
        if ($("telephone").getProperty("value") == "") {
            $("telephone").setProperty("value", "");
            $$(".telephoneValidate").morph({ left: "-44px", "background-color": "#9C1F31" });

            if ($("emailAddress").getProperty("value") != "") {
                $$(".emailValidate").setStyle("z-index", "-1");
            }
            if ($("emailAddress").getProperty("value") == "") {
                $$(".emailValidate").setStyle("z-index", "1");
            }
        }
    });

    $("telephone").addEvent("blur", function () {
        if ($("telephone").getProperty("value") == "") {
            $("telephone").setProperty("value", "");
            $$(".telephoneValidate").morph({ left: "5px", "background-color": "#000000" });
        }
    });
    $('telephone').addEvent("click", function () {

        $$(".telephoneValidate").setStyle("z-index", "1");

        if ($("emailAddress").getProperty("value") != "") {
            $$(".emailValidate").setStyle("z-index", "-1");
        }
    });
    $$('.telephoneValidate').addEvent("click", function () {

        $$(".telephoneValidate").morph({ left: "-44px" });
        $("telephone").focus();
    });


    $("emailAddress").addEvent("focus", function () {
        if ($("emailAddress").getProperty("value") == "") {
            $("emailAddress").setProperty("value", "");
            $$(".emailValidate").morph({ left: "-44px", "background-color": "#9C1F31" });

            if ($("fullName").getProperty("value") != "") {
                $$(".nameValidate").setStyle("z-index", "-1");

            }
            if ($("fullName").getProperty("value") == "") {
                $$(".nameValidate").setStyle("z-index", "1");
            }
        }
    });

    $("emailAddress").addEvent("blur", function () {
        if ($("emailAddress").getProperty("value") == "") {
            $("emailAddress").setProperty("value", "");
            $$(".emailValidate").morph({ left: "5px", "background-color": "#000000" });
        }
    });
    $('emailAddress').addEvent("click", function () {

        $$(".emailValidate").setStyle("z-index", "1");

        if ($("fullName").getProperty("value") != "") {
            $$(".nameValidate").setStyle("z-index", "-1");
        }
    });
    $$('.emailValidate').addEvent("click", function () {

        $$(".emailValidate").morph({ left: "-44px" });
        $("emailAddress").focus();
    });

    $("fullName").addEvent("focus", function () {
        if ($("fullName").getProperty("value") == "") {
            $("fullName").setProperty("value", "");
            $$(".nameValidate").morph({ left: "-44px", "background-color": "#9C1F31" });
        }
    });

    $("fullName").addEvent("blur", function () {
        if ($("fullName").getProperty("value") == "") {
            $("fullName").setProperty("value", "");
            $$(".nameValidate").morph({ left: "5px", "background-color": "#000000" });
        }

        $('fullName').addEvent("click", function () {

            $$(".nameValidate").setStyle("z-index", "1");
        });
    });
    $$('.nameValidate').addEvent("click", function () {

        $$(".nameValidate").morph({ left: "-44px" });
        $("fullName").focus();
    });

    $('contactSubmit').addEvent("click", function () {
        return ValidateForm();
    });

});


function ValidateForm() {
    var msg = "";
    //alert(msg);

    if ($("YourMessage").getProperty("value") == "" || $("telephone").getProperty("value") == "") {

        $("YourMessage").focus();
        $("YourMessage").morph({ "background-color": ["#9c1f31", "#ffffff"] });
        msg = msg + "You must enter a phone number\n"
    }



    if ($("telephone").getProperty("value") == "" || $("telephone").getProperty("value") == "") {

        $("telephone").focus();
        $("telephone").morph({ "background-color": ["#9c1f31", "#ffffff"] });
        msg = msg + "You must enter a phone number\n"
    }

    if ($("emailAddress").getProperty("value") == "" || $("emailAddress").getProperty("value") == "") {

        $("emailAddress").focus();
        $("emailAddress").morph({ "background-color": ["#9c1f31", "#ffffff"] });
        msg = msg + "You must enter an email address\n"
    }

    if ($("fullName").getProperty("value") == "" || $("fullName").getProperty("value") == "") {

        $("fullName").focus();
        $("fullName").morph({ "background-color": ["#9c1f31", "#ffffff"] });
        msg = msg + "You must enter your name\n"
    }

    if (msg.length > 0) {
        //alert(msg);
        return false;
    }

    return true;
}



function AddHooks() {
    $('BlogNextLink').addEvent("click", function () {
        Blogposition++;

        // Hide Button If Needed
        if (Blogposition == $$(".BlogPostGadget").length - 1) {
            $('BlogNextLink').setStyle("opacity", 0);
        }

        // Show Back Button If Needed
        if (Blogposition > 0) {
            $('BlogBackLink').setStyle("opacity", 1);
        }

        $('BlogInnerMover').morph({ "left": -BlogElementWidth * Blogposition });
    });

    $('BlogBackLink').setStyle("opacity", 0);

    $('BlogBackLink').addEvent("click", function () {
        Blogposition--;

        // Hide Button If Needed
        if (Blogposition == 0) {
            $('BlogBackLink').setStyle("opacity", 0);
        }

        // Show Back Button If Needed
        if (Blogposition < $$(".BlogPostGadget").length - 1) {
            $('BlogNextLink').setStyle("opacity", 1);
        }

        $('BlogInnerMover').morph({ "left": -BlogElementWidth * Blogposition });

    });
}
