jQuery.fn.centrar=function(){this.css("top",(($(window).height()-this.outerHeight())/2)+$(window).scrollTop()+"px");this.css("left",(($(window).width()-this.outerWidth())/2)+$(window).scrollLeft()+"px");return this;};(function($){var _opciones;var _pos_bajada=false;$.fn.news_sorteo=function(opciones_accion,otros_argumentos){if(typeof(opciones_accion)=='string'){return eval(opciones_accion)(otros_argumentos);}else{_opciones=opciones_accion;init();}}
function init(){$('.newsletter button').attr('onclick','');$('.newsletter button').click(function(){_pos_bajada=false;muestra_ventana_sorteo()});$('.modulo_box_newsletter button').click(function(){_pos_bajada=true;muestra_ventana_sorteo()});}
function muestra_ventana_sorteo(){telon(true,function(){coloca_capa_contenedor(true,function(){$(document).keyup(function(e){if(e.keyCode==27)$().news_sorteo('cerrar_ventana_sorteo');});});});}
function cerrar_ventana_sorteo(){coloca_capa_contenedor(false,function(){telon(false,function(){$(parent.document).find('#newssorteo_telon').remove();$(parent.document).find('#newsorteo_contenedor').hide();});});}
function telon(estado,callback){if(estado){$('<div/>',{'id':'newssorteo_telon','style':'background:#000000; position:absolute; top:0px; left:0px; width:'+$(document).width()+'px; height:'+$(document).height()+'px; z-index:159;'}).css('opacity',0).click(function(){$().news_sorteo('cerrar_ventana_sorteo');}).appendTo($('body')).animate({'opacity':0.8},callback);}else{$(parent.document).find('#newssorteo_telon').animate({'opacity':0},callback);}}
function coloca_capa_contenedor(estado,callback){if(estado){var doc_width=$(document).width()/2;var left_pos=doc_width-(_opciones.width/2);var email_newsletter=$('#email_newsletter').val();var url_formulario=($('#email_newsletter').val()=='')?_opciones.url:_opciones.url+'?email='+email_newsletter;var pos_top=(_pos_bajada)?30:5;if($('#newsorteo_contenedor').length){var iframe=$('#newsorteo_contenedor').attr({'src':url_formulario});$(iframe).show();}else{var iframe=$('<iframe/>',{'id':'newsorteo_contenedor','border':0,'src':url_formulario,'style':'border:0px; background:#ffffff; width:'+_opciones.width+'px; height:'+_opciones.height+'px; z-index:160; position:absolute; '}).css('opacity',0).appendTo($('body'));}
$(iframe).centrar();$(iframe).animate({'opacity':1},callback);}else{$(parent.document).find('#newsorteo_contenedor').animate({'opacity':0},callback);}}})(jQuery);
