﻿(function ($) {
    var cache = [];
    // Arguments are image paths relative to the current page.
    $.preLoadImages = function () {
        var args_len = arguments.length;
        for (var i = args_len; i--; ) {
            var cacheImage = document.createElement('img');
            cacheImage.src = arguments[i];
            cache.push(cacheImage);
        }
    }
})(jQuery);

jQuery.fn.rollover = function () {
    return this.each(function () {
        //alert(this);
        $(this).hover(function () {
            var currentImg = $(this).attr('src');
            if (currentImg.indexOf("_on") > -1) {
                $(this).removeRollover();
            }
            else {
                $(this).attr('src', $(this).attr('rollover'));
                $(this).attr('rollover', currentImg);
            }
        },
        function () {
            var currentImg = $(this).attr('src');
            $(this).attr('src', $(this).attr('rollover'));
            $(this).attr('rollover', currentImg);
        });
    });
};

jQuery.fn.removeRollover = function () {
    return this.each(function () {
        $(this).removeClass('rollover');
    });
};

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;
}

jQuery.fn.DisableEnterKey = function () {
    return this.each(function () {
        $(this).keydown(function (e) {
            var key = e.charCode || e.keyCode || 0;
            // return false for the enter key
            return (key != 13);
        })
    })
};

/* NON JQUERY EXTENSIONS */
/*$('.btn').each(function(){
    var b = $(this);
    var tt = b.text() || b.val();
    if ($(':submit,:button',this)) {
        b = $('<a>').insertAfter(this). addClass(this.className).attr('id',this.id);
        $(this).remove();
    }
    b.text('').css({cursor:'pointer'}). prepend('<i></i>').append($('<span>').
    text(tt).append('<i></i><span></span>'));
});*/


