﻿
var tips;
var tipIndex = 0;

$(document).ready(function () {
    GetTips();
});

function GetTips() {
    $.ajax({
        type: "POST",
        url: "http://www.unicefenjij.nu/Webservices/Unicefenjij.asmx/GetTips",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: GetTips_OnSucceeded,
        error: OnFailed
    });
}


function GetTips_OnSucceeded(data, textStatus, XMLHttpRequest) {
    tips = data.d;

    $(this).everyTime(10000, "tips", function () { RotateTips() });

    RotateTips();
}

function OnFailed(XMLHttpRequest, textStatus, errorThrown) {
    alert("Error: " + errorThrown);
}

function RotateTips() {
    var tip = tips[tipIndex];
    tipIndex++;
    if (tipIndex >= tips.length) tipIndex = 0;

    $('#unicefHelper .balloon').fadeOut(250, function () {
        //$('#unicefHelper .balloon .txtclear').text(tip.Content);

        if (tip.IsUnicef) {
            $('#unicefHelper .balloon').css("background-image", "url(../assets/images/panelTipBlue.png)");
        }
        else {
            $('#unicefHelper .balloon').css("background-image", "url(../assets/images/panelTipRed.png)");
        }

        if (tip.PageLink) {
            $('#unicefHelper .balloon .txtclear').html(tip.PageLink);
            $('#unicefHelperLink').attr("href", $('#unicefHelper .balloon .txtclear > a').attr("href"));
        }

        $('#unicefHelper .balloon').fadeIn(250);
    });
}
