$(document).ready(function() {
// put your code
});
/*
 TOP MOVIES
 MOCKUP
<div class="last-films">
    <h3>Top quieren verlas</h3>
	<ol class="top-likes">
	</ol>
	<h3>Las m&aacute;s comentadas</h3>
	<ol class="top-comments">
	</ol>
	<h3>Top 5 Box Office</h3>
	<ol class="top-box-office">
	</ol>
</div>
 */
// top likes

$.getJSON("/videos?format=json&limit=5&order=popularity&desc=true&scope=30", function(data) {
  if(!$.isEmptyObject(data)){
    $.each(data['resources']['resource'], function(i, item) {
      $(".top-likes").prepend("<li><h3><a href=' " + item['url'] +"  '>" + item['title'] + "</a></h3><!--<span>99%</span><em>(430/2)</em>--></li>");
    });
  }
}).success(function() { $("li.loading.all").remove() });


// top comments
$.getJSON("/videos?format=json&limit=5&order=comments_count&scope=30", function(data) {
  if(!$.isEmptyObject(data)){
    $.each(data['resources']['resource'], function(i, item) {
      $(".top-comments").prepend("<li><h3><a href=' " + item['url'] +"  '>" + item['title'] + "</a></h3><!--<span>99%</span><em>(430/2)</em>--></li>");
    });
  }
}).success(function() { $("li.loading.all").remove() });

// box office
$.getJSON("/videos?format=json&limit=5&tag=boxoffice&scope=30", function(data) {
  if(!$.isEmptyObject(data)){
    $.each(data['resources']['resource'], function(i, item) {
      $(".top-box-office").prepend("<li><h3><a href=' " + item['url'] +"  '>" + item['title'] + "</a></h3><!--<span>99%</span><em>(430/2)</em>--></li>");
    });
  }
}).success(function() { $("li.loading.all").remove() });




$.getJSON("/videos?format=json&covers=true&order=popularity&limit=8&scope=30", function(data) {
  if(!$.isEmptyObject(data)){
    $.each(data['resources']['resource'], function(i, item) {
      if($.isArray(item['attachments']['attachment'])){
        $("#featured-films #popular ul").prepend("<li><a href=' " + item['url'] +"  '><img src='" + item['attachments']['attachment'][0]['cover'][22]['url'] + "' /></a><strong class='title'>" + item['title'] + "</strong><a class='btn' href=' " + item['url'] +"  '>Ver Trailer</a><a class='btn wannasee' href=' " + item['url'] +"/like  '>Quiero verla!</a></li>");
      } else {
        $("#featured-films #popular ul").prepend("<li><a href=' " + item['url'] +"  '><img src='" + item['attachments']['attachment']['cover'][22]['url'] + "' /></a><strong class='title'>" + item['title'] + "</strong><a class='btn' href=' " + item['url'] +"  '>Ver Trailer</a><a class='btn wannasee' href=' " + item['url'] +"/like  '>Quiero verla!</a></li>");
      }
    });
  }
}).success(function() { $("#popular li.loading").remove() });
// FEATURED FILMS
$.getJSON("/videos?format=json&covers=true&tag=cartelera&limit=8", function(data) {
  if(!$.isEmptyObject(data)){
    $.each(data['resources']['resource'], function(i, item) {
      if($.isArray(item['attachments']['attachment'])){
        $("#featured-films #cartelera ul").prepend("<li><a href=' " + item['url'] +"  '><img src='" + item['attachments']['attachment'][0]['cover'][22]['url'] + "' /></a><strong class='title'>" + item['title'] + "</strong><a class='btn' href=' " + item['url'] +"  '>Ver Trailer</a><a class='btn wannasee' href=' " + item['url'] +"/like  '>Quiero verla!</a></li>");
      } else {
        $("#featured-films #cartelera ul").prepend("<li><a href=' " + item['url'] +"  '><img src='" + item['attachments']['attachment']['cover'][22]['url'] + "' /></a><strong class='title'>" + item['title'] + "</strong><a class='btn' href=' " + item['url'] +"  '>Ver Trailer</a><a class='btn wannasee' href=' " + item['url'] +"/like  '>Quiero verla!</a></li>");
      }
    });
  }
}).success(function() { $("#cartelera li.loading").remove() });


$.getJSON("/videos?format=json&covers=true&tag=estreno&limit=8", function(data) {
  if(!$.isEmptyObject(data)){
    $.each(data['resources']['resource'], function(i, item) {
      if($.isArray(item['attachments']['attachment'])){
        $("#featured-films #estrenos ul").prepend("<li><a href=' " + item['url'] +"  '><img src='" + item['attachments']['attachment'][0]['cover'][22]['url'] + "' /></a><strong class='title'>" + item['title'] + "</strong><a class='btn' href=' " + item['url'] +"  '>Ver Trailer</a><a class='btn wannasee' href=' " + item['url'] +"/like  '>Quiero verla!</a></li>");
      } else {
        $("#featured-films #estrenos ul").prepend("<li><a href=' " + item['url'] +"  '><img src='" + item['attachments']['attachment']['cover'][22]['url'] + "' /></a><strong class='title'>" + item['title'] + "</strong><a class='btn' href=' " + item['url'] +"  '>Ver Trailer</a><a class='btn wannasee' href=' " + item['url'] +"/like  '>Quiero verla!</a></li>");
      }
    });
  }
}).success(function() { $("#estrenos li.loading").remove() });

$.getJSON("/videos?format=json&covers=true&tag=proximamente&limit=8", function(data) {
  if(!$.isEmptyObject(data)){
    $.each(data['resources']['resource'], function(i, item) {
      if($.isArray(item['attachments']['attachment'])){
        $("#featured-films #proximos ul").prepend("<li><a href=' " + item['url'] +"  '><img src='" + item['attachments']['attachment'][0]['cover'][22]['url'] + "' /></a><strong class='title'>" + item['title'] + "</strong><a class='btn' href=' " + item['url'] +"  '>Ver Trailer</a><a class='btn wannasee' href=' " + item['url'] +"/like  '>Quiero verla!</a></li>");
      } else {
        $("#featured-films #proximos ul").prepend("<li><a href=' " + item['url'] +"  '><img src='" + item['attachments']['attachment']['cover'][22]['url'] + "' /></a><strong class='title'>" + item['title'] + "</strong><a class='btn' href=' " + item['url'] +"  '>Ver Trailer</a><a class='btn wannasee' href=' " + item['url'] +"/like  '>Quiero verla!</a></li>");
      }
    });
  }
}).success(function() { $("#proximos li.loading").remove() });



