﻿/* ------------------------------------------------------------------------
	Class: magipopup
	Use: To popup a simple div in the centre of the screen
	Author: Martin Poucher
	Company: Magico.ie
	Version: 1.0
	Created: 11th March 2009
------------------------------------------------------------------------- */

(function($){
    $.fn.magipopup = function(options) {
        var settings = $.extend({
            elementToDisplay: null,
            popupWidth: "50%",
            popupHeight: "400px",
            popupBackground: "#fff",
            popupBorder: "2px solid #ccc"
        },options);
        
        return $.each($(this), function() {
            $(settings.elementToDisplay).hide();
            $(this).click(function(e){
                var popupDiv = "simple_popup_div";
                $(popupDiv).remove();
                var strSimple = "<div class='" + popupDiv + "' style='width:" + settings.popupWidth + ";height:" + settings.popupHeight + "'>\
                                    <div class='simple_popup_inner'>";
                strSimple += "<p><a class='simple_close' href='#'>[ x ] Close</a></p>";
                strSimple += $(settings.elementToDisplay).html();
                strSimple += "<p><a class='simple_close' href='#'>[ x ] Close</a></p></div></div>";
                $("body").append(strSimple);
                
                $("." + popupDiv).css({
                    top: e.clientY + 10 + "px",
                    left: ($(window).width() / 2) - ($("." + popupDiv).width() / 2) + "px",
                    position: "absolute",
                    background: settings.popupBackground,
                    border: settings.popupBorder,
                    overflow: "auto"
                });
                $(".simple_close").click(function(){
                    $("." + popupDiv).remove();
                    return false;
                });
                return false;
            });
        });
    };
})(jQuery);
