(function($){
$.fn.commentscanner=function(o){
return this.each(function(){
new _3(this,o);
});
};
var _4={filter:"auto",imgwidth:45,imgheight:45,imgclass:"scanMug",onplay:false,onpause:false,format_item:function(_5){
var _6="";
var _7=$("userphoto",_5).text();
if(_7){
_6+="<a href=\"http://www.azcentral.com/members/User/"+$("username",_5).text()+"\"><img src=\""+_7+"/0/0/45/45\" class=\"scanMug\" /></a>";
}
_6+="<span class=\"h4hed\"><a href=\""+$("articleurl",_5).text()+"#comments\">"+$("headline",_5).text()+"</a></span>";
_6+="<span class=\"sidebar\"><em>Comment by: <strong class=\"scanName\"><a href=\"http://www.azcentral.com/members/User/"+$("username",_5).text()+"\">"+$("username",_5).text()+"</a></strong> <span class=\"scanRed\">@ "+$("formatted_date",_5).text()+"</span></em></span>";
_6+="<span class=\"sidebar\">"+$("text",_5).text()+"</span>";
_6+="<span class=\"sidebar\">("+$("totalcomments",_5).text()+") <a href=\""+$("articleurl",_5).text()+"#comments\">Comments</a> / <a href=\""+$("articleurl",_5).text()+"\">Read story</a> / <a href=\""+$("articleurl",_5).text()+"#commentform\">Post Comment</a></span>";
return _6;
}};
$.commentscanner=function(e,o){
this.options=$.extend({},_4,o||{});
this.container=$(e);
this.last_id=0;
this.ids=new Array();
this.incoming=new Array();
this.error_count=0;
this.empty_runs=0;
this.running=false;
if(!this.container||!this.container.html){
return false;
}
this.set_filter();
this.setup();
this.start();
};
var _3=$.commentscanner;
_3.fn=_3.prototype={commentscanner:"0.0.2"};
_3.fn.extend=_3.extend=$.extend;
_3.fn.extend({setup:function(){
var _a="";
_a+="\t\t<div class=\"azcLiveMask\"></div>\n";
_a+="\t\t<div class=\"azcLivePlayButton\"></div>\n";
_a+="\t\t<div class=\"azcLiveLogo\"></div>\n";
_a+="\t\t\n";
_a+="\t\t<div class=\"commentScanArea\"></div>\n";
_a+="\t\t<div class=\"commentScanAreaScrollable\"></div>\n";
_a+="\t\t\n";
_a+="\t\t";
_a+="<div class=\"scan_corner_botleft\"></div>";
_a+="<div class=\"scan_corner_botright\"></div>";
_a+="<div class=\"scan_corner_topleft\"></div>";
_a+="<div class=\"scan_corner_topright\"></div>";
_a+="\n";
this.container.html(_a);
},set_filter:function(){
if(this.options.filter!="auto"){
return;
}
var _b=window.location.toString();
if(_b.indexOf("/ent/celeb/")>0){
this.options.filter="/ent/celeb";
}else{
if(_b.indexOf("/ent/")>0){
this.options.filter="/ent";
}else{
if(_b.indexOf("/news/")>0||_b.indexOf("/business/")>0){
this.options.filter="/news,/business";
}else{
if(_b.indexOf("/style/")>0){
this.options.filter="/style";
}else{
if(_b.indexOf("/sports/")>0){
this.options.filter="/sports";
}else{
if(_b.indexOf("/community/")>0){
this.options.filter="/community";
}else{
this.options.filter="";
}
}
}
}
}
}
},inside_viewport:function(){
var _c=this.container.offset();
return _c.top<$(window).height()+$(window).scrollTop()&&_c.top+this.container.height()>$(window).scrollTop();
},cycle:function(){
var _d=this;
if(!this.running){
return;
}
if(this.ids.length==0||this.inside_viewport()){
if(this.incoming.length<3){
this.refill_incoming();
}
if(this.incoming.length>0){
_d.empty_runs=0;
this.display_new_comment();
setTimeout(function(){
_d.cycle();
},5000);
return;
}
}else{
}
if(this.ids.length>0&&this.incoming.length==0){
if(_d.empty_runs++>40){
setTimeout(function(){
_d.cycle();
},60000);
}else{
setTimeout(function(){
_d.cycle();
},15000);
}
}else{
setTimeout(function(){
_d.cycle();
},1000);
}
},refill_incoming:function(){
if(!this.request_active){
this.request_active=true;
var _e=$.extend({},{url:"/members/embed/",data:{id:"storychat-xml",max:"25",format:"xml",last_id:this.last_id,date_format:"%I:%M%p",filter:this.options.filter},dataType:"xml",self:this,success:this.parse_storychat_xml,error:function(_f,_10,_11){
var _12=this.self;
_12.request_active=false;
if(_12.error_count++>30){
_12.error_count=0;
_12.pause();
setTimeout(function(){
_12.start();
},30000);
}
}});
var _13=$.ajax(_e);
}
},parse_storychat_xml:function(xml){
var _15=this.self;
_15.request_active=false;
_15.error_count=0;
$(xml).find("comment").each(function(){
var _16=$(this);
var _17=_16.attr("id");
var _18=_15.options.format_item(_16);
_15.incoming.push({comment_id:_17,text:_18});
});
},display_new_comment:function(_19){
if(!this.running){
return;
}
if(typeof _19=="undefined"){
_19=false;
}else{
_19=true;
}
while(!_19&&this.ids.length<3&&this.display_new_comment(true)){
void (0);
}
if(this.incoming.length>0){
var _1a=this.incoming.shift();
if(this.last_id>0&&this.last_id>=_1a.comment_id){
var _1b=this;
setTimeout(function(){
_1b.display_new_comment();
},0);
return;
}
this.last_id=_1a.comment_id;
this.container.find(".commentScanArea").prepend("<div id='sc_item_"+_1a.comment_id+"' class='commentScanPost blocked-out' style='display: none;'></div>\n");
this.container.find("#sc_item_"+_1a.comment_id).html(_1a.text).slideDown("slow");
this.ids.push(_1a.comment_id);
if(this.ids.length>25){
var _1c=this.ids.shift();
this.container.find("#sc_item_"+_1c).hide().remove();
}
return true;
}else{
return false;
}
},pause:function(){
var _1d=this;
_1d.running=false;
if(typeof _1d.options.onpause=="function"){
_1d.container.find(".azcLivePlayButton").unbind("click").bind("click",function(){
_1d.start();
});
_1d.options.onpause(_1d);
}else{
_1d.container.find(".azcLivePlayButton").html("<div style='width: 18px; height: 18px;'></div>").unbind("click").bind("click",function(){
_1d.start();
}).css({background:"url(/imgs/azcLivePlay.gif)"});
}
var _1e=$(".commentScanArea").html();
_1d.container.find(".commentScanArea").html("").hide();
_1d.container.find(".commentScanAreaScrollable").html(_1e).show();
},start:function(){
var _1f=this;
_1f.running=true;
if(typeof _1f.options.onplay=="function"){
_1f.container.find(".azcLivePlayButton").unbind("click").bind("click",function(){
_1f.pause();
});
_1f.options.onplay(_1f);
}else{
_1f.container.find(".azcLivePlayButton").html("<div style='width: 18px; height: 18px;'></div>").unbind("click").bind("click",function(){
_1f.pause();
}).css({background:"url(/imgs/azcLivePause.gif)"});
}
var _20=_1f.container.find(".commentScanAreaScrollable").html();
_1f.container.find(".commentScanAreaScrollable").html("").hide();
_1f.container.find(".commentScanArea").html(_20).show();
_1f.cycle();
}});
})(jQuery);


