﻿function ShowPopup(id, pos) {
    switch (pos) {
        case "middleCenter":
            $('#' + id).middleCenter();
            $(window).scroll(function() {
                $('#' + id).middleCenter();
            });
            break;
        case "scrollTopLeft":
            $('#' + id).scrollTopLeft();
            $(window).scroll(function() {
                $('#' + id).scrollTopLeft();
            });
            break;
        case "scrollTopRight":
            $('#' + id).scrollTopRight();
            $(window).scroll(function() {
                $('#' + id).scrollTopRight();
            });
        case "scrollBottomLeft":
            $('#' + id).scrollBottomLeft();
            $(window).scroll(function() {
                $('#' + id).scrollBottomLeft();
            });
        case "scrollBottomRight":
            $('#' + id).scrollBottomRight();
            $(window).scroll(function() {
                $('#' + id).scrollBottomRight();
            });
    }

    $('#' + id).css('z-index', '6000');
    $('#' + id).fadeIn('fast');
    return true;
}

function HidePopup(id) {
    $('#' + id).css({ "display": "none" });
    $(window).unbind('scroll');
}


jQuery.fn.middleCenter = function() {
    this.css("position", "absolute");
    this.css("top", ($(window).height() - this.outerHeight()) / 2 + $(window).scrollTop() + "px");
    this.css("left", ($(window).width() - this.outerWidth()) / 2 + $(window).scrollLeft() + "px");
    return this;
}

jQuery.fn.topLeft = function() {
    this.css("position", "absolute");
    this.css("top", "0px");
    this.css("left", "0px");
    return this;
}
jQuery.fn.scrollTopLeft = function() {
    this.css("position", "absolute");
    this.css("top", $(window).scrollTop() + "px");
    this.css("left", "0px");
    return this;
}

jQuery.fn.topRight = function() {
    this.css("position", "absolute");
    this.css("top", "0px");
    this.css("left", ($(window).width() - this.outerWidth()) + "px");
    return this;
}
jQuery.fn.scrollTopRight = function() {
    this.css("position", "absolute");
    this.css("top", $(window).scrollTop() + "px");
    this.css("left", ($(window).width() - this.outerWidth()) + $(window).scrollLeft() + "px");
    return this;
}

jQuery.fn.bottomLeft = function() {
    this.css("position", "absolute");
    this.css("top", ($(window).height() - this.outerHeight()) + "px");
    this.css("left", "0px");
    return this;
}
jQuery.fn.scrollBottomLeft = function() {
    this.css("position", "absolute");
    this.css("top", ($(window).height() - this.outerHeight()) + $(window).scrollTop() + "px");
    this.css("left", "0px");
    return this;
}

jQuery.fn.bottomRight = function() {
    this.css("position", "absolute");
    this.css("top", ($(window).height() - this.outerHeight()) + "px");
    this.css("left", ($(window).width() - this.outerWidth()) + "px");
    return this;
}
jQuery.fn.scrollBottomRight = function() {
    this.css("position", "absolute");
    this.css("top", ($(window).height() - this.outerHeight()) + $(window).scrollTop() + "px");
    this.css("left", ($(window).width() - this.outerWidth()) + $(window).scrollLeft() + "px");
    return this;
}
