var invitationWidget=null;function InvitationWidget(e,b,c){this.inviteConn=null;this.inviteCallback={success:function(j){input=j.responseText;if(input.indexOf("\n")!=-1){var h=input.split("\n");var i=h[1].split("\x01");var g=h[4];for(var f=0;f<i.length;f++){if(i[f].indexOf("\x02")!=-1){parts=i[f].split("\x02");invitationWidget.newInvite(parts[0],parts[1],parts[2],((parts[3]=="0")?0:1),parts[4]*1000);if(g=="open"&&invitationWidget.popoutMode==0){invitationWidget.open()}}}}},cache:false,timeout:10000};this.sendConn=null;this.sendOnlyCallback={cache:false};this.activeInvites=new Array();this.inactiveInvites=new Array();this.connPath="/updatedchat/handler/processor.php";this.maxVisibleElements=5;this.elementHeight=141;this.userid=c;this.popoutMode=e;this.minimized=false;this.closedStatus=b;this.busyDuration=300000;this.pollDelay=14000;this.visibleTimeout=120;this.timeout=this.visibleTimeout+Math.round(this.pollDelay/1000);this.animator=null;this.self=document.getElementById("invitations-widget");this.minbutton=document.getElementById("inv-minimize");this.popbutton=document.getElementById("inv-popout");this.closebutton=document.getElementById("inv-close");this.header=document.getElementById("inv-header");this.title=document.getElementById("inv-header-text");this.body=document.getElementById("inv-body");this.invites=document.getElementById("inv-list");this.originalTop=188;this.originalLeft=872;this.maxBodyHeight=(this.elementHeight+2)*this.maxVisibleElements+2;this.popoutHeight=this.maxBodyHeight+63;this.restoreParentWindow=function(){if(window.opener){window.opener.invitationWidget.sendConn=YAHOO.util.Connect.asyncRequest("GET","/updatedchat/invitations.php?__tcAction=popoutClosed",window.opener.invitationWidget.sendOnlyCallback,null);var g=new Date().getTime();for(var h=0;h<invitationWidget.activeInvites.length;h++){var f=g-invitationWidget.activeInvites[h].created;window.opener.invitationWidget.newInvite(invitationWidget.activeInvites[h].id,invitationWidget.activeInvites[h].profile,invitationWidget.activeInvites[h].name,invitationWidget.activeInvites[h].video,f)}window.opener.invitationWidget.open();window.opener.invitationWidget.resizeLength(window.opener.invitationWidget.activeInvites.length)}else{invitationWidget.sendConn=YAHOO.util.Connect.asyncRequest("GET","/updatedchat/invitations.php?__tcAction=popoutClosed",invitationWidget.sendOnlyCallback,null)}};this.closeSession=function(){invitationWidget.closedMode();while(invitationWidget.activeInvites.length>0){invitationWidget.rejectInvite(invitationWidget.activeInvites[0].profile)}};this.updatePositionOnResize=function(){if(invitationWidget.minimized){invitationWidget.self.style.top=invitationWidget.calcMinimizedTop()+"px";invitationWidget.self.style.left=invitationWidget.calcMinimizedLeft()+"px"}};this.setTitle=function(f){this.title.innerHTML=f};this.resizeLength=function(g){if(!this.minimized){var f=this.maxBodyHeight;if(g>this.maxVisibleElements){this.body.style.overflowY="scroll";f=8+this.maxVisibleElements*this.elementHeight}else{if(g>0){this.body.style.overflowY="hidden";this.body.scrollTop="0px";f=2+g*(this.elementHeight+2)}else{this.body.style.overflowY="hidden";this.body.scrollTop="0px";f=0}}if(!this.popoutMode){this.animator=new YAHOO.util.Anim(this.body.id,{height:{to:f}},0.5,YAHOO.util.Easing.easeBoth);this.animator.animate()}else{this.body.style.height=this.maxBodyHeight+"px"}}};this.checkInvites=function(){var f=this.pollDelay;if(this.closedMode){f=this.pollDelay*2}this.inviteConn=YAHOO.util.Connect.asyncRequest("GET",this.connPath+"?action=checkinvites&id="+this.userid+"&popout="+this.popoutMode,this.inviteCallback,null);setTimeout("invitationWidget.checkInvites()",f)};this.updateTimers=function(){var k=new Date().getTime();for(var l=0;l<this.activeInvites.length;l++){var g=this.timeout-((k-this.activeInvites[l].created)/1000);var f=g/this.visibleTimeout;if(g>0){for(var h=0;h<this.activeInvites[l].timer.rows[0].cells.length;h++){if(((h+1)/this.activeInvites[l].timer.rows[0].cells.length)>f){this.activeInvites[l].timer.rows[0].cells[h].className="expired"}}}else{this.removeInvite(l)}}setTimeout("invitationWidget.updateTimers()",3000)};this.cleanOldInvites=function(){var f=new Date().getTime();if(this.inactiveInvites.length>0&&this.inactiveInvites[0].destroy<f){this.inactiveInvites.splice(0,1)}setTimeout("invitationWidget.cleanOldInvites()",10000)};this.minimize=function(){if(this.minimized){this.minimized=false;this.animator=new YAHOO.util.Motion(this.self.id,{points:{to:[this.originalLeft,this.originalTop]}},0.25,YAHOO.util.Easing.easeBoth);this.animator.onComplete.subscribe(function(){invitationWidget.self.style.top=invitationWidget.originalTop+"px";invitationWidget.resizeLength(invitationWidget.activeInvites.length)});this.animator.animate();this.minbutton.src="/images/new/invitations/icon-min.gif";this.minbutton.title="Minimize"}else{this.minimized=true;this.body.style.overflowY="hidden";this.animator=new YAHOO.util.Anim(this.body.id,{height:{to:0}},0.25,YAHOO.util.Easing.easeBoth);this.animator.onComplete.subscribe(function(){invitationWidget.animator=new YAHOO.util.Motion(invitationWidget.self.id,{points:{to:[invitationWidget.calcMinimizedLeft(),invitationWidget.calcMinimizedTop()]}},0.5,YAHOO.util.Easing.easeBoth);invitationWidget.animator.animate()});this.animator.animate();this.minbutton.src="/images/new/invitations/icon-max.gif";this.minbutton.title="Maximize"}};this.lookupInvite=function(g){for(var f=0;f<this.activeInvites.length;f++){if(this.activeInvites[f].profile==g){return f}}return null};this.calcMinimizedTop=function(){var g=document.documentElement.scrollTop+(document.documentElement.clientHeight-this.header.offsetHeight);var f=document.documentElement.offsetHeight-(this.header.scrollHeight+document.getElementById("Hot-Russian-Dating").offsetHeight+4);return Math.min(g,f)};this.calcMinimizedLeft=function(){return this.originalLeft};this.newInvite=function(h,l,g,j,o){if(!this.closedMode){this.open()}if(this.lookupInvite(l)==null){var k="invitation-timer"+l;var f=(j)?"":"visibility: hidden;";var q=this.invites.insertRow(this.invites.rows.length).insertCell(0);q.id="invitation-cell"+l;q.className="inv-invite";q.vAlign="top";q.innerHTML='<div class="inv-portrait"><img src="/i/im'+l+'_small.jpg" width=100 height=133 style="display:block;" /></div><div class="inv-content"><h2 class="inv-title">'+g+' would like to chat</h2><div class="inv-buttoncol"><img src="/images/new/invitations/button-chatnow.png" class="inv-chatnow" onclick="invitationWidget.acceptInvite('+l+')" /><img src="/images/new/invitations/button-livevideo.gif" class="inv-viewvideo" style="'+f+'" onclick="invitationWidget.viewVideo('+l+')" /></div><a class="inv-link" target="_blank" href="/'+l+'.html" style="margin-top:1px;">View Profile</a><a class="inv-link" onclick="invitationWidget.rejectInvite('+l+')">No Thanks</a><a class="inv-link" onclick="invitationWidget.blockUser('+l+')">Block User</a><table id="'+k+'" cellspacing=2 class="inv-timer"><tr></tr></table></div>';var n=document.getElementById(k);this.activeInvites.push(new Invitation(h,l,g,j,o,q,n));var p;for(var m=0;m<15;m++){p=n.rows[0].insertCell(0);p.innerHTML='<img src="/images/spacer.gif" width=7 height=1 />'}}this.resizeLength(this.activeInvites.length)};this.removeInvite=function(f){this.activeInvites[f].invite.innerHTML="";this.activeInvites[f].invite.style.background="none";this.inactiveInvites.push(new InactiveInvitation(this.activeInvites[f]));if((f+1)==this.activeInvites.length){this.activeInvites.pop()}else{this.activeInvites.splice(f,1)}this.resizeLength(this.activeInvites.length)};this.acceptInvite=function(g){var f=this.lookupInvite(g);this.sendConn=YAHOO.util.Connect.asyncRequest("GET",this.connPath+"?id="+this.userid+"&inviteid="+this.activeInvites[f].id+"&recipient="+this.activeInvites[f].profile+"&action=acceptinvite",this.sendOnlyCallback,null);window.open("/updatedchat/clientchat.php?id="+this.userid+"&recipient="+g,"chat_"+g,"width=737,height=700,status=yes",false);this.removeInvite(f)};this.viewVideo=function(f){window.open("/updatedchat/clientchat.php?recipient="+f+"&id="+this.userid+"&startVideo=1","chat_"+f,"width=737, height=700, scrollbars=1");this.removeInvite(this.lookupInvite(f))};this.blockUser=function(g){var f=this.lookupInvite(g);this.sendConn=YAHOO.util.Connect.asyncRequest("GET",this.connPath+"?action=block&recipient="+this.activeInvites[f].profile,this.sendOnlyCallback,null);this.removeInvite(f)};this.rejectInvite=function(g){var f=this.lookupInvite(g);this.sendConn=YAHOO.util.Connect.asyncRequest("GET",this.connPath+"?action=rejectinvite&id="+this.userid+"&inviteid="+this.activeInvites[f].id+"&recipient="+this.activeInvites[f].profile,this.sendOnlyCallback,null);this.removeInvite(f)};this.setBusyStatus=function(){this.sendConn=YAHOO.util.Connect.asyncRequest("GET",this.connPath+"?action=donotdisturb&id="+this.userid,this.sendOnlyCallback,null);this.closedMode()};this.open=function(){this.self.style.display="";this.closedStatus=false};this.popout=function(){window.open("/updatedchat/invitations.php","_blank","width=306,height="+this.popoutHeight+",scrollbars=no,status=no,toolbar=no,location=no,directories=no");this.closedMode()};this.closedMode=function(){this.self.style.display="none";this.closedStatus=true};if(this.popoutMode){this.minbutton.style.visibility="hidden";this.popbutton.style.visibility="hidden";this.closebutton.style.visibility="hidden";this.body.style.height=this.maxBodyHeight+"px";this.self.style.display="";var d=new Date().getTime();while(window.opener.invitationWidget.activeInvites.length>0){var a=d-window.opener.invitationWidget.activeInvites[0].created;this.newInvite(window.opener.invitationWidget.activeInvites[0].id,window.opener.invitationWidget.activeInvites[0].profile,window.opener.invitationWidget.activeInvites[0].name,window.opener.invitationWidget.activeInvites[0].video,a);window.opener.invitationWidget.removeInvite(0)}YAHOO.util.Event.addListener(window,"beforeunload",this.restoreParentWindow)}else{YAHOO.util.Event.addListener(window,"resize",this.updatePositionOnResize);YAHOO.util.Event.addListener(window,"scroll",this.updatePositionOnResize)}return this}function Invitation(g,e,d,f,b,c,a){this.id=g;this.profile=e;this.name=d;this.video=f;this.created=new Date().getTime()-b;this.invite=c;this.timer=a;return this}function InactiveInvitation(a){this.activeRecord=a;this.destroy=new Date().getTime();this.collapse=new YAHOO.util.Anim(this.activeRecord.invite.id,{height:{to:0}},0.5,YAHOO.util.Easing.easeBoth);this.collapse.onComplete.subscribe(function(){this.getEl().parentNode.parentNode.deleteRow(this.getEl().parentNode.rowIndex)});this.collapse.animate()}function startupInvitations(c,b,a){if(a>0){invitationWidget=new InvitationWidget(c,b,a);setTimeout("invitationWidget.updateTimers()",1000);setTimeout("invitationWidget.cleanOldInvites()",10000);invitationWidget.checkInvites()}};