﻿$(document).ready(function () {

    $("#tag-cloud-container").fadeIn("slow");

    // when the page loads, the tag cloud should be set with the popular escort services
    displayHomePageTagCloud("Services");

    // tag cloud dropdown change
    $('#TagCloudDataSourceDropdown').change(function () {

        // or if you just want the selected items:
        displayHomePageTagCloud($("OPTION:selected", this).val());

    });

});


function displayHomePageTagCloud(URLParameter) {

    // Get the Services tag cloud
    $.ajax({
        type: "GET",
        url: "/Index/GetTagCloudDataStats/" + URLParameter,
        success: function (data) {

            // initially clear all the stats
            $(".tag-div-container").remove();

            $.each(data, function (key, value) {

                var sb = new StringBuilder();

                // the link should be this
                // <a class="addLinkMouseCursor weight3" weightpercentage="68.8888888888889" title="UK Escorts that offer Pussy Pumping" href="/EscortServiceSearch/UKEscorts/female/both/EscortService/Pussy Pumping" >A Levels (at discretion)</a>

                // test to see which dataset were dealing with
                sb.append("<div class='tag-div-container'>");
                sb.append("<h2 id='tagCloudh2'>");

                // switch on the tag cloud data
                switch (URLParameter) {
                    case "Services":
                        sb.append("<a title='UK Escorts that offer " + value.StatName + "' class='addLinkMouseCursor weight" + value.Weight + " weightPercentage= " + value.WeightPercentage + "' href='/EscortServiceSearch/UKEscorts/female/both/EscortService/" + value.StatValue + "' onclick='KillSearchSessions();'>" + value.StatName + "</a>");
                        break;

                    case "OneHourFromIncallPrice":
                        // /EscortSearch/UKEscorts/Female/Both/options/HourlyRateFrom=120-HourlyRateTo=120
                        sb.append("<a title='UK Escorts that offer 1 hour Incall at £" + value.StatValue + "' class='addLinkMouseCursor weight" + value.Weight + " weightPercentage= " + value.WeightPercentage + "' href='/EscortSearch/UKEscorts/Female/Both/options/HourlyRateFrom=" + value.StatValue + "-HourlyRateTo=" + value.StatValue + "' onclick='KillSearchSessions();'>" + value.StatName + "</a>");
                        break;

                    case "Ages":
                        // /EscortSearch/UKEscorts/Female/Both/options/-escortAgeFrom=31-escortAgeTo=31
                        sb.append("<a title='" + value.StatValue + " year old UK Escorts' class='addLinkMouseCursor weight" + value.Weight + " weightPercentage= " + value.WeightPercentage + "' href='/EscortSearch/UKEscorts/Female/Both/options/escortAgeFrom=" + value.StatValue + "-escortAgeTo=" + value.StatValue + "' onclick='KillSearchSessions();'>" + value.StatName + "</a>");
                        break;
                }
                
                sb.append("</h2>");
                sb.append("</div>");


                // add them after the 
                $("#tag-cloud-container").append(sb.toString());
                sb = null;

            });

            $("#tag-cloud-container").append("<div class='clear'></div>");
        },
        error: function () { },
        beforeSend: function () { },
        complete: function () {
            $("#tagCloudLoaderImage").hide();

            // switch on the tag cloud data
            switch (URLParameter) {
                case "Services":
                    $("#TagCloudTitleText").text("Most Popular Escort Services.").fadeIn("slow");
                    break;

                case "OneHourFromIncallPrice":
                    $("#TagCloudTitleText").text("Most Popular One Hour Incall Price.").fadeIn("slow");
                    break;

                case "Ages":
                    $("#TagCloudTitleText").text("Most Popular Escort Age.").fadeIn("slow");
                    break;
            }

        },
        dataType: "json",
        cache: false
    });

}
