jQuery(document).ready(function() {
  // Get url
  var url = window.location.href;
            
  // Position of social bar on bottom
  var windowheight = jQuery(window).height();
  var mainheight = jQuery("#main").height();
  
  if(windowheight > mainheight) {
    var height = mainheight;
  }
  else {
    var height = windowheight;
  }  
  
  // Window resize
  jQuery(window).resize(function() {
    windowheight = jQuery(window).height();
    mainheight = jQuery("#main").height();
    
    if(windowheight > mainheight) {
      height = mainheight;
    }
    
    else {
      height = windowheight;
    }       
    
    if(jQuery("#footer_overlay").height() == 50) {
      jQuery("#footer_overlay").removeAttr("style").css({
        "top": height-52+"px",
        "height": "50px"
      });           
    }       
    
    else {
      jQuery("#footer_overlay").removeAttr("style").css({
        "top": height-34+"px",
      }); 
    }
  });
            
  // Click function facebook button
  jQuery("a.facebook_dummy").click(function() {          
    // Add real facebook button        
    if(windowheight > mainheight) {
      jQuery("#footer_overlay").css("height", "50px");
    }
    
    else {
      jQuery("#footer_overlay").css({
        "height": "50px",
        "top": height-52+"px"
      });
    }
    
    jQuery("#footer").css("height","125px");
    jQuery(this).parent().empty().append('<iframe src="http://www.facebook.com/plugins/like.php?href=' + url + '&amp;send=true&amp;layout=standard&amp;width=290&amp;show_faces=false&amp;action=recommend&amp;colorscheme=light&amp;font&amp;height=45" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:290px; height:45px;" allowTransparency="true"></iframe>');
  });
  
  jQuery("a.gplus_dummy").click(function() {   
    // Add real Google plus button
    jQuery(this).parent().empty().append('<div id="footer_overlay_right_inner"></div>');
    renderPlusone(url);
  });
  
  jQuery("#footer_overlay").css({
    "top": height-34+"px"
  });
});

function renderPlusone(url) {
  gapi.plusone.render("footer_overlay_right_inner", {"size": "medium", "count": "true", "href": url});
} 
