﻿var loaded = 0;
var runLeftIntervalId;

$(document).ready(function() {

    var soapEnv =
        "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
                <soapenv:Body> \
                     <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                        <listName>" + $("#listName").val() + "</listName> \
                        <viewFields> \
                            <ViewFields> \
                               <FieldRef Name='Title' /> \
                               <FieldRef Name='VCard' /> \
                           </ViewFields> \
                        </viewFields> \
                    </GetListItems> \
                </soapenv:Body> \
            </soapenv:Envelope>";
    if (loaded == 0) {
        $.ajax({
        url: $("#listUrl").val()+"/_vti_bin/lists.asmx",
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: processResult,
            contentType: "text/xml; charset=\"utf-8\""
        });
        loaded = 1;
    }


});

function processResult(xData, status) {
    SetupContactSlider($(xData.responseXML).find("z\\:row").length);

    $(xData.responseXML).find("z\\:row").each(function() {
        var liHtml = $(this).attr("ows_VCard");
        try 
        {
            lcid = getCookie('lcid');
            if (lcid != null && lcid != "" && lcid == "latn") {
                liHtml = CirToLat(liHtml);

            }
        }
        catch (err) { }
        $("#ContactSlider").append(liHtml.substring(liHtml.indexOf('>') + 1, liHtml.lastIndexOf('<')));

    });
    runLeftIntervalId = setInterval("runLeft()", 9000);
    $("#contactRotator").mouseover(function() { clearTimeout(runLeftIntervalId); });
    $("#contactRotator").mouseout(function() { runLeftIntervalId = setInterval("runLeft()", 9000); });
}








var ContactSliderLimit;

function SetupContactSlider(contactCount) {
    ContactContainerWidth = $("#ContactContainer").width();

    $("#ContactSlider").css("width", (contactCount + 1) * ContactContainerWidth);
    if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
        $("#ContactSlider").css("width", (contactCount + 1) * ContactContainerWidth + 15);
    }


    ContactSliderLimit = contactCount * ContactContainerWidth;


}

function runLeft() {
    var currentLeft = -($("#ContactSlider").css("left").toString().replace('px', ''));
    if (currentLeft >= ContactSliderLimit) {
        $("#ContactSlider").animate({ left: '0' }, 2000, "easeInOutBack");
    } else {
        $("#ContactSlider").animate({ left: '-=290' }, 2000, "easeOutBack");
        $("#goRight").css("display", "block");
    }



}
function runRight() {
    var currentLeft = ($("#ContactSlider").css("left").toString().replace('px', ''));
    if (currentLeft >= 0) {
        $("#goRight").css("display", "none");
    } else {
        $("#ContactSlider").animate({ left: '+=290' }, 2000, "easeInOutBack");
        $("#goLeft").css("display", "block");
    }
}

