'use strict';

var STATIC_URL = '/static/';
var MEDIA_URL = 'uploads/';

/**
 * Handle login with facebook button.
 */
$('.loginBtn--facebook').click(function(){
  checkLoginState();

  // Check if the "share" button was clicked.
  if($(this).hasClass('fb-share')) {
    shareThisPost();
  }

  $('.loginBtn--facebook').text("Share with Facebook");
  $(this).addClass('fb-share');
});

/**
 * Share a post to facebook.
 */
function shareThisPost(){
  var captionText = $('p.to-FB-share').text();
  var url = $(location).attr('href');
  url = url.split("/")[0] + '//' + url.split("/")[2];
  var image = url + $('#FB-image-game').attr('src');
  console.log(image);

  FB.ui({
    method: 'share',
    name: 'Something',
    picture: image,
    href: url,
    link: url,
    description: captionText,
    caption: 'http://www.whatsbuzz.co.il'

  }, function(response){});
}

/**
 * Handle the quizzes button, when displayed.
 */
$('#quizzes-game').click(function(){
  $(this).hide();
  showSpinner();

  // Show the quiz and hide the play button
  setTimeout(function(){
    $('#quizzes').show();
  }, 5250);
});

/**
 * Handle "show more" button in the nav pages.
 * Get posts, by type, from server and display them on the page.
 */
$('#show-more-in-page').click(function(event){
  event.preventDefault();
  var type = $('.show-more').data('posts-type');
  var start = $('.posts').length;
  $.get("/get-more-posts/" + type + "/" + start, function(data){
    // Convert the data to array of js objects.
    var data = JSON.parse(data[0].posts);

    // Create a post for each of them.
    data.forEach(function(postObject){
      // The title.
      var postTitle = $('<h2>').text(postObject.fields.title);
      // The image banner.
      var postImage = $('<img>').addClass('banner-image').attr('src', MEDIA_URL + postObject.fields.image_banner).attr('alt', postObject.fields.image_banner);
      // The button link.
      var postSlog = $('<a>').attr('href', "/posts/" + postObject.fields.slug).append($('<div>').addClass('row link').append($('<p>').text("התחל משחק")));

      // The whole post card.
      var postObj = $('<div>').addClass('col-sm-6 posts').append($('<div>').addClass('post').append(postTitle).append(postImage).append(postSlog));

      $('#main-posts').append(postObj);
    });
  });
});
@@ -16,14 +16,13 @@
 var 
-STATIC
+MEDIA
 _URL
@@ -36,29 +36,8 @@
 atic
-/';%0Avar MEDIA_URL = '
 uplo

Fix upload static images.