﻿function GetFeaturedAreas(requestUrl) {
    $('#btnMoreAreas').toggle(function() {
        $(this).html('Less [ - ]');
        $('#featured-areas ul li:gt(4)').fadeIn('slow');
        return false;
    }, function() {
        $(this).html('More [+]');
        $('#featured-areas ul li:gt(4)').fadeOut('normal');
        return false;
    });
    $.ajax({
        url: requestUrl,
        type: "GET",
        cache: false,
        dataType: "json",
        cache: true,
        success: function(json) {
            var areasPresent = false;
            $('#featured-areas ul').html(''); $('#featured-areas ul').html('');
            if (json.featured.length > 0) {
                $.each(json.featured, function(index, item) {
                    if (index <= 9) {
                        $('#featured-areas ul').append('<li><a href="' + item.Url + '">'
                                + '<img src="'
                                    + item.ImageUrl + '" alt="Foreign direct investment in ' + item.Text + '" class="flag" />'
                                + '<div class="text"><strong class="designation">'
                                    + item.Text
                                    + '</strong><div class="view">View</div></div></a>');
                    } else {
                        $('#featured-areas ul').append('<li style="display:none"><a href="' + item.Url + '">'
                                + '<img src="'
                                    + item.ImageUrl + '" alt="Foreign direct investment in ' + item.Text + '" class="flag" />'
                                + '<div class="text"><strong class="designation">'
                                    + item.Text
                                    + '</strong><div class="view">View</div></div></a>');

                    }
                });

                areasPresent = true;
            }
            if (areasPresent == true) {
                $('#featured-loader').hide('fast', function() {
                    if (json.featured.length > 0) {
                        $('#featured-areas').fadeIn('fast');
                    }

                    if (json.featured.length > 4) {
                        $('#btnMoreAreas').fadeIn('slow');
                    }
                });
            } else {
                $('#featured-loader').html('No featured areas found at this time.');
            }
        }
    });
}
function GetProjectInfo(requestUrl) {
    $('#btnMoreProjects').toggle(function() {
        $(this).html('Less [ - ]');
        $('#latest-projects ul li:gt(4)').fadeIn('slow');
        return false;
    }, function() {
        $(this).html('More [+]');
        $('#latest-projects ul li:gt(4)').fadeOut('normal');
        return false;
    });
    $.ajax({
        url: requestUrl,
        type: "GET",
        cache: false,
        dataType: "json",
        cache: true,
        success: function(json) {
            $('#latest-projects ul').html('');
            var projectsPresent = false;
            if (json.projects.length > 0) {
                $.each(json.projects, function(index, item) {
                    if (index <= 4) {
                        $('#latest-projects ul').append('<li>' +
                                item.CompanyName + " invested in " + item.BusinessFunction + " within " + item.DestinationCountryName + '</li>');
                    } else {
                        $('#latest-projects ul').append('<li style="display:none">' +
                                item.CompanyName + " invested in " + item.BusinessFunction + " within " + item.DestinationCountryName + '</li>');
                    }
                });
                projectsPresent = true;
            }
            if (projectsPresent == true) {
                $('#projects-loader').hide('fast', function() {
                    if (json.projects.length > 0) {
                        $('#latest-projects').fadeIn('fast');
                    }

                    if (json.projects.length > 4) {
                        $('#btnMoreProjects').fadeIn('slow');
                    }
                });
            } else {
                $('#projects-loader').html('No project information found at this time.');
            }
        }
    });
}
