<?php 
global $theme_path, $user; 
drupal_add_js("http://platform.twitter.com/anywhere.js?id=" . variable_get(WD_SETTINGS_PREFIX . 'twitter_anywhere_api_key') . "&v=1", 'external');
$donation = node_load(arg(2));
$donation_language = (isset($donation->language)) ? $donation->language : LANGUAGE_NONE;
$project_id = $donation->field_donation_project[$donation_language][0]['target_id'];
$project_url = 'http://' . $_SERVER['HTTP_HOST'] . url('node/' . $project_id);
$project = node_load($project_id);
?>
<h2>Tell your friends you've donated</h2>
<div class="why-you-gave-social-media">
  <div class="social-media-icons">
    <img id="why-you-gave-facebook-icon" alt="Facebook" src="/<?php print $theme_path; ?>/images/symbols/facebook.png"/> 
    <img id="why-you-gave-twitter-icon" alt="Twitter"  src="/<?php print $theme_path; ?>/images/symbols/twitter.png"/> 
    <img id="why-you-gave-google-icon" alt="Google+"  src="/<?php print $theme_path; ?>/images/symbols/google.png"/> 
    <img id="why-you-gave-email-icon" alt="Email"  src="/<?php print $theme_path; ?>/images/symbols/email.png"/>
  </div>

  <div class="social-media-content-container">

<!-- facebook plugin will not initially render properly if style is set to display:none, so we're rendering it off the screen and then back on when we want top display it -->
    <div class="social-media-facebook" style="position:absolute; top:-1000px;">
      <div class="social-media-arrow"> </div>
      <div class="social-media-content">
        <div class="fb-like" data-href="<?php print $project_url; ?>" data-send="true" data-width="450" data-height="35" data-show-faces="true"></div>
        <div class="fb-comments" data-href="<?php print $project_url; ?>" data-num-posts="2" data-width="470"></div>
      </div>
    </div>

<!-- twitter plugin will not initially render properly if style is set to display:none, so we're rendering it off the screen and then back on when we want top display it -->
    <div class="social-media-twitter" style="position:absolute; top:-1000px;">
      <div class="social-media-arrow"></div>
      <div class="social-media-content">
<!-- This is not realistic because we can't iframe content with js -->
<!--
        <div class="twitter-suggestions">
          <input type="radio" name="twitter-tweet-radios" id="twitter-tweet-suggest1" onclick="updateTweetBox('I just donated to <?php print $project->title; ?> on @wecatapult. You can help too: http://dlrp.fm/cb0987')"><label>I just donated to <?php print $project->title; ?> on @wecatapult. You can help too: http://dlrp.fm/cb0987</label>
        </div>
        <div class="twitter-tweet-box">
          <input type="radio" name="twitter-tweet-radios" id="twitter-tweet-custom">
-->
<!-- DEPRECATED for @anywhere framework
<a href="https://twitter.com/share" class="twitter-share-button" data-text="geergegrege" data-via="bfuzze">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
-->
          <div class="tbox"></div>
<!--        </div> -->
      </div>

    </div>

    <div class="social-media-google" style="display:none;">
      <div class="social-media-arrow"> </div>
      <div class="social-media-content">
        <div class="g-plusone" data-size="tall" data-annotation="inline" data-width="300"></div>
      </div>
    </div>

    <div class="social-media-email" style="display:none;">
      <div class="social-media-arrow"></div>
      <div class="social-media-content">

      </div>
    </div>

<?php 
if (user_is_logged_in()) { 
  if (!in_array('WD Partner', $user->roles)) {
?>
      <div style="height: 40px;">
      <a class="button-orange" href="/node/add/team" ><b>Start a team</b> Invite your friends</a>
     </div>
<?php 
  }
} else { ?>
    <div class="social-media-default">
      <h2>Join catapult to follow your project</h2>
      <div id='donation-why-you-gave-facebook-button'><?php echo fboauth_action_display('connect'); ?></div>
      <a class="colorbox-load button-green" href="/colorbox/form/user_register_form?destination=donations/whyyougave/<?php print $donation->nid; ?>&width=1000&height=630&scrolling=false"><B>Create an account</b>with Catapult</a>
     <a class="colorbox-load button-orange" href="/colorbox/form/user_register_form?destination=node/add/team&width=1000&height=630&scrolling=false"><b>Start a team</b> Invite your friends</a>
    </div>
<?php } ?>

  </div><!-- END social-media-content-container -->
</div><!-- END why-you-gave-social-media -->

<div id="fb-root"></div>
<script type="text/javascript">
var whyYouGaveSocialMediaHideAll = function() {
   jQuery('.why-you-gave-social-media .social-media-content-container .social-media-facebook').hide();
   jQuery('.why-you-gave-social-media .social-media-content-container .social-media-twitter').hide();
   jQuery('.why-you-gave-social-media .social-media-content-container .social-media-google').hide();
   jQuery('.why-you-gave-social-media .social-media-content-container .social-media-email').hide();
   jQuery('.why-you-gave-social-media .social-media-content-container .social-media-default').hide();
}

//FACEBOOK
jQuery('#why-you-gave-facebook-icon').click(function(){
  var current_style = jQuery('.why-you-gave-social-media .social-media-content-container .social-media-facebook').attr('style');
  if (current_style == '' || current_style == 'display: block;') {
    jQuery('.why-you-gave-social-media .social-media-content-container .social-media-facebook').hide();
    jQuery('.why-you-gave-social-media .social-media-content-container .social-media-default').show();
  } else {
    whyYouGaveSocialMediaHideAll();
    jQuery('.why-you-gave-social-media .social-media-content-container .social-media-facebook').attr('style', '');
    jQuery('.why-you-gave-social-media .social-media-content-container .social-media-facebook').show();
  }
});

//TWITTER
jQuery('#why-you-gave-twitter-icon').click(function(){
  var current_style = jQuery('.why-you-gave-social-media .social-media-content-container .social-media-twitter').attr('style');
  if (current_style == '' || current_style == 'display: block;') {
    jQuery('.why-you-gave-social-media .social-media-content-container .social-media-twitter').hide();
    jQuery('.why-you-gave-social-media .social-media-content-container .social-media-default').show();
  } else {
    whyYouGaveSocialMediaHideAll();
    jQuery('.why-you-gave-social-media .social-media-content-container .social-media-twitter').attr('style', '');
    jQuery('.why-you-gave-social-media .social-media-content-container .social-media-twitter').show();
  }
});

//GOOGLE+
jQuery('#why-you-gave-google-icon').click(function(){
  if (jQuery('.why-you-gave-social-media .social-media-content-container .social-media-google').is(':visible')) {
    jQuery('.why-you-gave-social-media .social-media-content-container .social-media-google').hide();
    jQuery('.why-you-gave-social-media .social-media-content-container .social-media-default').show();
  } else {
    whyYouGaveSocialMediaHideAll();
    jQuery('.why-you-gave-social-media .social-media-content-container .social-media-google').show();
  }
});

//EMAIL
jQuery('#why-you-gave-email-icon').click(function(){
  if (jQuery('.why-you-gave-social-media .social-media-content-container .social-media-email').is(':visible')) {
    jQuery('.why-you-gave-social-media .social-media-content-container .social-media-email').hide();
    jQuery('.why-you-gave-social-media .social-media-content-container .social-media-default').show();
  } else {
    whyYouGaveSocialMediaHideAll();
    jQuery('.why-you-gave-social-media .social-media-content-container .social-media-email').show();
  }
});

(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

(function() {
  var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
  po.src = 'https://apis.google.com/js/plusone.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();

jQuery(document).ready(function(){
  twttr.anywhere(function (T) {
    T('.page-donations-whyyougave .social-media-twitter .tbox').tweetBox({
      height: 100,
      width: 450,
      label: '',
      defaultContent: 'I just donated to <?php print $project->title; ?> on @wecatapult. You can help too: http://dlrp.fm/cb0987'
    });
  });
  getWhyYouGaveEmailForm(<?php print $donation->nid; ?>);
});

var updateTweetBox = function(m) {
  jQuery('iframe.twitter-anywhere-tweet-box textarea#tweet-box').val(m);
}
</script>