﻿var currentGalleryItem = 1;
var totalGalleryItems = 3;
var galleryInterval;
var galleryDuration = 10000;
function ShowCurrent(cont) {
    $(".galleryItem").hide();
    clearTimeout(galleryInterval);
    $(".galleryButton").removeClass("galleryButtonSelected");
    $("#galleryButton" + currentGalleryItem).addClass("galleryButtonSelected");
    $("#gallery" + currentGalleryItem).css('filter', 'none');
    $("#gallery" + currentGalleryItem).fadeTo("slow", 1.0, function () {
        $("#gallery" + currentGalleryItem).css('filter', 'none');
        if (cont) {
            galleryInterval = setTimeout(ShowNext, galleryDuration);
        }
    });
    $("#gallery" + currentGalleryItem).css('filter', 'none');
}
function ShowNext() {
    $("#gallery" + currentGalleryItem).fadeTo("slow", 0.0, function () {
        currentGalleryItem++;
        if (currentGalleryItem > totalGalleryItems) {
            currentGalleryItem = 1;
        }
        ShowCurrent(true);
    });
}
$(document).ready(function () {
    $(".menuItem").mouseover(function () { $("#" + this.id).addClass("menuItemSelected"); });
    $(".menuItem").mouseout(function () { $("#" + this.id).removeClass("menuItemSelected"); });
    $("#how").css("margin-right", "30px");
    $("#here").css("margin-right", "30px");
    $(".galleryButton").click(function () {
        var id = this.id;
        id = id.replace("galleryButton", "");
        currentGalleryItem = parseInt(id);
        ShowCurrent(false);
    });
    ShowCurrent(true);
    $(".menuItem").addClass("hand");
    $(".menuItem").click(function () { var id = this.id.replace("menu", ""); location = '/' + id; });
    $("#login").click(function () { 
        location = '/login';
    });
    /*positionFooter();
    $(window)
		.resize(positionFooter);*/

});
function positionFooter() {
        /*var padding_top = $("#footer").css("margin-top").replace("px", "");
        var page_height = $(document.body).height() - padding_top;
        var window_height = $(window).height();
        var difference = window_height - page_height;
        if (difference < 0)
        difference = 0;

        $("#footer").css({
        margin: difference + "px 0 0 0"
        })*/
        $("#footer").hide();
        $("#footer").css("position", "absolute");

        $("#footer").css("top", $(document.body).height() + "px");
        $("#footer").width($("#header").width());
        $("#footer").show();
    }

function alertValidationError(id, text) {
    var div = "<div class='validation'>* " + text + "</div>";
    $("#"+id).after(div);
}
function validateNotEmpty(id) {
    var obj = $("#" + id);
    if (obj == null) {
    }
    else {
        var v = obj.val();
        if ((v == null) || (v == "")) {
            alertValidationError(id, "required");
            flag = false;
        }
    }
}
function validatePhone(id) {
    var phoneExpression = /^([0-9])+$/;
    var o = document.getElementById(id);
    if (o != null) {
        if ((o.value == null) || (o.value == "")) {
            alertValidationError(id, "required");
            flag = false;
        }
        else {
            if (o.value.search(phoneExpression) == -1) //if match failed
            {
                alertValidationError(id, "phone not valid");
                flag = false;
            }
        }
    }
}

function validateEmail(id) {
    var emailExpression = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var o = document.getElementById(id);
    if (o != null) {
        if ((o.value == null) || (o.value == "")) {
            alertValidationError(id, "required");
            flag = false;
        }
        else {
            if (o.value.search(emailExpression) == -1) //if match failed
            {
                alertValidationError(id, "email not valid");
                flag = false;
            }
        }
    }
}
var flag;
function validateFile(id) {
    var obj = $("#" + id);
    if (obj == null) {
    }
    else {
        var v = obj.val();
        if ((v == null) || (v == "")) {
            alertValidationError(id, "required");
            flag = false;
        }
        else {
            var index = v.lastIndexOf(".");
            var ending = (/[.]/.exec(v)) ? /[^.]+$/.exec(v)[0] : "";
            switch (ending.toLowerCase()) {
                case "pdf":
                case "doc":
                case "docx":
                case "rtf":
                case "jpg":
                case "jpeg":
                case "gif":
                case "bmp":
                case "png":
                    {
                        break;
                    }
                default:
                    {
                        alertValidationError(id, "illegal file type");
                    }
            }
        }
    }
}
function validateContact() {
    flag = true;
    $(".validation").remove();
    validateNotEmpty("name");
    validateEmail("email");
    validateNotEmpty("subject");
    validateNotEmpty("msg");
    return flag;
}
function validateApply() {
    flag = true;
    $(".validation").remove();
    validateNotEmpty("fname");
    validateNotEmpty("lname");
    validateEmail("email");
    validatePhone("phone");
    validateFile("resume");
    return flag;
}
function validateLogin() {
    flag = true;
    $(".validation").remove();
    validateNotEmpty("username");
    validateNotEmpty("password");
    return flag;
}
