var imageFlowHomePage = new ImageFlow();
var homePageGalleryJsonUrl = "/Sites/TheKnotChina/PhotoGalleryHandler.ashx?action=gethomepagephotogallery";
var imageFlow_Count = 0;
$("#imageflow").ready(function() {
    _start = 0;
    _size = 11;

    $.getJSON(
            homePageGalleryJsonUrl,
            { start: _start, size: _size },
            function(data) {
                var galleryId = data.galleryId;
                var obj = $("#imageflow");
                var json = data.photos;
                $.each(json, function(i) {
                    imageFlow_Count++;
                    obj.append("<img src=\"" + json[i].Src + "\" longdesc=\"" + imageFlow_Count + "\" width=\"80\" height=\"70\" id=\"" + json[i].Id + "\" alt=\"" + json[i].Alt + "\" title=\"" + json[i].Title + "\" />");
                });

                ImageFlow_HomePage_Init(galleryId);
                if (imageFlow_Count >= _size) {
                    imageFlowHomePage.isEnd = false;
                } else {
                    imageFlowHomePage.circular = true;
                }
            }
        );
});
    function ImageFlow_HomePage_Init(galleryId) {
        imageFlowHomePage.init({ ImageFlowID: 'imageflow',
            startID: 6,
            reflections: false,
            slider: false,
            captions: false,
            imageFocusMax: 3,
            circular: false,
            imageFocusM: 1.2,
            imagesHeight: 0.3,
            imagesM: 0.9,
            onClick: function() {
                window.open("Gallery.aspx?gallery_id=" + galleryId + "&photo_id=" + this.id + "&index=" + this.url);
            }
        });
    }
    function HomePage_Pre_onClick() {
        imageFlowHomePage.MouseWheel.handle(1);

    }
    function HomePage_Next_onClick() {
        imageFlowHomePage.MouseWheel.handle(-1);
        
    }
    function LoadingMoreImage(_start) {
        _size = 1000;
        imageFlowHomePage.newAddCount = 0;
        $.getJSON(
            homePageGalleryJsonUrl,
            { start: _start, size: _size },
            function(data) {
                var galleryId = data.galleryId;
                var obj = $("#imageflow_images");
                var json = data.photos;
                $.each(json, function(i) {
                    imageFlow_Count++;
                    obj.append("<img src=\"" + json[i].Src + "\" longdesc=\"" + imageFlow_Count + "\" width=\"80\" height=\"70\" id=\"" + json[i].Id + "\" alt=\"" + json[i].Alt + "\" title=\"" + json[i].Title + "\" />");
                    imageFlowHomePage.newAddCount++;
                });
                if (imageFlowHomePage.newAddCount >= _size) {
                    imageFlowHomePage.isEnd = false;
                } else {
                    for (var i = 0; i < (imageFlowHomePage.imageFocusMax * 2); i++) {
                        obj.append(obj.children("img").eq(i).clone(true).removeAttr("style"));
                        imageFlowHomePage.newAddCount++;
                    }
                    imageFlowHomePage.circular = true;                    
                }

                imageFlowHomePage.refresh();

            }
        );
    }
        
