(function($){
 
    // Defining our jQuery plugin
 
    $.fn.paulund_modal_box = function(prop){
 
        // Default parameters
 		var element_title=$(this).attr('rel');
		var href_div_content=$($(this).attr("href")).html();
        var newModalBox=$(this).attr("href");
		var isItReady=false;
	    var options = $.extend({
            width : "500",
            title:element_title,
            description:"",
            top: "20%",
            left: "30%",
        },prop);
 
        return this.live('click', function(e){
			
            add_block_page();
				add_popup_box();
	
				add_styles(); 
            $(newModalBox).slideDown(700);
        });
 
         function add_styles(){
            $(newModalBox).css({
                'position':'absolute',
                'left':options.left,
                'top':0,
                'display':'none',
                'height': options.height + 'px',
                'width': options.width + 'px',
                'border':'1px solid #fff',
                'box-shadow': '0px 2px 7px #292929',
                '-moz-box-shadow': '0px 2px 7px #292929',
                '-webkit-box-shadow': '0px 2px 7px #292929',
                'background': '#f2f2f2',
                'z-index':'50',
            });
			$('.bm_modal_h2_title').css({
				'font-size':'18px',
				'text-shadow': '#fff 1px 1px 0px'
			});
            $('.paulund_modal_close').css({
                'position':'relative',
                'top':'-25px',
                'left':'20px',
                'float':'right',
                'display':'block',
                'height':'50px',
                'width':'50px',
                'background': ' transparent url(images/apps/bm/core/modal/close.png) no-repeat',
            });
                        /*Block page overlay*/
            var pageHeight = $(document).height();
            var pageWidth = $(window).width();
 
            $('.paulund_block_page').css({
                'position':'absolute',
                'top':'0',
                'left':'0',
                'background-color':'rgba(0,0,0,0.6)',
                'height':pageHeight,
                'width':pageWidth,
                'z-index':'10'
            });
            $('.paulund_inner_modal_box').css({
                //'height':(options.height - 50) + 'px',
                //'width':(options.width - 50) + 'px',
                'padding-top': '0px',
				'padding-right': '10px',
				'padding-bottom': '10px',
				'padding-left': '10px',
				'margin-top': '15px',
				'margin-right': '15px',
				'margin-bottom': '15px',
				'margin-left': '15px'
            });
			$('.bm_modal_hr').css({
				 	'width':'100%', 
					'height':0,
					'color':'none', 
					'background':'none', 
					'border':'none', 
					'border-top':'1px solid #E4E4E4', 
					'border-bottom':'1px solid #F9F9F9',
					'margin-top':'6px'

			});
			$('.bm_modal_content').css({
				'margin-left':'10px',
				'height':(options.height - 50) + 'px',
                'width':(options.width - 50) + 'px'
			});
        }
 
         function add_block_page(){
            var block_page = $('<div class="paulund_block_page"></div>');
 
            $(block_page).appendTo('body');
        }
 
         function add_popup_box(){
             //var pop_up = $('<div class="paulund_modal_box"></div>');
			 //append the title
			 
			 var addMoreContent='<a href="#" class="paulund_modal_close">x</a><div class="paulund_inner_modal_box"><h2 class="bm_modal_h2_title">' + options.title + '<hr class="bm_modal_hr"></h2><div>' + options.description + '</div></div>';
			 
				 $(newModalBox).prepend(addMoreContent);
             //$(addMoreContent).appendTo('.paulund_block_page');
             $('.paulund_modal_close').click(function(){
                $(this).parent().slideUp(700);
                $('.paulund_block_page').fadeOut().remove();
                $('.paulund_modal_close').fadeOut().remove();
				$('.paulund_inner_modal_box').fadeOut().remove();
				
             });
        }
 
        return this;
    };
 
})(jQuery);
