var TRANSITION_DELAY = 400; var ENTRY_DELAY = 600; var SPONSORSHIP_TYPE = ""; var visibleBuffersPointer = 1; var lastJSON = null; var myEasing = "easeOutQuad"; var tto; var raceTrap = 0; var formDataTemplate = '<input name="VariantStyle_pid_vid" id="VariantStyle_pid_vid" type="hidden" value="0">'; formDataTemplate += '<input name="IsWishList_pid_vid" id="IsWishList_pid_vid" type="hidden" value="0">'; formDataTemplate += '<input name="IsGiftRegistry_pid_vid" id="IsGiftRegistr_pid_vid" type="hidden" value="0">'; formDataTemplate += '<input type="hidden" name="UpsellProducts_pid_vid" id="UpsellProducts_pid_vid" value="">'; formDataTemplate += '<input type="hidden" name="CartRecID_pid_vid" id="CartRecID_pid_vid" value="0">'; formDataTemplate += '<input type="hidden" name="ProductID_pid_vid" id="ProductID_pid_vid" value="pid">'; formDataTemplate += '<input type="hidden" name="PackID" id="PackID" value="0">'; formDataTemplate += '<input type="hidden" name="VariantID_pid_vid" id="VariantID_pid_vid" value="vid">'; formDataTemplate += '<input type="hidden" name="Quantity_pid_vid" id="Quantity_pid_vid" value="1">'; formDataTemplate += ""; $(document).ready(function () { $(".page-item-8").addClass("current_page_item"); $("#children_wrapper > .items").empty(); for (var a = 0; a < 3; a++) { insertChildHTML() } $("#children_wrapper").append("<img class='loading' src='loading.gif' rel='Loading...' />"); $("#children_wrapper .items").css("left", "624px"); unbindNavigation(); if (countryID != null && countryID.length == 2) { navigate(firstSelectCountry, "HelloChild") } else { navigate(finishInitialization, "HelloChild") } $("#country, #gender, #age, #schoolOrChildNumber").keypress(function (b) { if (b.which == 13) { b.preventDefault; $("#search_submit").click(); return false } }) }); $("div.sponsor a").live("click", function (f) { unbindNavigation(); $("div.sponsor a").die(); var b = ($("div.sponsor a").index(this) % 6) - 1; if (b == -1) { b = 3 } if (b == 4) { b = 0 } var a = lastJSON.d["bufferedChildData"][b]["name"]; var d = lastJSON.d["bufferedChildData"][b]; var c = d.ProductID; var h = d.VariantID; var e = "0_" + c + "_" + h; var g = formDataTemplate.replace(/pid/g, c).replace(/vid/g, h); $("#aspnetForm").append(g); __doPostBack("AddToCart", e) }); $.fn.imagesLoaded = function (c) { var a = this; var b = setInterval(function () { var d = true; a.each(function () { d = d && this.complete }); if (d) { clearInterval(b); c.call(a) } }, 200); return this }; function childImagesLoaded(a) { $('.items img[src$=".jpg"]').imagesLoaded(a) } jQuery.easing.jswing = jQuery.easing.swing; jQuery.extend(jQuery.easing, { def: "easeOutQuad", swing: function (e, f, a, h, g) { return jQuery.easing[jQuery.easing.def](e, f, a, h, g) }, easeInQuad: function (e, f, a, h, g) { return h * (f /= g) * f + a }, easeOutQuad: function (e, f, a, h, g) { return -h * (f /= g) * (f - 2) + a }, easeInOutQuad: function (e, f, a, h, g) { if ((f /= g / 2) < 1) { return h / 2 * f * f + a } return -h / 2 * ((--f) * (f - 2) - 1) + a } }); function insertChildHTML() { $("#children_wrapper > .items").prepend("<div class='child'><div><img /></div><div class='sponsor'><a>Sponsor this child</a></div><div class='name'></div><p> from <strong></strong></p><p></p></div>") } function finishInitialization(b) { clearTimeout(tto); for (var a = 0; a < 3; a++) { populateChild(lastJSON, a, 1) } for (a = 0; a < 4; a++) { populatePopup(lastJSON, a, 0) } tto = setTimeout(function () { transactionTimeout2() }, 60000); childImagesLoaded(finishInitialization1) } function finishInitialization1() { clearTimeout(tto); $("#children_wrapper .loading").remove(); $("#children_wrapper .items").animate({ left: "0px" }, ENTRY_DELAY, myEasing, function () { setupScrolling(lastJSON) }); $("#resultInfo").text(" " + lastJSON.d["displayMessage"] + " ") } function firstSelectCountry() { clearTimeout(tto); tto = setTimeout(function () { transactionTimeout2() }, 60000); $.ajax({ type: "POST", url: "/LaccService.svc/ChildSearch", data: '{"request":{"CountryNumber": "' + countryID + '", "Gender": "", "AgeGroup": "", "SchoolOrChildNumber": "", "SponType": "' + SPONSORSHIP_TYPE + '"}}', contentType: "application/json; charset=utf-8", dataType: "json", processdata: true, cache: false, success: function (a) { lastJSON = a; finishInitialization(a) }, error: serviceFailed }) } function setupScrolling(a) { $("#children_wrapper .items").css("left", "624px"); insertChildHTML(); populateChild(a, 0, 0); $("#scrolly").scrollable({ circular: true, speed: TRANSITION_DELAY }); $("#children_wrapper").scrollable({ size: 2, clickable: false, circular: true, initialIndex: 3, speed: TRANSITION_DELAY, easing: myEasing }).find("img").each(function (b) { $(this).overlay({ effect: "apple", target: "#c1", mask: { maskId: "mask" }, onBeforeLoad: function () { var c = 650 * (b); $("#scrolly .items").css("left", "-" + c + "px"); unbindNavigation() }, onLoad: function () { if (b == 0) { b = 3 } if (b == 5) { b = 0 } $("#scrolly").data("scrollable").seekTo(b - 1, 0); bindNavigation() } }) }); $("#search_submit").click(function () { unbindNavigation(); $("#children_wrapper *").unbind(); $("#search_submit").unbind(); $("#children_wrapper").removeData("scrollable"); $("#scrolly").removeData("scrollable"); $("#children_wrapper > .items").empty().css("left", "624px"); $(".cloned").remove(); for (var c = 0; c < 3; c++) { insertChildHTML() } $("#children_wrapper").append("<img class='loading' src='loading.gif' rel='Loading...' />"); var f = $("#country").val(); var b = $("#age").val(); var e = $("#gender").val(); var d = $("#schoolOrChildNumber").val(); tto = setTimeout(function () { transactionTimeout2() }, 60000); $.ajax({ type: "POST", url: "/LaccService.svc/ChildSearch", data: '{"request":{"CountryNumber": "' + f + '", "Gender": "' + e + '", "AgeGroup": "' + b + '", "SchoolOrChildNumber": "' + d + '", "SponType": "' + SPONSORSHIP_TYPE + '"}}', contentType: "application/json; charset=utf-8", dataType: "json", processdata: true, cache: false, success: function (g) { lastJSON = g; finishInitialization(g) }, error: serviceFailed }); $("#search select").each(function () { this.selectedIndex = 0 }); $(".lookup input[type=text]").val("") }); visibleBuffersPointer = 1; $("#children_wrapper").data("scrollable").seekTo(1, 0); $("#scrolly").data("scrollable").seekTo(1, 0); refreshCarouselClones(); unbindNavigation(); bindNavigation(); if (lastJSON.d["bufferedChildData"][1]["orderIndex"] == 0) { $("#children_wrapper img").eq(2).trigger("click", "") } } function navigate(b, a) { tto = setTimeout(function () { transactionTimeout2() }, 60000); $.ajax({ type: "GET", url: "/LaccService.svc/" + a, data: { sponType: SPONSORSHIP_TYPE }, contentType: "application/json; charset=utf-8", dataType: "json", processdata: true, cache: false, success: function (c) { lastJSON = c; b(c) }, error: serviceFailed }) } function populateChild(b, a, d) { var c = b.d["bufferedChildData"][a + d]; if (c.orderIndex < 1000000) { $("#children_wrapper .child:eq(" + a + ") img").addClass("match") } else { $("#children_wrapper .child:eq(" + a + ") img").removeClass("match") } $("#children_wrapper .child:eq(" + a + ")").children(".name").text(c.name); $("#children_wrapper .child:eq(" + a + ") div img").attr("src", c.imageURL); $("#children_wrapper .child:eq(" + a + ") p:eq(0)").empty().append(c.gender + " from <strong>" + c.country + "</strong>"); $("#children_wrapper .child:eq(" + a + ") p:eq(1)").text(c.birthday) } function populatePopup(b, a, d) { var c = b.d["bufferedChildData"][a + d]; if (c.orderIndex < 1000000) { $("#scrolly > .items > div:eq(" + a + ") img").addClass("match") } else { $("#scrolly > .items > div:eq(" + a + ") img").removeClass("match") } $("#scrolly > .items > div:eq(" + a + ") img").attr("src", c.popupImageURL); $("#scrolly > .items > div:eq(" + a + ") .bio > span:eq(0)").text(c.name); $("#scrolly > .items > div:eq(" + a + ") .bio > span:eq(1)").text(c.birthday); $("#scrolly > .items > div:eq(" + a + ") .bio > span:eq(2)").text(c.country); $("#scrolly > .items > div:eq(" + a + ") .bio > span:eq(3)").text(c.gender); $("#scrolly > .items > div:eq(" + a + ") .bio > span:eq(4)").text(c.livesWith); $("#scrolly > .items > div:eq(" + a + ") .bio > span:eq(5)").text(c.brothers); $("#scrolly > .items > div:eq(" + a + ") .bio > span:eq(6)").text(c.sisters); $("#scrolly > .items > div:eq(" + a + ") .bio > span:eq(7)").text(c.number) } function serviceFailed(a) { alert("Error: " + a) } function unbindNavigation() { $(".children_left .prev").unbind("click").addClass("none"); $(".children_left .next").unbind("click").addClass("none"); $("#overlay_left").css("display", "none").unbind("click"); $("#overlay_right").css("display", "none").unbind("click") } function bindNavigation() { var e = lastJSON.d["visibleBuffersPointer"]; var d = e + 2; if (e > 1) { d = 0 } var a = e - 1; if (e == 0) { a = 3 } var b = $("#scrolly").data("scrollable").getIndex(); var c = $("#children_wrapper").data("scrollable").getIndex(); if (lastJSON.d["bufferedChildData"][a]["orderIndex"] != -1) { $(".children_left .prev").removeClass("none").click(prev); $("#overlay_left").css("display", "block").click(overlayPrev) } else { if (c != b) { $("#overlay_left").css("display", "block").click(overlayPrev) } } if (lastJSON.d["bufferedChildData"][d]["orderIndex"] < 2000000) { $(".children_left .next").removeClass("none").click(nex); $("#overlay_right").css("display", "block").click(overlayNex) } } function prev(a) { clearTimeout(tto); unbindNavigation(); tto = setTimeout(function () { transactionTimeout1() }, 2000); childImagesLoaded(doPrev) } function doPrev() { clearTimeout(tto); $("#children_wrapper").data("scrollable").prev(); setTimeout(function () { navigate(moveSuccess, "PreviousChild") }, TRANSITION_DELAY) } function nex(a) { clearTimeout(tto); unbindNavigation(); tto = setTimeout(function () { transactionTimeout1() }, 2000); childImagesLoaded(doNex) } function doNex() { clearTimeout(tto); if ($("#children_wrapper").data("scrollable").getIndex() == 3) { $("#children_wrapper > .items").css("left", "0px"); $("#children_wrapper > .items").animate({ left: "-312px" }, TRANSITION_DELAY, myEasing, function () { $("#children_wrapper").data("scrollable").seekTo(0, 0) }) } else { $("#children_wrapper").data("scrollable").next() } setTimeout(function () { navigate(moveSuccess, "NextChild") }, TRANSITION_DELAY + 100) } function overlayPrev(a) { clearTimeout(tto); unbindNavigation(); tto = setTimeout(function () { transactionTimeout1() }, 2000); childImagesLoaded(doOverlayPrev) } function doOverlayPrev() { clearTimeout(tto); si = $("#scrolly").data("scrollable").getIndex(); var a = lastJSON.d["visibleBuffersPointer"]; $("#scrolly").data("scrollable").prev(); if (si === a) { doPrev() } else { setTimeout(function () { bindNavigation() }, TRANSITION_DELAY) } } function overlayNex(a) { clearTimeout(tto); unbindNavigation(); tto = setTimeout(function () { transactionTimeout1() }, 2000); childImagesLoaded(doOverlayNex) } function doOverlayNex() { clearTimeout(tto); var a = $("#scrolly").data("scrollable").getIndex(); var b = lastJSON.d["visibleBuffersPointer"]; if (a == 3) { $("#scrolly > .items").css("left", "0px"); $("#scrolly > .items").animate({ left: "-650px" }, TRANSITION_DELAY, myEasing, function () { $("#scrolly").data("scrollable").seekTo(0, 0) }) } else { $("#scrolly").data("scrollable").next() } if (b != a) { doNex() } else { setTimeout(function () { bindNavigation() }, TRANSITION_DELAY) } } function moveSuccess(b) { clearTimeout(tto); $("#children_wrapper .loading").remove(); visibleBuffersPointer = b.d["visibleBuffersPointer"]; for (var a = 0; a < 4; a++) { if (a != visibleBuffersPointer && a != visibleBuffersPointer + 1) { populateChild(b, a + 1, -1); populatePopup(b, a + 1, -1) } } refreshCarouselClones(); $("#resultInfo").text(" " + lastJSON.d["displayMessage"] + " "); bindNavigation() } function transactionTimeout1() { $("#children_wrapper").append("<img class='loading' src='loading.gif' rel='Loading...' />"); tto = setTimeout(function () { transactionTimeout2 }, 60000) } function transactionTimeout2() { $("#children_wrapper > .items").empty(); for (var a = 0; a < 3; a++) { insertChildHTML() } $("#children_wrapper").append("<img class='loading' src='loading.gif' rel='Loading...' />"); $("#children_wrapper .items").css("left", "624px"); unbindNavigation(); navigate(finishInitialization, "HelloChild") } function refreshCarouselClones() { $(".cloned").remove(); $("#children_wrapper .child:eq(3)").clone().addClass("cloned").prependTo("#children_wrapper > .items"); $("#children_wrapper .child:eq(1)").clone().addClass("cloned").appendTo("#children_wrapper > .items"); $(".cloned").find("img").each(function (a) { $(this).overlay({ effect: "apple", target: "#c1", mask: { maskId: "mask" }, onBeforeLoad: function () { var b = 650 * (a); $("#scrolly .items").css("left", "-" + b + "px") }, onLoad: function () { if (a == 0) { a = 3 } if (a == 5) { a = 0 } $("#scrolly").data("scrollable").seekTo(a - 1, 0) } }) }); $("#scrolly > .items > div:eq(3)").clone().addClass("cloned").prependTo("#scrolly > .items"); $("#scrolly > .items > div:eq(1)").clone().addClass("cloned").appendTo("#scrolly > .items") };
