function addVisitorsCounter(data,category,type,style) { data = data+''; addZeros = 4 - data.length; for (i = 0; i < addZeros; i++) { data = '0'+data; } if (category !== 'back') { if (type === 'text') { jQuery('#visits_counter').html(data); cPosTop = Math.ceil((jQuery('#footer').height() - 32)/2); //32px average text + digit height cPosLeft = Math.ceil((jQuery('#footer_side').outerWidth() - 100)/2); //100px should contain all text and digits jQuery('#visits_counter_wrapper').css({'left' : cPosLeft+'px', 'top' : cPosTop+'px'}); } else if (type !== 'none') { var dWidth = style[0]; var dHeight = style[1]; digits = ''; for (i = 0; i <= (data.length - 1); i++) { value = data.charAt(i); //digits += ''+value+''; digits += ''; } jQuery('#visits_counter').html(digits); cPosTop = Math.ceil((jQuery('#footer').height() - (parseInt(dHeight) + 16))/2); //16px average text height cPosLeft = Math.ceil((jQuery('#footer_side').outerWidth() - (dWidth * data.length))/2); jQuery('#visits_counter_wrapper').css({'left' : cPosLeft+'px', 'top' : cPosTop+'px'}); } } else { var cWidth = style[0]; var cHeight = style[1]; var paddingTop = style[2]; var paddingLeft = style[3]; var tStyle = style[4]; var dStyle = style[5]; if (paddingTop === '') paddingTop = 0; if (paddingLeft === '') paddingLeft = 0; if (tStyle !== '') tStyle = ' style="'+tStyle+'"'; if (dStyle !== '') dStyle = ' style="'+dStyle+'"'; var text = jQuery('#visits_text_back').html(); jQuery('#visits_counter').css({'width' : (cWidth - paddingLeft)+'px', 'height' : (cHeight - paddingTop)+'px', 'padding-top' : paddingTop+'px', 'padding-left' : paddingLeft+'px', 'background-image' : 'url(/gfx/counters/'+type+'/counter.png)'}); jQuery('#visits_text_back').replaceWith(''+text+''); jQuery('#visits_text_back').after(''+data+''); cPosTop = Math.ceil((jQuery('#footer').height() - cHeight)/2); cPosLeft = Math.ceil((jQuery('#footer_side').outerWidth() - cWidth)/2); jQuery('#visits_counter_wrapper').css({'left' : cPosLeft+'px', 'top' : cPosTop+'px'}); } } function visitorsCounter(address,category,type,style) { var mfVisCookie = jQuery.cookies.get('mf_visits'); if (mfVisCookie === null) { jQuery.ajax({ type: 'POST', url: '/actions/visitscounter.seam', data: { url: address }, success: function(data) { if (!isNaN(data)) { cookieExpiryDate = new Date(); cookieExpiryDate.setTime(cookieExpiryDate.getTime()+(1000*60*15)); jQuery.cookies.set('mf_visits', data, {expiresAt: cookieExpiryDate}); addVisitorsCounter(data,category,type,style); } } }); } else { addVisitorsCounter(mfVisCookie,category,type,style); } }