﻿(function($) {

   $.fn.awtHoverBehavior = function() {
      function t() {$(this).toggleClass("hover");}
      return this.each(function() {
         $(this).hover(t,t);
      });
   };

   function itg(i) {
      i.toggleClass("clp").toggleClass("exp").children(":eq(1)").slideToggle("normal");
   }
   
   function toggle(o, n) {
      if (o && n.hasClass("clp")) {
         itg(o);
         itg(n);
      }  
   }   

   $.fn.awtAccordion = function(opts) {
      var cur, o = $.extend({}, $.fn.awtAccordion.defaults, opts);
      return this.each(function() {
         var t = $(this), items = t.children();
         cur = $(items[0]);
         items.css({paddingBottom:o.gap}).addClass("clp").children(":odd").hide();
         itg(items.filter(":eq(0)"));
         $.event.special.hover.delay = 150;
         items.awtHoverBehavior().eshover( function() { toggle(cur, $(this)); cur = $(this); } );
         if (opts.delayedShow) {
            if ($.browser.msie) {
               $(this).slideDown("fast");
            } else {
               $(this).fadeIn(1000);
            }
         }
      });
   };
   
   $.fn.awtAccordion.defaults = {
      gap: "4px"
   };
   
   $.fn.awtNoSpam = function() {
      function dec (s) {
         var o = "", n = 0;
         while (n < s.length) {
            o += String.fromCharCode((parseInt(s[n++], 16) << 4) + parseInt(s[n++], 16));
         }
         return o;
      }         
      return this.each(function() {
         $(this).click( function() {
            var t = $(this), ohr = t.attr("href");
            t.attr({href:dec($.url.setUrl(ohr).attr("query").substr(2))});
            setTimeout(function() {
               t.attr({href: ohr});
            }, 10);
         });         
      });
   }
   
})(jQuery);
