
// center object
jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}



// pridanie priesvitneho pozadia example: $.overlay(200, 0.5);
jQuery.overlay = jQuery.fn.overlay = function(speed,opacity){
    speed = typeof(speed) != 'undefined' ? speed : 0;
    opacity = typeof(opacity) != 'undefined' ? opacity : 0.5;
    if($("#overlayShadow").length==0){
	$('body').append('<div id="overlayShadow" style="background-color:#000;opacity:0;position:fixed;left:0;right:0;top:0;bottom:0;"></div>');
    }
    $("#overlayShadow").fadeTo(speed,opacity);
    return this;
}
// odstranenie priesvitneho pozadia, example: $.overlayHide(200);
jQuery.overlayHide = jQuery.fn.overlayHide = function(speed){
    speed = typeof(speed) != 'undefined' ? speed : 200;
    $("#overlayShadow").fadeOut(speed,function(){$(this).remove()});
    return this;
}



// AutoScroll preskroluje na triedu ktoru chcem $('.area_name').autoscroll();
jQuery.fn.autoscroll = function(selector) {
    $('html,body').animate(
	{scrollTop: $(selector).offset().top},
	500
    );
}

// log jQuery events using Firebug and Firefox
// Usage: $('#someDiv').hide().log('div hidden').addClass('someClass');
jQuery.log = jQuery.fn.log = function (msg) {
      if (console){
         console.log("%s: %o", msg, this);
      }
      return this;
};


// input clearing
// How to use it: $('input').clearDefault();
(function($){
    $.fn.clearDefault = function(){
        return this.each(function(){
            var default_value = $(this).val();
            $(this).focus(function(){
                if ($(this).val() == default_value)
                             $(this).val("");
            });
            $(this).blur(function(){
                if ($(this).val() == "")
                              $(this).val(default_value);
            });
        });
    };
})(jQuery);
