looping text slider with jQuery

setInterval(function(){
  //console.log("looped");
  $('#test li:first-child').fadeOut(420, "easeInCirc", function(){
    $(this).next('li').fadeIn(420, "easeInCirc").end().appendTo('#test');
  });
}, 2000);

Window close on "body" click

var login_win = jQuery('#loginWin');

$("a#login_link").click(function(){
login_win.fadeIn(200);
return false;
});

$("#loginWin .close").on('click',function(){
login_win.hide();
return false;
});

if($('#loginWin .error').text().length > 0) login_win.show();

var mouse_is_inside = false;

login_win.on({mouseenter:function(){
mouse_is_inside=true;
}, mouseleave:function(){
mouse_is_inside=false;
}
});

$('body').click(function(){
    if(!mouse_is_inside) {
        if (login_win.is(':visible')) login_win.hide();
    }
});

plural russian


function plural_str(i, str1, str2, str3){
  function plural (a){
    if ( a % 10 == 1 && a % 100 != 11 ) return 0
    else if ( a % 10 >= 2 && a % 10 <= 4 && ( a % 100 < 10 || a % 100 >= 20)) return 1
    else return 2;
  }
  switch (plural(i)) {
    case 0: return str1;
    case 1: return str2;
    default: return str3;
  }
}

example:
var num = 12;
plural_str(num, ‘товар’,'товара’,'товаров’); // 12 товаров

jQuery setTimeout() Function

setTimeout(function() {
      // Do something after 5 seconds
}, 5000);

Create jQuery function

(function($) {
jQuery.fn.doSomething = function() {
return this.each(function() {
var $this = $(this);
$this.click(function(event) {
event.preventDefault();
// Your function goes here
});
});
};
})(jQuery);

$(document).ready(function() {
$('#div1').doSomething();
$('#div2').doSomething();
});

Simple login window popup system

var _initialize = function () {
_doc = jQuery(document);
_win = jQuery(window);
_docHeight = _doc.height();
_winHeight = _win.height();
_winWidth = _win.width();
_overlay = jQuery('#myoverlay');
_logw = jQuery('#loginWindow');
};
var _center = function (w, h) { //center aligning of window
return [(_docHeight > _winHeight) ? _winWidth/2 - w/2 - 18: _winWidth/2 - w/2, _doc.scrollTop() + _winHeight/2 - h/2];
};
var _show = function(){
_overlay.show();
var pos = _center(_logw.width(), _logw.height());
_logw.css({left: pos[0] + 'px',top: pos[1] + 'px'}).show();
};
var _hide= function(){
_logw.hide();
_overlay.hide();
};
var _login= function(){
_initialize();
if($('.notify').text().length > 0 || _logw.hasClass('passwordRemindForm')) {
_show();
}
var mouse_is_inside = false;
$('.openLogin').click(function(){
_show(); return false
});
_logw.live({mouseenter:function(){
mouse_is_inside=true;
}, mouseleave:function(){
mouse_is_inside=false;
}
});
$('body').click(function(){
if(!mouse_is_inside) {
if (_logw.is(':visible')) {
_hide();
}
}
});
if(_logw.hasClass('passwordRemindForm')) {
$('body').unbind('click');
}
$('.close').live('click', function(){
_hide(); return false;
});
};


$(document).ready(function(){
_login(); //init login popup system
});

Vertical aligning of images

function imgValignCenter(parent) {
var img = $(parent).find('img');
$(img).load(function() {
var wrHeight = $(parent).height();
var imgHeight = $(img).height();
var imgTopPos = (wrHeight - imgHeight)/2;
$(img).css('margin-top', imgTopPos+'px');
});
}

$(document).ready(function(){
$('.parentImgDiv').each(function(){
imgValignCenter($(this));
});
});

Remove http from website url

var url = $('.website a').text();
newurl = url.replace(/^https?:\/\//,'')
var urlarr = newurl.split('/');
if (urlarr.length > 1) newurl = urlarr[0];
$('.website a').text(newurl);