﻿function OnError(request, status, error) {
    $("#error").append(request.statusText);
    $("#error").append(request.responseText);
    $("#error").show();
};
function getLeaders() {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "wsDefaultService.asmx/topLeaders",
        data: "{}",
        dataType: "json",
        beforeSend: function () { $('#loader').show() },
        complete: function () { $('#loader').hide() },
        success: function (msg) { ApplyWhosHotTemplate(msg); },
        error: OnError
    });

};
function getCarousel() {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "wsDefaultService.asmx/getCarousel",
        data: "{}",
        dataType: "json",
        beforeSend: function () { $('#loader').show() },
        complete: function () { $('#loader').hide() },
        success: function (msg) { ApplyCarouselTemplate(msg); },
        error: OnError
    });

};
function getNews() {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "wsDefaultService.asmx/getNews",
        data: "{}",
        dataType: "json",
        beforeSend: function () { $('#loader').show() },
        complete: function () { $('#loader').hide() },
        success: function (msg) { ApplyNewsTemplate(msg); },
        error: OnError
    });

};
function getDailyVenues() {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "wsDefaultService.asmx/getDailyVenues",
        data: "{}",
        dataType: "json",
        beforeSend: function () { $('#loader').show() },
        complete: function () { $('#loader').hide() },
        success: function (msg) { ApplyDailyVenues(msg); },
        error: OnError
    });

};
function ApplyDailyVenues(msg) {
    var daily = msg.d;
    $("#daily").setTemplateURL("templates/default_treeview.htm");
    $("#daily").processTemplate(daily);
};
function ApplyNewsTemplate(msg) {
    var news = msg.d;
    for(n in news){
        $("#news").append('<h3 class="collapsePanelHeader">Published by:'+news[n].publishedby+ " on "+news[n].publishedwhen+"</h3>");
        $("#news").append('<div class="collapsePanel">' + news[n].message + '</div>');
    }
    
//    $("#news").setTemplateURL("templates/default_news.htm");
//    $("#news").processTemplate(news);
//    $(function () { $("#accordion").accordion({ autoHeight: false }); });
};
function ApplyWhosHotTemplate(msg) {
    var hot = msg.d;
    $("#whosHot").setTemplateURL("templates/leaderboard.htm");
    $("#whosHot").processTemplate(hot);
};
function ApplyCarouselTemplate(msg) {
    var carousel = msg.d;
    $("#carouselcenter").setTemplateURL("templates/partner_carousel.htm");
    $("#carouselcenter").processTemplate(carousel);
    $('#carouselcenter').jcarousel({
        auto: .5,
        wrap: 'circular',
        initCallback: mycarousel_initCallback

    });
};
function mycarousel_initCallback(carousel) {
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function () {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function () {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function () {
        carousel.stopAuto();
    }, function () {
        carousel.startAuto();
    });
};
