﻿$(document).ready(function () {

    //NEWS TICKER
    var news = [
        "Read Avco's latest project news on: Demonstrating Industrial Symbiosis (IS) through Semantic Web technologies: an EC-funded project",
		"Free Business Consultation: Let Avco offer you free business consultation to validate your idea’s viability before you commit it to code.",
        "AnyComms Plus: See our famed automated file transfer application in action."
    ];
    var seperatorLength = 25;
    $(".marquee").html(news.join(Array(seperatorLength).join("&nbsp;")));
    $("marquee").marquee("marquee");


    //SITE NAVIGATION
    $("#navigation").hover(null, reset);
    $(".menuLevel1").hover(showSubMenu, null);

    function showSubMenu() {
        reset();

        this.children[0].className = "highlight";

        var subMenuID = this.id + "Sub";
        var subMenuItem = $("#" + subMenuID);
        if (subMenuItem.length) {
            subMenuItem.show();
        }
    }

    function reset() {
        $(".menuLevel1").children().each(function () {
            this.className = ''
        });

        $(".subMenu").hide();
    }


    //CONTACT US PAGE
    $("input[name='nature_of_enquiry']").change(function () {
        if (this.id == "examRadio") {
            $(".exam").show();
        } else {
            $(".exam").hide();
        }
    });

    $("#contactSubmit").click(function (e) {
        var validates = true;
        var radioSelected = false;
        var elements = $("#contactForm :input");
        for (var i = 0; i < elements.length; i++) {
            var el = elements[i];
            switch (el.type) {
                case "text":
                case "textarea":
                    if (el.value == '') {
                        validates = false;
                    }
                    break;
                case "radio":
                    if (!radioSelected) {
                        radioSelected = el.checked;
                    }
                    break;
            }
        }

        if (validates) {
            validates = radioSelected;
        }

        if (!validates) {
            e.preventDefault();
            $(".message").html('Please complete all fields');
        }
    });

});
