(function($) {
  var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
  $(document).keydown(function(e){
    kkeys.push( e.keyCode );
    if ( kkeys.toString().indexOf( konami ) >= 0 ) {
      window.location = "/konami-code-is-the-shit";
    }
  });
})(jQuery);




;
(function ($) {

  Drupal.behaviors.anonInit = {
    attach: function(context, settings) {

      var focusElement = $('#user-login #edit-name', context);
      if(focusElement.length == 1) {
        focusElement.focus();
      }

      $('body', context).IE6ify();
    }
  };
  
  Drupal.behaviors.shInit = {
    attach: function(context, settings) {
      SyntaxHighlighter.defaults['tab-size'] = 2;
      SyntaxHighlighter.config.stripBrs = true;
      SyntaxHighlighter.config.clipboardSwf = Drupal.settings.basePath + 'sites/all/themes/stjerneman/js/syntaxhighlighter/scripts/clipboard.swf';
      SyntaxHighlighter.highlight();
    }
  };

  Drupal.behaviors.smoothSlide = {
    attach: function(context, settings) {
      $('a[href*=#]', context).click(function () { 
        if($(this).attr('href') == "#") {
          return true;
        }
        var target = $('[name=' + this.hash.slice(1) +']').length > 0 ? $('[name=' + this.hash.slice(1) +']') : $('#' + this.hash.slice(1));
        if(target.length > 0) {
          $("html:not(:animated), body:not(:animated)").animate({ scrollTop: target.offset().top }, 1100 );
          return false;
        }
      });
    }
  };

  Drupal.behaviors.customComment = {
      attach: function(context, settings) {
        
        $('.not-logged-in #comment-form #edit-name', context).data('overlabel', 'Namn');
        $('.not-logged-in #comment-form #edit-mail', context).data('overlabel', 'E-post (kommer inte att visas)');
        $('.not-logged-in #comment-form #edit-homepage', context).data('overlabel', 'Webbplats');
        $('.not-logged-in #comment-form #edit-comment-body-und-0-value', context).data('overlabel', 'Din kommentar...');
        $('.not-logged-in #comment-form #edit-mollom-captcha', context).data('overlabel', 'CAPTCHA (texten i bilden)');

 
        $('.not-logged-in #comment-form .form-text:not(#edit-mollom-homepage), .not-logged-in #comment-form .form-textarea', context).each(function(i) {
          var item = $(this);
          var div = $('<div>').html(item.data('overlabel')).addClass('labeldiv');
          item.parent().append(div);
          (item.val() == "") ?  div.show() : div.hide() ; 

          item.focus(function() {
            (item.val() == '') ? item.parent().find('.labeldiv').hide(): '' ;
            if( item.attr('id') == 'edit-homepage') {
              (item.val() == "") ? item.val('http://') : '';
            }
          })
          .blur(function() {
            if( item.attr('id') == 'edit-homepage') {
              (item.val() == 'http://' ) ? item.val('') : '';
            }
            (item.val() == '') ? item.parent().find('.labeldiv').show(): '' ;
          });
        });

        $('.labeldiv', context).live('click', function() {
          $(this).parent().find('.form-text, .form-textarea').trigger('focus');
        });

      }
    };

    Drupal.behaviors.customContact = {
      attach: function(context, settings) {
        
        $('.not-logged-in #contact-site-form #edit-name', context).data('overlabel', 'Namn');
        $('.not-logged-in #contact-site-form #edit-mail', context).data('overlabel', 'E-post (kommer inte att visas)');
        $('.not-logged-in #contact-site-form #edit-subject', context).data('overlabel', 'Ämne');
        $('.not-logged-in #contact-site-form #edit-message', context).data('overlabel', 'Ditt meddelande...');
        $('.not-logged-in #contact-site-form #edit-mollom-captcha', context).data('overlabel', 'CAPTCHA (texten i bilden)');

 
        $('.not-logged-in #contact-site-form .form-text:not(#edit-mollom-homepage), .not-logged-in #contact-site-form .form-textarea', context).each(function(i) {
          var item = $(this);
          var div = $('<div>').html(item.data('overlabel')).addClass('labeldiv');
          item.parent().append(div);
          (item.val() == "") ?  div.show() : div.hide() ; 

          item.focus(function() {
            (item.val() == '') ? item.parent().find('.labeldiv').hide(): '' ;
          })
          .blur(function() {
            (item.val() == '') ? item.parent().find('.labeldiv').show(): '' ;
          });
        });

        $('.labeldiv', context).live('click', function() {
          $(this).parent().find('.form-text, .form-textarea').trigger('focus');
        });

      }
    };


    Drupal.behaviors.anonToolTip = {
      attach: function(context, settings) {
        $("img[title!=''], abbr[title!=''], acronym[title!='']").qtip({
          show: 'mouseover',
          hide: 'mouseout',
          style: { 
            name: 'dark',
            border: {
              width: 7,
              radius: 5
            },
            tip: 'leftBottom'
          },
          position: {
            target: 'mouse',
            adjust: { 
              mouse: true
            },
            corner: {
              target: 'topRight',
              tooltip: 'bottomLeft'
            }
          },
          show: { 
            delay: 300,
            effect: { 
              type: 'grow'
            } 
          }
        })
      }
    };


    Drupal.behaviors.fuck_IE_6_7 = {
      attach: function(context, settings) {
        // Add "focus" class to inputs and textareas when focus and remove it again on blur. 
        $(".not-logged-in .form-item input[type='text'], .not-logged-in .form-item textarea").focus(function(){
          $(this).addClass('focus');
        }).blur(function(){
          $(this).removeClass('focus');
        });
      }
    };
  

})(jQuery);

/**
 * MODIFYED by Emil Stjerneman / http://www.anon-design.se
 * ORIGINAL http://elbertf.com/ie6ify/
 */
(function($) {
	$.fn.IE6ify = function(options){
      
     $('.IE6ify').click(function() {
      var i = 0,
      r = function (n) {
          return Math.floor(Math.random() * n)
      },
      f = document.getElementsByTagName('body')[0].getElementsByTagName('*'),
      o = function (e) {
          return typeof(e.style) == 'object' && e.tagName != 'SCRIPT'
      },
      s = function () {
          while (!o(e = f[r(f.length)])) {}
          return e.style
      };
      while (i++<20) {
          s().display = r(2) ? 'block' : 'inline';
          s().position = r(2) ? 'absolute' : 'relative';
          s().margin = r(2) ? '0' : '1em';
          s().padding = r(2) ? '0' : '1em';
          s().width = r(2) ? '' : 'auto';
      }
    });
	};
})(jQuery);;

