/*
========================================
 FreshFavicon.com "common.js"
========================================
 (c)2008 ET VADIKOM-VASIL DINKOV
 http://www.smartmenus.org/vadikom/
========================================
*/


function init(){
c_gO("URIorUpload").style.display="none";
var a=c_gO("linkUpload");
if(!a.getAttribute("rel")||!/selected/i.test(a.getAttribute("rel")))
	toggleURIorUpload("Upload","URI");
else
	toggleURIorUpload("URI","Upload");
c_gO("linkURI").onclick=function(){toggleURIorUpload("Upload","URI");return false};
a.onclick=function(){toggleURIorUpload("URI","Upload");return false};
if(window.scrollTo)
	addLinkHandlers();
addIconHandlers();
initViewOptions();
hBox=c_d.createElement("div");
var s="position:absolute;top:-1000px;width:10px;";
c_iE?hBox.style.cssText=s:hBox.setAttribute("style",s);
c_gT(c_d,"body")[0].appendChild(hBox);
}


preloadImg=[];
function preloadImgs(a){
for(var i=0,l=a.length,j;i<l;i++){
	j=preloadImg.length;
	preloadImg[j]=new Image;
	preloadImg[j].src=a[i];
}
}


var xmlHttp;
if(c_w.ActiveXObject)
	try{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}catch(e){}
if(!xmlHttp&&typeof XMLHttpRequest!="undefined")
	try{
		xmlHttp=new XMLHttpRequest();
	}catch(e){}


function c_gCN(c,t,o){
	var r,os,resultA,cur;
	r=new RegExp("(^|\\s)"+c+"(\\s|$)");
	t=t||"*";
	o=o||c_d;
	os=t=="*"&&o.all?o.all:c_gT(o,t);
	resultA=[];
	for(var i=0,l=os.length;i<l;i++){
		cur=os[i];
		if(cur.className&&r.test(cur.className))
			resultA[resultA.length]=cur;
	}
	return resultA;
}


function addLinkHandlers(){
var as,a;
as=c_gT(c_d,"a");
for(var i=0,l=as.length;i<l;i++){
	a=as[i];
	if(a.hash&&currentURL(a)&&(!a.getAttribute("rel")||!/nosmoothscroll/i.test(a.getAttribute("rel"))))
		c_aE(a,"onclick",smoothScrollToElement);
}
}


function currentURL(a){
var d,h,L,H;
d=/index\.[^#\?]*/i;
h=/#.*/;
L=location.href.replace(d,"").replace(h,"");
H=a.href.replace(d,"").replace(h,"");
return H==L?1:0;
}


function smoothScrollToElement(e){
if(!e)
	e=event;
var id,o;
id=this.hash.substring(1);
o=c_gO(id);
if(!o)
	return true;
var c,s;
c=c_cA(o);
s=c_gW();
for(var i=1;i<25;i++)
	setTimeout("c_w.scrollTo(0,"+parseInt(s.y+(c.y-s.y)*(1-Math.cos(Math.PI*i/25))/2)+")",30*i);
if((this.getAttribute("rel")||"").substring(0,3)=="hl_"){
	var att=this.getAttribute("rel").split("_");
	setTimeout("highlightBox('"+att[1]+"',"+att[2]+",'"+att[3]+"','#"+att[4]+"')",30*i);
}
if(e.preventDefault)
	e.preventDefault();
return false;
}


function highlightBox(id,bw,bs,bc){
if(!c_dl)
	return;
var o=c_gO(id);
if(!o)
	return;
var c,s;
c=c_cA(o);
s="position:absolute;left:"+(c.x-bw)+"px;top:"+(c.y-bw)+"px;width:"+o.offsetWidth+"px;height:"+o.offsetHeight+"px;z-index:50000;";
c_iE?hBox.style.cssText=s:hBox.setAttribute("style",s);
hBox.style.border=bw+"px "+bs+" "+bc;
for(var i=1;i<8;i++)
	setTimeout("hBox.style.border='"+(i%2?'none':bw+'px '+bs+' '+bc)+"'",200*i);
setTimeout("hBox.style.display='none'",200*i);
}


function addIconHandlers(){
var imgs,img,a;
imgs=c_gT(c_d,"img");
for(var i=0,l=imgs.length;i<l;i++){
	img=imgs[i];
	if(img.className&&/icon/.test(img.className)){
		a=img.parentNode;
		if(xmlHttp){
			a.onmouseover=iconOver;
			a.onmouseout=iconOut;
		}else{
			img.title=img.alt+" | "+img.title;
		}
	}
}
preloadImgs(["/i/tooltip_left."+(c_iEW5?"gif":"png"),"/i/tooltip_center."+(c_iEW5?"gif":"png"),"/i/tooltip_right."+(c_iEW5?"gif":"png"),"/i/zoombox."+(c_iEW5?"gif":"png"),"/i/rate_dots.gif"]);
}


function iconOver(e){
if(!e)
	e=event;
var rt=e.relatedTarget||e.fromElement;
if(rt==this||rt.parentNode==this)
	return;
var icon=this.firstChild;
if(typeof tooltip=="undefined"){
	var s,t,tb,tr,td1,td2;
	tooltip=c_d.createElement("div");
	s="visibility:hidden;position:absolute;left:0;top:-1000px;height:25px;text-align:left;overflow:hidden;";
	c_iE?tooltip.style.cssText=s:tooltip.setAttribute("style",s);
	t=c_d.createElement("table");
	t.border="0";
	t.cellSpacing="0";
	t.cellPadding="0";
	t.style.margin="0";
	tb=c_d.createElement("tbody");
	tr=c_d.createElement("tr");
	td1=c_d.createElement("td");
	td1.style.width="6px";
	td1.style.height="25px";
	tooltipText=c_d.createElement("td");
	tooltipText.style.font="0.9166em 'trebuchet ms',arial,helvetica,sans-serif";
	tooltipText.style.verticalAlign="top";
	tooltipText.style.paddingTop="3px";
	td2=c_d.createElement("td");
	td2.style.width="6px";
	if(c_iEWo&&!c_iEW5){
		td1.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/i/tooltip_left.png',sizingMethod='crop')";
		tooltipText.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/i/tooltip_center.png',sizingMethod='crop')";
		td2.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/i/tooltip_right.png',sizingMethod='crop')";
	}else{
		td1.style.background="url(/i/tooltip_left."+(c_iEW5?"gif":"png")+") no-repeat";
		tooltipText.style.background="url(/i/tooltip_center."+(c_iEW5?"gif":"png")+") no-repeat";
		td2.style.background="url(/i/tooltip_right."+(c_iEW5?"gif":"png")+") no-repeat";
	}
	tr.appendChild(td1);
	tr.appendChild(tooltipText);
	tr.appendChild(td2);
	tb.appendChild(tr);
	t.appendChild(tb);
	tooltip.appendChild(t);
	c_gT(c_d,"body")[0].appendChild(tooltip);
}
tooltipText.innerHTML=icon.alt;
var c,f;
c=c_cA(this);
f=icon.className&&/sponsored/.test(icon.className);
tooltip.style.left=c.x+(f?-2:2)+"px";
tooltip.style.top=c.y-26+"px";
tooltip.style.visibility="visible";
//if(icon.className&&/sponsored/.test(icon.className))
if(typeof rateBox=="undefined"){
	rateDots=[];
	rateBox=c_d.createElement("div");
	s="visibility:hidden;position:absolute;left:0;top:0;font-size:1px;width:88px;height:27px;background:url(/i/rate_dots.gif) no-repeat 0 -10000px;";
	c_iE?rateBox.style.cssText=s:rateBox.setAttribute("style",s);
	rateDots[0]=c_d.createElement("span");
	s="float:left;display:block;width:10px;height:8px;overflow:hidden;margin-top:13px;background-image:url(/i/rate_dots.gif);background-position:0 0;background-repeat:no-repeat;";
	c_iE?rateDots[0].style.cssText=s:rateDots[0].setAttribute("style",s);
	rateDots[0].IN=1;
	rateBox.appendChild(rateDots[0]);
	for(var i=1;i<5;i++){
		rateDots[i]=rateDots[0].cloneNode(true);
		rateDots[i].IN=i+1;
		rateBox.appendChild(rateDots[i]);
	}
	rateDots[0].style.marginLeft=c_iEWo?"10px":"20px";
	rateDots[4].style.marginRight="0";
	zoomBox=c_d.createElement("div");
	s="position:absolute;top:26px;left:24px;width:40px;height:40px;overflow:hidden;visibility:"+(c_w.zoomBoxVisibility||"hidden")+";";
	c_iE?zoomBox.style.cssText=s:zoomBox.setAttribute("style",s);
	if(c_iEWo&&!c_iEW5)
		zoomBox.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/i/zoombox.png',sizingMethod='crop')";
	else
		zoomBox.style.background="url(/i/zoombox."+(c_iEW5?"gif":"png")+") no-repeat";
	zoomBoxImg=c_d.createElement("img");
	s="display:block;width:32px;height:32px;margin:4px;";
	c_iE?zoomBoxImg.style.cssText=s:zoomBoxImg.setAttribute("style",s);
	zoomBoxImg.src="/i/rate_dots.gif";
	zoomBox.appendChild(zoomBoxImg);
	rateBox.appendChild(zoomBox);
	rateBox.onmouseout=rateBoxOut;
	c_gT(c_d,"body")[0].appendChild(rateBox);
}
if(c_w.showZoomBox)
	zoomBoxImg.src=icon.src;
rateDotsUpdate(icon);
this.parentNode.style.backgroundImage="none";
rateBox.style.left=c.x-(f?27:23)+"px";
rateBox.style.top=c.y+15+"px";
rateBox.style.visibility="visible";
}


function iconOut(e){
//var icon=this.firstChild;
if(!e)
	e=event;
var rt=e.relatedTarget||e.toElement;
//if(icon.className&&/sponsored/.test(icon.className)||typeof rateBox=="undefined"||r&&r==rateBox)
if(rt==this||rt.parentNode==this||typeof tooltip=="undefined")
	return;
tooltip.style.visibility="hidden";
if(typeof rateBox=="undefined"||rt==rateBox)
	return;
rateBox.style.visibility="hidden";
this.parentNode.style.backgroundImage="url(/i/rating_bar.png)";
}


function rateBoxOut(e){
if(!e)
	e=c_w.event;
if(!e)
	e="";
var rt=e.relatedTarget||e.toElement;
if(rt&&(rt==rateBox||rt.parentNode==rateBox||rt.parentNode==zoomBox))
	return;
rateBox.style.visibility="hidden";
for(var M=0,I=c_gCN("icon"+rateBox.favicon_id,"img"),L=I.length;M<L;M++)
	I[M].parentNode.parentNode.style.backgroundImage="url(/i/rating_bar.png)";
}


function rateDotOver(){
var d;
for(var i=0;i<5;i++){
	d=rateDots[i];
	d.style.backgroundPosition=d.IN<=this.IN?"0 -16px":"0 0";
}
}


function rateDotOut(e){
if(!e)
	e=event;
var rt=e.relatedTarget||e.toElement;
if(rt&&rt.IN)
	return;
rateDotsUpdate();
}


function rateDotsUpdate(icon){
var M,I,L;
if(icon){
	if(icon.voteInProgress){
		voteProgress(icon);
		return;
	}
	rateBox.title=icon.title||icon.oldTitle;
	rateBox.favicon_id=parseInt(icon.className.substring(4));
	for(M=0,I=c_gCN("icon"+rateBox.favicon_id,"img"),L=I.length;M<L;M++){
		I[M].oldTitle=rateBox.title;
		I[M].title="";
	}
}
var R=parseFloat(rateBox.title.replace(/.*Rating: /,"")),d,voted;
voted=/You have voted/.test(rateBox.title);
if(voted)
	rateBox.title=rateBox.title.replace(/You have voted\. \| /,"");
var p,n;
p=["0","0","-42","-84","-126","-168","-210","-252","-294","-336","-378"];
n=0;
for(i=0;i<5;i++){
	d=rateDots[i];
	d.style.backgroundPosition=R>=1?"0 -16px":R>0.39?"0 -8px":"0 0";
	n+=(R>=1?2:R>0.39?1:0);
	R--;
	if(voted){
		d.title="You have voted. | "+rateBox.title;
		d.style.cursor="default";
		d.onmouseover=null;
		d.onmouseout=null;
		d.onclick=null;
	}else{
		d.title="Rate with "+(i+1)+" point"+(i>0?"s":"")+" | "+rateBox.title;
		d.style.cursor=c_iE?"hand":"pointer";
		d.onmouseover=rateDotOver;
		d.onmouseout=rateDotOut;
		d.onclick=vote;
	}
}
for(M=0,I=c_gCN("icon"+rateBox.favicon_id,"img"),L=I.length;M<L;M++)
	I[M].parentNode.parentNode.style.backgroundPosition=p[n]+"px 36px";
}


function vote(){
if(c_w.xmlHttpInProgress||this==window)
	return;
xmlHttpInProgress=1;
for(var M=0,I=c_gCN("icon"+rateBox.favicon_id,"img"),L=I.length;M<L;M++)
	voteProgress(I[M]);
favicon_id=rateBox.favicon_id;
var data="favicon_id="+rateBox.favicon_id+"&rate="+this.IN;
xmlHttp.open("POST","/vote/?timestamp="+(new Date().getTime()),true);
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-Length",data.length);
xmlHttp.onreadystatechange=voteDone;
xmlHttp.send(data);
}


function voteProgress(icon){
icon.voteInProgress=1;
rateBox.title="";
var d;
for(var i=0;i<5;i++){
	d=rateDots[i];
	d.onmouseover=null;
	d.onmouseout=null;
	d.onclick=null;
	d.title="";
	d.style.backgroundPosition="0 -24px";
	d.style.cursor="default";
}
}


function voteDone(){
if(xmlHttp.readyState==4){
	var M,I=c_gCN("icon"+rateBox.favicon_id,"img"),L=I.length;
	if(xmlHttp.status==200)
		for(M=0;M<L;M++)
			I[M].title=xmlHttp.responseText;
	else
		alert("There was a problem with the server. Your vote was not submitted successfully!\n\nPlease try again later...");
	for(M=0;M<L;M++)
		I[M].voteInProgress=0;
	rateDotsUpdate(I[0]);
	if(c_w.showRating)
		rateBoxOut();
	xmlHttpInProgress=0;
}
}


function toggleRating(f){
try{
	c_d.styleSheets[0].disabled=f;
}catch(e){
	try{
		c_gO("rating").disabled=f;
	}catch(e){}
}
showRating=f;
var v=new Date();
v.setTime(v.getTime()+365*24*60*60*1000);
v=v.toGMTString();
c_d.cookie="showRating="+f+";path=/;expires="+v+";";
}


function toggleZoomBox(f){
if(c_w.zoomBox)
	zoomBox.style.visibility=f?"inherit":"hidden";
else
	zoomBoxVisibility=f?"inherit":"hidden";
showZoomBox=f;
var v=new Date();
v.setTime(v.getTime()+365*24*60*60*1000);
v=v.toGMTString();
c_d.cookie="showZoomBox="+f+";path=/;expires="+v+";";
}


function toggleOpenInNewWindow(f){
var t,i,j,l,L,iL,aS,a;
t=f?"_blank":"_top";
iL=c_gCN("iconsList","ul");
for(i=0,l=iL.length;i<l;i++){
	aS=c_gT(iL[i],"a");
	for(j=0,L=aS.length;j<L;j++){
		a=aS[j];
		if(a.href!="http://www.freshfavicon.com/sponsor/"&&a.href!="/sponsor/")
			aS[j].target=t;
	}
}
var v=new Date();
v.setTime(v.getTime()+365*24*60*60*1000);
v=v.toGMTString();
c_d.cookie="openInNewWindow="+f+";path=/;expires="+v+";";
}


function initViewOptions(){
if((c_gO("ShowRating")||"").checked)
	toggleRating(true);
if((c_gO("ShowZoomBox")||"").checked)
	toggleZoomBox(true);
if((c_gO("OpenInNewWindow")||"").checked)
	toggleOpenInNewWindow(true);
}


function toggleURIorUpload(a,b){
c_gO("submitFavicon"+a).style.display="none";
c_gO("submitFavicon"+b).style.display="block";
var o=c_gO("link"+b).style;
o.fontWeight="bold";
o.cursor="default";
o=c_gO("link"+a).style;
o.fontWeight="normal";
o.cursor="pointer";
}


/* Fix IE flicker - credits: http://www.mister-pixel.com/#Content__state=is_that_simple */
function fixIE6flicker(f){
try{
	c_d.execCommand("BackgroundImageCache", false, f);
}catch(e){}
}
if(c_iEW&&!c_iEW5&&!c_iE7){
	fixIE6flicker(true);
	c_w.attachEvent("onunload",function(){fixIE6flicker(false)})
}


if(c_dl&&!c_oP7m&&!c_iC&&!c_iEM){
	schInit=function(){
		if(!c_gO("copyrightText")){
			if(c_M)
				return;
			setTimeout("schInit()",200);
			return;
		}
		c_dB=c_gT(c_d,"body")[0];c_dE=c_qM?c_dB:c_d.documentElement;
		init();
	};
	schInit();
}