$(document).ready(function(){messaging=function(i){function h(a){var c=$(document.createElement(a.type));typeof a.opts!="undefined"&&$.each(a.opts,function(d,e){c.attr(d,e)});typeof a.txt!="undefined"&&c.html(a.txt);typeof a.where=="undefined"?c.appendTo(a.into):c.prependTo(a.into);return c}i=i||{};var b={};$.extend(true,b,{colorbox:{transition:"none",speed:"350",title:false,rel:false,width:false,height:false,initialWidth:300,initialHeight:100,maxWidth:false,maxHeight:false,photoScaling:false,scrollbars:true,
iframe:false,photo:false,opacity:0.65,open:true,preloading:false,overlayClose:false},base_url:false,cache_html:true,additional_params:"",cache_response:false,require_response:true},i,{messaging_id:false});b.colorbox.inline=true;var j=false,f=false,k=0,l=0,g={init:function(){document.getElementById("messaging_popups")||h({into:"body",type:"div",opts:{id:"messaging_popups",style:"display: none;"}});if(b.messaging_id===false||$("#"+b.messaging_id).length==1){b.messaging_id=b.base_url.replace(/-/,"_")+
"_"+String((new Date).getTime()).replace(/\D/gi,"");h({into:$("#messaging_popups"),type:"div",opts:{id:"messaging_placeholder_"+b.messaging_id,style:"width:"+b.colorbox.initialWidth+"px; height:"+b.colorbox.initialHeight+"px;"}});h({into:"#messaging_placeholder_"+b.messaging_id,type:"div",opts:{id:b.messaging_id,"class":"messaging"}});b.colorbox.href="#messaging_placeholder_"+b.messaging_id;g.getHtml()}},getHtml:function(){$.ajax({url:"/messaging/"+(b.cache_html?"cache/":"")+b.base_url+"/html"+b.additional_params,
cache:true,success:function(a){if($("#"+b.messaging_id).length==1){$("#"+b.messaging_id).empty();$("#"+b.messaging_id).html(a)}else h({into:$("#messaging_popups"),type:"div",opts:{id:b.messaging_id,"class":"messaging"},txt:a})}})},getResponse:function(a,c,d){if(typeof a=="undefined"||a==null)a={empty:0};$.ajax({type:"post",url:"/messaging/"+(b.cache_response?"cache/":"")+b.base_url+b.additional_params,data:a,dataType:"json",success:function(e){if(b.cache_response)j=e;f||g.processResponseAndDisplayColorbox($.extend(true,
a,e),c,d)}})},processResponseAndDisplayColorbox:function(a,c,d){if(typeof a.success!="undefined"&&a.success===true&&f===false){f=true;$.each(a.data.messaging_js,function(e,m){k+=1;$.getScript(m,function(){k-=1})});$.each(a.data.messaging_css,function(e,m){l+=1;$.getScript(m,function(){l-=1},"css")});$("#"+b.messaging_id).ready(function(){if(typeof a.data=="undefined")a.data={};var e=setInterval(function(){if(k==0&&l==0){clearInterval(e);$.fn.colorbox(b.colorbox,function(){f=false});$.fn.colorbox.load("#"+
b.messaging_id);if(typeof c=="function")c(a);else typeof c=="string"&&typeof d=="string"&&window[d][c](a)}},225)})}}};this.resize=function(){$.fn.colorbox.resize()};this.close=function(a,c){$.fn.colorbox.close();if(typeof a=="function")a(response);else typeof a=="string"&&typeof c=="string"&&window[c][a](response)};this.display=function(a,c,d){if(typeof $.fn.colorbox=="function"&&!f){f=true;if(b.require_response)b.cache_response&&j!==false?g.processResponseAndDisplayColorbox(j,c,d):g.getResponse(a,
c,d);else g.processResponseAndDisplayColorbox({success:true,data:a},c,d);f=false}};g.init()}});
