/*
 * jQuery  Plugin jQPOOOP v 1.0.16
 * http://www.dieroboter.com/jQPOOOP/
 *
 * Copyright (c) 2009 Esteban Martin Gimenez
 *http://www.dieroboter.com
 * Dual licensed under the MIT and GPL licenses.
 *Email:jqpooop@gmail.com
 * Date: 2009-08-12 20:42:16 
 * Revision: 25
 */
 
(function($) {

$.fn.jqpooop = function(){


	
    this.each( function(){
			alert(this);
    });
}

$.fn.jqpooop.options_default = {
		 Unique:true,
		 Top:0,
		 Left:0,
		 Mensaje:"Ninguno",
		 Position:"absolute",
		 Ajax:" ",
		 Id:"Id",
		 Center:"true",
		 Width:200,
		 Height:100,
		 Headmsg:"Alert message"
	},

$.extend({
	'load':function(urlajax){
		
		$.ajax({
			'url':urlajax,
			'cache': false,
			'dataType': 'html',
			'type':'GET',
			success: function(msg)
			{
				//<a href="" class="accept"><span>Aceptar</span></a>
				$('<div id="'+ opc.Id +'" class="popup">'+ msg +'</div>').appendTo(document.body);
				var w = window.innerWidth ||document.documentElement.clientWidth || document.body.clientWidth;
				var h = window.innerHeight ||document.documentElement.clientHeight || document.body.clientHeight;
				
				w1 = $(window).scrollLeft() + (w - opc.Width )  /2; 
				h1 =  $(window).scrollTop() + (h - opc.Height ) /2;
				
				$('#'+opc.Id).css("top",h1+"px");
				$('#'+opc.Id).css("left",w1+"px");
				$('#'+opc.Id).css("display","");
				$('#'+opc.Id).css("z-index","1000");
				$('#'+opc.Id).css("position","absolute");
				
				
				//$('body').css('overflow','hidden');
				if ($('#modalpopup').size() == 0){
					$('body').append("<div id='modalpopup' class='modalpopupclass'></div>");
				}
				if ($.browser.msie){
					$('#modalpopup').css('height', $('body').height() + $(window).scrollTop() - 4 + 'px');
					$('body').css('overflow-y','hidden');
				}else{
					$('#modalpopup').css('height', $('html').height() + $(window).scrollTop() + 'px');
					if (window.innerHeight > $('html').height()){
						$('#modalpopup').css('height',  window.innerHeight + $(window).scrollTop() + 'px');
					}
				}
				$('#modalpopup').show();
			
				$(window).resize(function(){
					var w = window.innerWidth ||document.documentElement.clientWidth || document.body.clientWidth;
					var h = window.innerHeight ||document.documentElement.clientHeight || document.body.clientHeight;

					w1 = $(window).scrollLeft() + (w - opc.Width )  /2; 
					h1 =  $(window).scrollTop() + (h - opc.Height ) /2;
							
					$('#'+opc.Id).css("top",h1+"px");
					$('#'+opc.Id).css("left",w1+"px");
					
					// Added
					
					if ($.browser.msie){
						$('#modalpopup').css('height', $('body').height() + $(window).scrollTop() -4 + 'px');
						
					}else{
						$('#modalpopup').css('height', $('html').height() + $(window).scrollTop() + 'px');
						if (window.innerHeight > $('html').height()){
							$('#modalpopup').css('height',  window.innerHeight + $(window).scrollTop() + 'px');
						}
					}
					
					
					
				});
				
				$(window).scroll(function(){
					var w = window.innerWidth ||document.documentElement.clientWidth || document.body.clientWidth;
					var h = window.innerHeight ||document.documentElement.clientHeight || document.body.clientHeight;

					w1 = $(window).scrollLeft() + (w - opc.Width )  /2; 
					h1 =  $(window).scrollTop() + (h - opc.Height ) /2;
						
					$('#'+opc.Id).css("top",h1+"px");
					$('#'+opc.Id).css("left",w1+"px");
					
					// Added
					$('#modalpopup').css('left',  $(window).scrollLeft() + 'px');
				});
				
			}
		})
	},
'msg':function(msg){

			$('<div id="'+ opc.Id +'" class="popup"><h6>'+opc.Headmsg+'</h6><button id="botonpop'+ opc.Id +'" onclick="$(this).parent().remove()"><img src="imgs/close.gif"/></button><p>'+ msg +'</p><a href="" class="accept"><span>Aceptar</span></a></div>').appendTo(document.body);
			var w = window.innerWidth ||document.documentElement.clientWidth || document.body.clientWidth;
			var h = window.innerHeight ||document.documentElement.clientHeight || document.body.clientHeight;
			w1 =(w/2) - (opc.Width/2);
			h1 =(h/2) - (opc.Height/2);
			$('#'+opc.Id).css("top",h1+"px");
			$('#'+opc.Id).css("left",w1+"px");
			$('#'+opc.Id).css("display","");
			$('#'+opc.Id).css("z-index","1000");
			$('#'+opc.Id).css("position","absolute");
		
}	
	
	
});

$.jqpooop=function(options_user)
	{

		opc = $.extend( $.fn.jqpooop.options_default,options_user );

	
		if(opc.Unique==true && $('#'+opc.Id).length)
			{		
				return false;
			}
				
		if(opc.Ajax!=''){	
			this.load(opc.Ajax);	
				return false;
			}
		
		this.msg(opc.Mensaje);	
				return false;
	},

$.close=function(options_user)
	{
		opc = $.extend( $.fn.jqpooop.options_default,options_user );
		$('#'+opc.Id).remove();
	}

})(jQuery);


function closePopup(id){
	$('#' + id).remove();
	$('#modalpopup').hide();
	if ($.browser.msie){
		$('body').css('overflow-y','auto');
	}
	
}
