// Generated by CoffeeScript 1.6.3
(function() {
  $(document).ready(function() {
    var getRandom;
    getRandom = function(min, max) {
      return Math.floor(Math.random() * (max - min + 1) + min);
    };
    $('#CotD').click(function() {
      return $.getJSON('http://drunkzilla.herokuapp.com/cotd.json', function(data) {
        var items;
        items = '';
        $('#title').text(data[0]['name']);
        $('#img').html('<img src="' + data[0]['image'] + '" style="float:left; margin:0 10px 10px 0" height="40%" width="40%" alt="" />');
        $.each(data[0]['ingredients'], function(key, value) {
          return items += '<li>' + data[0]['ingredients'][key]['quantity'] + ' ' + data[0]['ingredients'][key]['name'] + '</li>';
        });
        $('#ingredients').html($(items));
        return $('#preparation').text(data[0]['preparation']);
      });
    });
    return $('#navbar a').click(function() {
      var position;
      position = $(this).attr('href');
      if (position !== void 0) {
        return $.getJSON('http://drunkzilla.herokuapp.com/cocktails.json', function(data) {
          var items, randCocktail;
          randCocktail = getRandom(0, data.length);
          $('#random').attr('data-cocktailid', randCocktail);
          $('#random').click(function() {
            var cocktail_id;
            cocktail_id = $('#random').attr('data-cocktailid');
            if (cocktail_id !== void 0) {
              return $.getJSON('http://drunkzilla.herokuapp.com/cocktail_' + cocktail_id + '.json', function(data) {
                var items;
                items = '';
                $('#title').text(data[0]['name']);
                $('#img').html('<img src="' + data[0]['image'] + '" style="float:left; margin:0 10px 10px 0" height="40%" width="40%" alt="" />');
                $.each(data[0]['ingredients'], function(key, value) {
                  return items += '<li>' + data[0]['ingredients'][key]['quantity'] + ' ' + data[0]['ingredients'][key]['name'] + '</li>';
                });
                $('#ingredients').html($(items));
                return $('#preparation').text(data[0]['preparation']);
              });
            }
          });
          items = '';
          $.each(data, function(key) {
            return items += '<li><a id="cocktail" data-cocktailid="' + data[key]['id'] + '" href="#cocktail"><img src="' + data[key]['image'] + '" width="160" height="160" alt="" /><h2>' + data[key]['name'] + '</h2></a></li>';
          });
          $('#results').html($(items));
          $('#results').trigger('create');
          $('#results').listview('refresh');
          return $('a').click(function() {
            var cocktail_id;
            cocktail_id = $(this).attr('data-cocktailid');
            if (cocktail_id !== void 0) {
              return $.getJSON('http://drunkzilla.herokuapp.com/cocktail_' + cocktail_id + '.json', function(data) {
                items = '';
                $('#title').text(data[0]['name']);
                $('#img').html('<img src="' + data[0]['image'] + '" style="float:left; margin:0 10px 10px 0" height="40%" width="40%" alt="" />');
                $.each(data[0]['ingredients'], function(key, value) {
                  return items += '<li>' + data[0]['ingredients'][key]['quantity'] + ' ' + data[0]['ingredients'][key]['name'] + '</li>';
                });
                $('#ingredients').html($(items));
                return $('#preparation').text(data[0]['preparation']);
              });
            }
          });
        });
      }
    });
  });

}).call(this);
