/***
@title:
Center

@version:
2.0

@author:
Andreas Lagerkvist

@date:
2008-09-17

@url:
http://andreaslagerkvist.com/jquery/center/

@license:
http://creativecommons.org/licenses/by/3.0/

@copyright:
2008 Andreas Lagerkvist (andreaslagerkvist.com)

@requires:
jquery

@does:
This little pluggy centers an element on the screen using either fixed or absolute positioning. Can be used to display messages, pop up images etc.

@howto:
jQuery('#my-element').center(true); would center the element with ID 'my-element' using absolute position (leave empty for fixed).

@exampleHTML:
<p>I should be fixed centered</p>

<p>The paragraph above and the paragraph beneath this one are centered. They should be in the middle of the viewport.</p>

<p>I should be absolutely centered</p>

@exampleJS:
jQuery('#jquery-center-example p:first-child').center();
jQuery('#jquery-center-example p:last-child').center(true);
***/
jQuery.fn.center = function (absolute) {
    return this.each(function () {
        var t = jQuery(this);
        var userAgent = navigator.userAgent;

        if (userAgent.match(/MSIE 9/i)) {
            if (t.hasClass("footerContent")) {
                t.css("position", "absolute");
                if (t.parents("body").hasClass("ConductorOverview")) {
                    var leftPosition = jQuery('.main').offset().left;
                } else if (t.parents("body").hasClass("ConductorMaster")) {
                    var leftPosition = jQuery('.main').offset().left + 150;
                } else if (t.parents("body").hasClass("ConnectOverview") || t.parents("body").hasClass("ConnectMaster")) {
                    var leftPosition = jQuery('.main').offset().left - 200;
                }
                t.css("left", leftPosition);
            } else if (t.hasClass("PartnersBandContent")) {
                t.css("position", "absolute");
                if (t.parents("body").hasClass("ConductorOverview") || t.parents("body").hasClass("ConductorMaster")) {
                    var leftPosition = jQuery('.main').offset().left;
                } else if (t.parents("body").hasClass("ConnectOverview") || t.parents("body").hasClass("ConnectMaster")) {
                    var leftPosition = jQuery('.main').offset().left - 200;
                }
                t.css("left", leftPosition);
            } else if (t.attr("id") == "CrowdFull") {
                t.css("left", "50%");
                t.css("margin-left", "-1430px");
            }

        } else {
            t.css({
                position: absolute ? 'absolute' : 'fixed',
                left: '50%'
            }).css({
                marginLeft: '-' + (t.outerWidth() / 2) + 'px'
            });

            if (absolute) {
                t.css({
                    //marginTop:	parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
                    marginLeft: parseInt(t.css('marginLeft'), 10) + jQuery(window).scrollLeft()
                });
            }
        }
    });
};

jQuery.fn.OverviewCenter = function (absolute) {
    return this.each(function () {
        var t = jQuery(this);
        var userAgent = navigator.userAgent;

        if (userAgent.match(/MSIE 9/i)) {
            if (t.attr("class").match(/footerContent/i)) {
                t.css("position", "absolute");
                var leftPosition = jQuery('.main').offset().left;
                t.css("left", leftPosition);
            } else if (t.attr("class").match(/PartnersBandContent/i)) {
                t.css("position", "absolute");
                var leftPosition = jQuery('.main').offset().left;
                t.css("left", leftPosition);
            }
        }
    });
};


jQuery.fn.GatewayCenter = function (absolute) {
    return this.each(function () {
        var t = jQuery(this);

        t.css({
            position: absolute ? 'absolute' : 'fixed',
            left: '50%'
        }).css({
            marginLeft: '-' + ((t.outerWidth() / 2) +0) + 'px'
        });

        if (absolute) {
            t.css({
                //marginTop:	parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
                marginLeft: parseInt(t.css('marginLeft'), 10) + jQuery(window).scrollLeft()
            });
        }
    });
};
jQuery.fn.GatewayMedallionCenter = function (absolute) {
    return this.each(function () {
        var t = jQuery(this);

        t.css({
            position: absolute ? 'absolute' : 'fixed',
            left: '50%'
        }).css({
            marginLeft: '-' + ((t.outerWidth() / 2) - 12 ) + 'px'
        });

        if (absolute) {
            t.css({
                //marginTop:	parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
                marginLeft: parseInt(t.css('marginLeft'), 10) + jQuery(window).scrollLeft()
            });
        }
    });
};

jQuery.fn.LeftBorderCenter = function (absolute) {
    return this.each(function () {
        var t = jQuery(this);

        t.css({
            position: absolute ? 'absolute' : 'fixed',
            left: '0'
        }).css({
            //marginLeft: '-' + (t.outerWidth()-10) + 'px'
            marginLeft: 0 + 'px'
        });

        if (absolute) {
            var marginleft = t.css('margin-left');
            t.css({
                //marginTop:	parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
                marginLeft: parseInt(t.css(marginleft), 10) + jQuery(window).scrollLeft()
            });
        }
        var userAgent = navigator.userAgent;

        if (userAgent.match(/MSIE 9/i)) {
            var innerWidth = jQuery(window).innerWidth();
            //if (outerWidth < -400) { outerWidth = -400; }
            if (innerWidth >= 1200) {
                t.css("left", "50%");
                t.css("margin-left", "-1000px");
            } else {
                t.css("left", "-400px");
            }
        }
    });
};

jQuery.fn.LeftBorderCenterIE9 = function () {
    return this.each(function () {
        var t = jQuery(this);

        t.css("position", "absolute");
        //t.css("left", "-386px");
        t.css("left", "0").css("marginLeft", "0px");
        var marginleft = t.css('margin-left');
        t.css({
            left: "-"+((jQuery(window).innerWidth() - 591)/2)+"px"
        });
    });
};

jQuery.fn.RightBorderCenter = function (absolute) {
    return this.each(function () {
        var t = jQuery(this);
        t.css({
            position: absolute ? 'absolute' : 'fixed',
            right: '0'
        }).css({
            //marginLeft: '-' + (t.outerWidth()-10) + 'px'
            marginRight: 20 + 'px'
        });

        if (absolute) {
            var marginleft = t.css('margin-left');
            t.css({
                //marginTop:	parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
                marginLeft: parseInt(t.css(marginleft), 10) + jQuery(window).scrollLeft()
            });
        }
        var userAgent = navigator.userAgent;

        if (userAgent.match(/MSIE 9/i)) {
            var innerWidth = jQuery(window).innerWidth();
            //if (innerWidth >= 1200) {
                t.css("left", "50%");
                t.css("margin-left", "385px");
            //} else {
            //    t.css("left", "200px");
            //}
        }
    });
};

jQuery.fn.RightNavCenter = function (absolute) {
    return this.each(function () {
        var t = jQuery(this);

        t.css({
            position: absolute ? 'absolute' : 'fixed',
            left: '50%'
        }).css({
            //marginLeft: '-' + (t.outerWidth() / 1) + 'px'
            marginLeft: '244px'
        });

        if (absolute) {
            var marginleft = t.css('margin-left');
            t.css({
                //marginTop:	parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
                marginLeft: parseInt(t.css(marginleft), 10) + jQuery(window).scrollLeft()
            });
        }
    });
};

jQuery.fn.LeftNavCenter = function (absolute) {
    return this.each(function () {
        var t = jQuery(this);

        t.css({
            position: absolute ? 'absolute' : 'fixed',
            left: '50%'
        }).css({
            marginLeft: '-553px'
        });

        if (absolute) {
            var marginleft = t.css('margin-left');
            t.css({
                //marginTop:	parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
                marginLeft: parseInt(t.css(marginleft), 10) + jQuery(window).scrollLeft()
            });
        }
    });
};

jQuery.fn.ConductorNavCenter = function (absolute) {
    return this.each(function () {
        var t = jQuery(this);
        t.css({
            position: absolute ? 'absolute' : 'fixed',
            left: '50%'
        }).css({
            marginLeft: '-' + (t.outerWidth() / 3) + 'px'
        });

        if (absolute) {
            var marginleft = t.css('margin-left');
            t.css({
                //marginTop:	parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
                marginLeft: parseInt(t.css(marginleft), 10) + jQuery(window).scrollLeft()
            });
        }
    });
};

jQuery.fn.ConductorOverviewNavCenter = function (absolute) {
    return this.each(function () {
        var t = jQuery(this);
        t.css({
            position: absolute ? 'absolute' : 'fixed',
            left: '50%'
        }).css({
            marginLeft: '-' + (t.outerWidth() / 2) + 'px'
        });

        if (absolute) {
            var marginleft = t.css('margin-left');
            t.css({
                //marginTop:	parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
                marginLeft: parseInt(t.css(marginleft), 10) + jQuery(window).scrollLeft()
            });
        }
    });
};

jQuery.fn.ConductorHighlightCenter = function (absolute) {
    return this.each(function () {
        var t = jQuery(this);
        t.css({
            position: absolute ? 'absolute' : 'fixed',
            left: '50%'
        }).css({
            marginLeft: '-' + ((t.outerWidth() / 2) - 600) + 'px'
        });

        if (absolute) {
            var marginleft = t.css('margin-left');
            t.css({
                //marginTop:	parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
                marginLeft: parseInt(t.css(marginleft), 10) + jQuery(window).scrollLeft()
            });
        }
    });
};

