﻿
// Centers the elements in the wrapped set vertically within their containing divs
$.fn.vcentre = function() {
    // Get width of container
    this.each(function() {
        var cHeight = $(this.parentNode).innerHeight();
        var nodeHeight = $(this).outerHeight();
        var newPos = parseInt((cHeight / 2) - (nodeHeight / 2));
        $(this).css("margin-top", newPos + "px");
    });
}

// Centers the elements in the wrapped set horizontally within their containing divs
$.fn.hcentre = function() {
    // Get width of children within container
    
    this.each(function() {        
        var childrenWidth = 0;
        
        $(this).children().each(function() {
            childrenWidth += $(this).outerWidth(true);
        });
        
        $(this).css({
            width: childrenWidth + "px",
            display: "block",
            float: "none",
            margin: "auto"
        });
    });
}

// Kudos to http://blog.bmn.name/2008/03/jquery-fadeinfadeout-ie-cleartype-glitch/ for this work around for the ie fadein/out anti alias issue.
$.fn.customFadeIn = function(speed, callback) {
    $(this).fadeIn(speed, function() {
        if (jQuery.browser.msie)
            $(this).get(0).style.removeAttribute('filter');
        if (callback != undefined)
            callback();
    });
}

$.fn.customFadeOut = function(speed, callback) {
    $(this).fadeOut(speed, function() {
        if (jQuery.browser.msie)
            $(this).get(0).style.removeAttribute('filter');
        if (callback != undefined)
            callback();
    });
}
