(function(){var artRating={staticContentURL:"",rated:false,avgRating:0,numRatings:0,PV:[],childWin:function(el,height,width){var h=height||610;var w=width||970;if(jQuery.browser.msie&&jQuery.browser.version<7){h=720;w=980}if(el.href){window.open(el.href,"_blank","height="+h+",width="+w+",status=yes,location=yes,toolbar=yes,directories=yes,menubar=yes,resizable=yes,scrollbars=yes")}},createRatingsWidget:function(container){var a,fn,inp=jQuery("#"+container.attr("id").replace(/-widget/,""));nRatingTxt="  Average rating (based on "+artRating.numRatings+(artRating.numRatings!=1?" votes":" vote")+")";
yrRatingTxt="  Your rating";for(var i=1;i<=5;i++){a=jQuery('<a href="javascript:void(0);"><img alt="'+i+(i>1?" stars":" star")+'" title="Click to rate '+i+(i>1?" stars":" star")+'" height="20" src="'+artRating.staticContentURL+'star-off.gif" width="20"/></a>');a.bind("click",function(){var nv=parseInt(jQuery(this).find("img:first").attr("alt"),10);if(isNaN(nv)){nv=0}inp.attr("value",nv);artRating.rated=true;jQuery(this).parent().find("a").each(function(j){jQuery(this).find("img:first").attr("title","Average rating of "+artRating.avgRating+(artRating.avgRating>1?" stars":" star")+" (You rated this "+nv+(nv>1?" stars":" star")+")")
});artRating.submitRating(nv);container.fadeOut(3000,function(){inp.attr("value",artRating.avgRating);artRating.rated=false;nRatingTxt="  Average rating";var a=container.find("a:first");a.fn=artRating.fn;a.fn();container.fadeIn(1000)});container.find("a").each(function(){jQuery(this).unbind()})});fn=function(){(artRating.rated)?jQuery("#rateTxt").html(yrRatingTxt):jQuery("#rateTxt").html(nRatingTxt);var v=parseInt(inp.attr("value"),10);jQuery(this).parent().find("a").each(function(j){if(j<v){jQuery(this).find("img:first").attr("src",artRating.staticContentURL+((artRating.rated)?"star-on.gif":"avg-star-on.gif"))
}else{jQuery(this).find("img:first").attr("src",artRating.staticContentURL+"star-off.gif")}})};a.bind("mouseout",fn);a.bind("mouseover",function(){jQuery("#rateTxt").html(yrRatingTxt);var me=jQuery(this);var tv=parseInt(me.find("img:first").attr("alt"),10);me.parent().find("a").each(function(j){if(j<tv){jQuery(this).find("img:first").attr("src",artRating.staticContentURL+"star-on.gif")}else{jQuery(this).find("img:first").attr("src",artRating.staticContentURL+"star-off.gif")}})});container.append(a);
if(i===5){artRating.fn=a.fn=fn;a.fn()}}a=jQuery('<span id="rateTxt"></span>');a.html(nRatingTxt);container.append(a)},submitRating:function(rating){var tPV=[];jQuery.each(PV,function(n,v){tPV.push(n+"="+v)});jQuery.ajax({type:"POST",url:"/developerworks/utils/RatingsHandler",data:tPV.join("&")+"&OtherApp=dwmavajax&Rating="+rating,success:function(msg){var json=eval("("+msg+")");if(json&&json.status!==undefined){if(json.status!=="success"){setTimeout("artRating.submitRating("+rating+")",10000)}}},error:function(msg){setTimeout("artRating.submitRating("+rating+")",10000)
}})},init:function(widgetId){var _wId=widgetId||"ibm-sbab-ratinga-widget";if(typeof jQuery==="undefined"){setTimeout(artRating.init,250);return }jQuery(document).ready(function(){PV=jQuery.makeArray(jQuery("div.metavalue"));var tPV={};jQuery.each(PV,function(){var t=jQuery(this).text().split("=");tPV[t[0]]=t[1]});PV=tPV;artRating.staticContentURL=PV["static.content.url"];jQuery.getJSON("/developerworks/utils/ratingJSON.jsp?article="+PV.ArticleID,function(data){var inp=jQuery("#"+_wId.replace(/-widget/,""));
artRating.avgRating=Math.round(data.avg_rating);if(isNaN(artRating.avgRating)){artRating.avgRating=0}inp.attr("value",artRating.avgRating);artRating.numRatings=data.num_ratings;if(isNaN(artRating.numRatings)){artRating.numRatings=0}var a=jQuery("#"+_wId);if(a.length!==0){artRating.createRatingsWidget(a)}})})}};window.artRating=artRating})();
