// sdge share js

SDGE = (typeof(SDGE) == 'undefined' ? {} : SDGE);

if(typeof jQuery != 'undefined') {
  (function ($) {

    // when document is ready
    $(document).ready(function(){
      // SDGE_TO : use delegate() here. not working in modals for some reason

      // when user clicks on a share link
      $('a.share-link').live('click',function(){
        // log its target
        console.log(this.href)
        // open its target
        window.open(this.href,this.title,'width=800,height=400')
        // stop link from redirecting user
        return false;
      })
      // when user clicks on 'share this'
      $('a.share-show-link').live('click',function(){
        // show its container
        $(this).siblings('.share-container').fadeToggle('fast');
      })
    });
    
  }(jQuery))
};
(function() {
  var SDGE;
  SDGE = (typeof SDGE === "undefined" ? {} : SDGE);
  if (typeof jQuery !== "undefined") {
    (function($) {
      SDGE.twitter = {};
      return $(document).ready(function() {
        
        var distance_to_move_the_tweet, moveUp, tweets_function_wrapper, tweets_text_wrapper;
        
        distance_to_move_the_tweet = 41;
        tweets_text_wrapper = $("#tweets-pulled-listing");
        tweets_function_wrapper = $("#tweets-pulled-functions");
        
        moveUp = function(tweet_container, tweets_function_wrapper) {
          // define all the variables
          var cloned_first_tweet, cloned_first_tweet_function, first_tweet, first_tweet_function, second_tweet, second_tweet_function;
            
            // find+clone the first tweet and find the second one
            first_tweet = tweet_container.children("p:first");
            cloned_first_tweet = tweet_container.children("p:first").clone(true);
            second_tweet = tweet_container.children("p:nth-child(2)");
          
            // find+clone the first tweet function and find the second one
            first_tweet_function = tweets_function_wrapper.children("p:first");
            cloned_first_tweet_function = tweets_function_wrapper.children("p:first").clone(true);
            second_tweet_function = tweets_function_wrapper.children("p:nth-child(2)");
          
          // animate the first tweet
          first_tweet.animate({
            top: distance_to_move_the_tweet + "px"
          }, 1000, function() {
            return first_tweet.remove();
          });
          
          // animate the second tweet
          second_tweet.animate({
            top: 0
          }, 1000, function() {
            $(this).css("top", "0px");
            first_tweet_function.remove();
            return second_tweet_function.css("left", "0px");
          });
          
          
          // append the first tweet and the first tweet-function back to their arrays
          cloned_first_tweet.appendTo(tweet_container).css("top", "-41px");
          return cloned_first_tweet_function.appendTo(tweets_function_wrapper);
        };
        
        // initially set the position of the tweet and the tweet function
        //tweets_function_wrapper.children("p:first").css("left", "0px");
        //tweets_text_wrapper.children("p:first").css("top", "0px");
        
        // set the interval of shuffling everything
        return SDGE.twitter.interval = setInterval(function() {
          return moveUp(tweets_text_wrapper, tweets_function_wrapper);
        }, 10000);
        
      });
    })(jQuery);
  }
}).call(this);
;

