/// <reference path="jquery-1.3.2-vsdoc.js" />
/// <reference path="jquery.validate.js" />
/// <reference path="forms.js" />

// JavaScript Document
var bMoreElements = true;
$(document).ready(function () {
    $("#div-carousel").show();
    jQuery('.jcarousel-skin-ie7').jcarousel({
        // Configuration goes here
        scroll: 4,
        wrap: 'last',
        itemLoadCallback: {
            onBeforeAnimation: mycarousel_itemLoadCallback
        }
    });
    
});

function mycarousel_itemLoadCallback(carousel, state) {
    //carousel.last = 4;
    //if (state == "init")
    //    return;

    var iLenght = $(carousel.list[0]).find("img").length;
    if (bMoreElements) {


        $.wsAjax({
            url: ("/services/UserService.asmx/GetNextTestimonies"),
            data: function () {
                return {
                    CurrentLenght: iLenght,
                    TestimonialIds: _testimonialIds
                }
            },
            success: function (result) {
                if (result.Status == 1) {
                    //OK
                    bMoreElements = result.bMoreElements;
                    if (result.items.length > 0) {
                        for (i = 0; i < result.items.length; i++) {
                            carousel.add(i + iLenght+ 1, result.items[i]);
                        }
                        //var iNewLenght = iLenght + result.items.length;
                        carousel.size($(carousel.list[0]).find("img").length);
                    }
                    else {
                        bMoreElements = false;
                    }
                }
                else {
                    //Error
                    alert("Uh oh, there was a problem.  " + result.Error);
                }
            }
        });
    }
    else {
        //carousel.size(28);
        //carousel.last = 4;
    }
}


function TogglePreview(id) {

    //$("#imgUpdateAd").show();
    if (id != '') {

        $("#p_Comment").text("");
        $("#h3_Author").text("");
        $("#img_PreviewImg").hide();
        $.wsAjax({
            url: ("/services/UserService.asmx/GetTestimonialInfo"),
            data: function () {
                return {
                    TestimonialId: id
                }
            },
            success: function (result) {
                //$("#imgUpdateAd").hide();
                if (result.Status == 1) {
                    //OK
                    $("#img_PreviewImg").show();
                    $("#p_Comment").text(result.Comment);
                    $("#h3_Author").text(result.Author + " writes:");
                    $("#img_PreviewImg").attr("src", "/testimonialImage/" + id + "/normal");

                    $('.ui-widget-overlay').toggle();
                    $('#FloatingPreview').toggle();
                    $('#FloatingPreviewShadow').toggle();
                }
                else {
                    //Error
                    alert("Uh oh, there was a problem.  " + result.Error);
                }
            }
        });
    }
    else {
        $('.ui-widget-overlay').toggle();
        $('#FloatingPreview').toggle();
        $('#FloatingPreviewShadow').toggle();
    }

    
    return false;
}


