// (c)2010 Affiliately.com

(function(){var requestUrl="http://ws.affiliately.com/find-links"
+"?callback=_affiliately.showLinks"
+"&aaID="+_affiliately.aaID
+"&aaMarketplace="+_affiliately.aaMarketplace
+"&url="+encodeURI(document.location);var e=document.createElement('script');e.type='text/javascript';e.charset='utf-8';e.src=requestUrl+'&noCacheIE='+(new Date()).getTime();e.id='affiliatelyDynamicScript';var head=document.getElementsByTagName("head").item(0);head.appendChild(e);})();_affiliately.hostFromURL=function(url){url=url.replace(/https?:\/\//,'');url=url.replace(/www\./,'');var forwardSlashIndex=url.indexOf('/');if(forwardSlashIndex!=-1){url=url.substring(0,forwardSlashIndex);}
return url.toLowerCase();}
_affiliately.AFFILIATE_PROGRAMS=['amazon.com','amazon.co.uk','amazon.de','clickbank.com'];_affiliately.isURLToAffiliateProgram=function(url){var host=_affiliately.hostFromURL(url);for(var i=0;i<_affiliately.AFFILIATE_PROGRAMS.length;i++){if(_affiliately.AFFILIATE_PROGRAMS[i]==host)return true;}
return false;}
_affiliately.showLinks=function(jsonData){_affiliately.products=jsonData;var preview=_affiliately.hasOwnProperty('preview')&&_affiliately.preview===false?false:true;var target=_affiliately.hasOwnProperty('newWindow')&&_affiliately.newWindow===true?' target="_blank"':'';var doubleUnderline=' style="text-decoration:underline !important; border-bottom:1px solid !important;"';if(_affiliately.hasOwnProperty('doubleUnderline')&&_affiliately.doubleUnderline===false){doubleUnderline='';}
var s=document.body.innerHTML;var regExp,previewAttributes,onclick;for(var i=0;i<jsonData.length;i++){regExp=new RegExp("<([^a])([^>]*?>)([^<]*?)(\\b"+jsonData[i].keyword+"\\b)",'i');previewAttributes=preview?' onmouseover="affiliatelyPreview.forKeyword(\''+jsonData[i].keyword+'\', \''+jsonData[i].affiliate_id+'\', this);"':'';onclick=' onclick="affiliatelyClickLog(this, \''+jsonData[i].affiliate_id+'\'); return false;"';s=s.replace(regExp,'<$1$2$3<a href="'+jsonData[i].url+'"'+doubleUnderline+target+previewAttributes+onclick+'>$4</a>');}
document.body.innerHTML=s;var script=document.getElementById('affiliatelyDynamicScript');var head=document.getElementsByTagName("head")[0];head.removeChild(script);_affiliately.AFFILIATE_PROGRAMS.push(_affiliately.hostFromURL(document.location.toString().substring(0)));var links=document.getElementsByTagName('a');for(var i=0;i<links.length;i++){if(!_affiliately.isURLToAffiliateProgram(links[i].href)){links[i].onclick=function(e){document.location='http://ws.affiliately.com/goto?aaID='+_affiliately.aaID+'&aaMarketplace='+_affiliately.aaMarketplace+'&url='+encodeURI(this.href);return false;}}}}
var affiliatelyClickLog=function(aElement,affiliate_id){var logClickUrl="http://ws.affiliately.com/log-click"
+"?marketplace="+_affiliately.aaMarketplace
+"&marketplaceId="+affiliate_id
+"&url="+encodeURI(aElement.href);var scriptId='affiliatelyClickLog'+(new Date()).getTime().toString();var e=document.createElement('script');e.type='text/javascript';e.charset='utf-8';e.src=logClickUrl+'&noCacheIE='+(new Date()).getTime();e.id=scriptId;var head=document.getElementsByTagName("head").item(0);head.appendChild(e);setTimeout('document.location = "'+aElement.href+'"',100);}
var affiliatelyPreview=function(){var yPad=8;var hPad=8;var maxWidth=250;var isIE=document.all?true:false;var ttE;var visibilityTimeoutId,mousePosX,mousePosY,waitTimer,startMilliseconds,affiliate_id,aElement,keyword;var waitBeforeShow=500;return{forKeyword:function(keywordIn,aff_id,element){keyword=keywordIn;affiliate_id=aff_id;aElement=element;for(var i=0;i<_affiliately.products.length;i++){if(_affiliately.products[i].keyword==keyword){var product=_affiliately.products[i];var html="<div style='background:#fafafa; color:#000; border:solid 1px #ccc; font-family:Verdana, Arial, sans-serif; font-weight:normal; font-size:9px; border-radius: 5px 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.1); -webkit-box-shadow: 3px 3px rgba(0, 0, 0, 0.1); -moz-box-shadow: 3px 3px rgba(0, 0, 0, 0.1);'>";var source=document.location&&document.location.host?document.location.host:'pb';html+="<div style='background:#e3e3e3; line-height:1em; padding:3px 6px 4px 6px; font-size:9px;'><div style='float:right;'><a href='#' onclick='affiliatelyPreview.hide(); return false;' style='font-size:10px; text-decoration:none; color:#333;'>x</a></div><a href='http://www.affiliate.ly/?s="+source+"' style='font-size:10px; text-decoration:none; color:#333;'>Affiliately</a></div>";html+="<div style='padding:5px; line-height:1.3em; font-size:12px;'>";if(product.image_url!=null&&product.image_url!=""){html+="<div style='float:left; padding-right:5px;'><img src='"+product.image_url+"' border='0' /></div>"}
var title=product.title.length>100?product.title.substring(0,97)+'...':product.title;html+="<div><b><a href='"+product.url+"' style='color:#333; text-decoration:none;' onclick=\"affiliatelyClickLog(this, '"+affiliate_id+"'); return false;\">"+title+"</a></b></div>";if(product.marketplace!="clickbank.com"){html+="<div style='padding-top:5px; color:#656565;'>"+product.marketplace+": "+product.price+"</div>";}
html+="<div style='clear:both;'></div></div>";html+="</div>";affiliatelyPreview.scheduleShow(html);break;}}},scheduleShow:function(content){cursorOnLinkPos={x:mousePosX,y:mousePosY};if(waitTimer){clearTimeout(waitTimer);}
waitTimer=setTimeout(function(){var deltaX=Math.abs(mousePosX-cursorOnLinkPos.x);var deltaY=Math.abs(mousePosY-cursorOnLinkPos.y);if(deltaX<=60&&deltaY<=20){affiliatelyPreview.show(content);}},waitBeforeShow);},show:function(content){if(ttE==null){affiliatelyPreview.setupTooltip();}
ttE.innerHTML=content;ttE.style.display='block';affiliatelyPreview.adjustPosition();affiliatelyPreview.scheduleHide(2000);startMilliseconds=(new Date()).getTime();},setupTooltip:function(){ttE=document.createElement('div');ttE.style.position="absolute";ttE.style.display="block";ttE.style.width=maxWidth+'px';ttE.onmouseover=function(){clearTimeout(visibilityTimeoutId);}
ttE.onmouseout=function(){if(ttE.style.display!='none'){affiliatelyPreview.scheduleHide(100);}}
document.body.appendChild(ttE);},mouseMove:function(e){mousePosX=isIE?event.clientX+document.documentElement.scrollLeft:e.pageX;mousePosY=isIE?event.clientY+document.documentElement.scrollTop:e.pageY;},adjustPosition:function(){var height=parseInt(ttE.offsetHeight)+yPad;var width=parseInt(ttE.offsetWidth)+hPad;ttE.style.top=(mousePosY-height<0?mousePosY+yPad:mousePosY-height)+'px';ttE.style.left=(mousePosX+width>affiliatelyPreview.windowWidth()?mousePosX-width:mousePosX+hPad)+'px';},hide:function(){ttE.style.display='none';affiliatelyPreview.logTooltipDisplay();},scheduleHide:function(miliseconds){if(visibilityTimeoutId){clearTimeout(visibilityTimeoutId);}
visibilityTimeoutId=setTimeout(function(){affiliatelyPreview.hide();},miliseconds);},windowWidth:function(){var width=0;if(typeof(window.innerWidth)=='number'){width=window.innerWidth;}
else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){width=document.documentElement.clientWidth;}
else if(document.body&&(document.body.clientWidth||document.body.clientHeight)){width=document.body.clientWidth;}
return width;},logTooltipDisplay:function(){var responseTime=(new Date()).getTime()-startMilliseconds;var logDisplayUrl="http://ws.affiliately.com/log-tooltip-display"
+"?marketplace="+_affiliately.aaMarketplace
+"&marketplaceId="+affiliate_id
+"&duration="+responseTime
+"&keyword="+encodeURI(keyword)
+"&url="+encodeURI(aElement.href);var e=document.createElement('script');e.type='text/javascript';e.charset='utf-8';e.src=logDisplayUrl+'&noCacheIE='+(new Date()).getTime();var head=document.getElementsByTagName("head").item(0);head.appendChild(e);setTimeout(function(){head.removeChild(e);},1000);}};}();var _oldMouseMoveFunction=document.onmousemove;document.onmousemove=function(e){affiliatelyPreview.mouseMove(e);if(_oldMouseMoveFunction){_oldMouseMoveFunction(e);}}
