﻿// Scripts for the Home Partner Module

if (!ActiveHealthyKids)
{
    var ActiveHealthyKids = {};
}

ActiveHealthyKids.HomePartnerModule = {
    Initialize: function (id, serviceUrl, contentName, urlRoot) {
    
        $.ajax({
            type: 'POST',
            url: serviceUrl + '/GetPartnerItem',
            data: '{\'ContentName\':' + '\'' + contentName + '\'}',
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            success: function(result)
                 {
                    if (result.d != null)
                    {
                        displayResults(result.d);
                    }
                 },
            failure: function(error)
                 {
                    //TODO: Do something
                 }
        });
        
        function displayResults(results) {
          
            var module = $('#' + id);
            
            if (module.length > 0) {
                module.find('.TitleLink').html(results.Title);
                module.find('.TextLink').html(results.Text);
                module.find('.ImageLink').append('<img src="' + results.Image.URL + '" alt="' + results.ImageLabel + '" />');
                module.find('.MoreInfoLink').attr('href', results.URL.replace('~/', urlRoot));
            }
        }
    
    }
};