Groupon country list

Groupon country list

by stofke

HTML

<body>
  <div id="countrySelect">
    <ul id="countryList" class="align">

    </ul>
  </div>
  <div id="main"></div>
  <div id="result"></div>

  <script src="http://shopsheep.com/groupon/js/jquery.cookie.js"></script>

</body>

JavaScript

function capitalize() {
  return arguments[0].toUpperCase();
}

function call_back(countries) {
  $.each(countries, function(index, value) {
    $("#main").append("<select id='" + value + "'></select>");
    $("#main #" + value).hide();
    if ($.cookie("country") == value) {
      $("#main #" + value).show();
    }
  });
  $.each(countries, function(index, value) {
    $("#countrySelect #countryList").append("<label for='" + value + "-country'><input name='country' id='" + value + "-country' type='radio' value='" + value + "' />");
  });

  $.getJSON("http://shopsheep.com/groupon/json/combine.php?callback=?", function(data) {
    $.each(data, function() {
      $.each(this, function(key, val) {
        $.each(countries, function(index, value) {
          if (val.country == value.split('_').join(' ').replace(/(^|\s)([a-z])/g, capitalize)) {
            $("select#" + countries[index]).append("<option id=" + val.id + " value='http://api.groupon.de/feed/api/v1/deals/oftheday/" + val.countrycode + "/" + val.id + "'>" + val.name + "</option>");
          }
        });
      });
    });
  });
}
$.getJSON("http://shopsheep.com/groupon/json/countries.php?callback=?", function(data) {
  call_back(data.countries); //callback
});
$('select').live('change', function(event) {
  $.ajax({
    type: 'GET',
    url: 'http://www.shopsheep.com/bestsellers/rss.php?rss=' + $(this).val(),
    beforeSend: function() {
      $('#loader').html('<div id="loading">Loading Content</div>');
    },
    success: function(data) {
      $('#loader').empty();
      $('#result').html(data);
    },
    error: function() {
      $('#result').html('<p class="error"><strong>Oops!</strong> Try that again in a few moments.</p>');
    }
  });
});

$("input:radio").live('click', function(event) {
  var country = $(this).val();
  console.log(country);
  $("#main").children().hide();
  $("#" + country).show();
  $.cookie("country", country, {
    path: '/'
  });
});