/* Released: 2010-01-28 14:28:25 */


(function ($) {
  var ns = $.downloadNow = $.downloadNow || {};

  $.fn.extend({
      downloadNow : function() {

          var content = $(this).parent().find('.other-os-content')[0];
          if (!content) return this;

          $(content).hide();

          $(this).bind('click', function(){
              if (!content) return false;
              var visible = $(content).css('display') == 'none' ? false : true;

              if (!visible) {
                  $(this).fadeOut(300, function(){
                      // Opera does not like it when we do animation on this element.
                      // As a workaround, we remove the absolute and set it relative, which layout wise
                      // works for opera as well.
                      if ($.browser.opera) {$(this).parents('.sub').css('position', 'relative');}
                      $(content).slideDown(300);
                  });
              } else {
                  $(content).slideUp(300);
              }
              return false;
          });

          return this;
      },

      startDownload : function() {
          var hash = document.location.hash + '';
          if (hash.length < 2) return;

          hash = hash.substring(1, hash.length);

          var autostartLink = null;
          $(this).find('.start-download-link').each(function(){
              if ($(this).hasClass(hash)) {
                  $(this).removeClass('hidden');
                  autostartLink = this;
              } else {
                  $(this).addClass('hidden');
              }
          });

          if (autostartLink) {
              var href = autostartLink.href;
              window.setTimeout(function(){window.location.href = href;}, 500);
          }

          return this;
      }
  });

})(jQuery);
