﻿$(document).ready(function () {
    LoadClientNav();
    PrepButtons();

    $('#Soft').click(
        function () {
            $('#DeliveryInformation').animate({ 'left': 0 }, 600, 'swing');
        });
    $('#Hosting').click(
        function () {
            $('#DeliveryInformation').animate({ 'left': -705 }, 600, 'swing');
        });
    $('#PC').click(
        function () {
            $('#DeliveryInformation').animate({ 'left': -1410 }, 600, 'swing');

        });

    moveDiv('home');

});

function FadeContent() {
    $('#PortfolioContent').stop().animate({
        'opacity': 0
    }, 200)
}
function ShowContent() {
    $('#PortfolioContent').stop().animate({
        'opacity': 1
    }, 200)
}
function PrepButtons() {
    $('.PortfolioBreadCrumbs').hover(function () {
        var position = $(this).position();
        $(this).css('background-color', '#53b7e5');
        $('#HoverBarText').html($(this).attr("rel"));
        // Stuff that happens when you hover on + the stop()
        $('.HoverBar').stop().animate({
            'left': position.left - ($('.HoverBar').width() / 2) + 13
        }, 1, function () {
            $('.HoverBar').css('top', position.top - 40);
            $('.HoverBar').animate({
                'opacity': 1
            }, 500);
        })
    }, function () {
        // Stuff that happens when you unhover + the stop()
        $(this).css('background-color', '#3a81a2');
        $('.HoverBar').stop().animate({
            'opacity': 0
        }, 1, function () { $('.HoverBar').css('left', -300); })
    });
};

function mycarousel_initCallback(carousel) {
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function () {
        carousel.stopAuto();
    }, function () {
        carousel.startAuto();
    });
};

function PageResize() {
    $('.divposition').each(
                function (i) {
                    var offset = $(this).position();
                    var x = offset.left;
                    if (x > -1) {
                        $(this).animate({ 'left': $('#ContentDiv').offset().left });
                    }
                }
            );
};
function moveDiv(div, btn) {
    $('.MenuSelected').removeClass('MenuSelected');
    $('#' + btn).addClass('MenuSelected');
    var x = $('#' + div).offset();
    if (x.left < 0) {
        animateDiv(div);
    }
    else {
        returnDiv('#' + div);
    }
    ReturnOtherDiv(div);
}

function returnDiv(object) {
    $(object).animate({ 'opacity': 0 }, 500);
    $(object).animate({ 'left': -1000 }, 100);
}

function animateDiv(object) {
    var item = '#' + object;
    var leftoff = $('#ContentDiv').offset();
    $(item).animate({ 'left': leftoff.left }, 100, function () { $(item).animate({ 'opacity': 1 }); });
}

function ReturnOtherDiv(item) {
    $('.divposition').each
            (
                function (i) {
                    if ($(this).attr("ID") != $('#' + item).attr("ID")) {
                        returnDiv(this);
                    }
                }
            );
}
function resetDivs() {
    $('.divposition').each
            (
                function (i) {
                    returnDiv(this);
                }
            );
};
function LoadClientDetails(ClientID) {

    $("#PortfolioContent").empty();

    $("#PortfolioContent").append("<img style='position:relative;top:200px' src='Images/loading.gif' alt='Loading' />");

    CallPageMethod("GetClientDetails", function (data) {
        $("#PortfolioContent").empty();
        var k = 0;

        for (k = 0; k < data.length; k = k + 1) {

            var strTechnologies = ""
            
            var TechArray = data[k].Technologies;

            var j = 0;
            for (j = 0; j < TechArray.length; j = j + 1) {
                strTechnologies += " - " + TechArray[j].Name + "<br/>";
            }

            $("#PortfolioContent").append("<table style='text-align:left'><tr><td><img class='reflect' style='margin-right:5px;' align='left' src='" + data[k].ImageURL + "' alt='" + data[k].Name + "' />" +
                                "</td><td><h1><a href='" + data[k].URL + "' target='_blank'>" + data[k].Name + "</a></h1>" +
                            "<h3>Status:</h3>" + data[k].Status + "<h3>Technologies:</h3>" + strTechnologies +
                            "<h3>Description:</h3>" + data[k].Description + "</td></tr></table>");
        }

        PrepButtons();
        ShowContent();
        $('.reflect').reflect();
    }, "clientID", ClientID.toString());
}

function LoadClientNav() {
    CallPageMethod("GetClientIDs", function (data) {
        var k = 0;

        for (k = 0; k < data.length; k = k + 1) {

            $("#divClientNav").append("<div OnClick='javascript:LoadClientDetails(" + data[k].ID + ")' rel='" + data[k].Name + "' id='PortFolioBreadCrumbs" + data[k].ID + "' class='PortfolioBreadCrumbs'></div>");
        }

        PrepButtons();

    });
}

function SendMail() {
    var Email = "";
    var Name = "";
    var Message = "";

    $("#divSendMailLoading").empty();

    $("#divSendMailLoading").append("<img src='Images/loading.gif' alt='Loading' />");

    $("#divTestFilterResults").empty();
    $("#divTestFilterResults").append("loading...");

    Email = Encoder.htmlEncode($("#txtEmail").val())
    Email = Email.replace(/\\/g, "\\\\");
    Name = Encoder.htmlEncode($("#txtName").val())
    Name = Name.replace(/\\/g, "\\\\");
    Message = Encoder.htmlEncode($("#txtMessage").val())
    Message = Message.replace(/\\/g, "\\\\");

    CallPageMethod("SendEmail", function (data) {
        $("#divSendMailLoading").empty();

        var k = 0;
        for (k = 0; k < data.length; k = k + 1) {
            $("#divSendMailLoading").append(data[k].Result);
        }

        $("#txtEmail").val('');
        $("#txtName").val('');
        $("#txtMessage").val('');
    }, "email", Email, "name", Name, "message", Message);
}
