/*
 * File:        secret.min.js
 * Version:     1.0.0
 * Author:      Allan Jardine (www.sprymedia.co.uk)
 * 
 * Copyright 2008-2009 Allan Jardine, all rights reserved.
 *
 * This source file is free software, under either the GPL v2 license.
 * 
 * This source file is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
 */
var Secret;(function(){Secret={iCharsPerLine:10,iLineHeight:70,iCharSpacing:50,iCharDelay:200,iExitDelay:100,bAutoOut:true,fnMessage:function(d){if(!document.defaultView){Secret.fnDisplayError("You need a browser with document.defaultView capabilities in order to use Secret. Firefox, Safari, Opera, Chrome etc...");
return}if(!document.body.getBoundingClientRect){Secret.fnDisplayError("You need a browser with Element.getBoundingClientRect capabilities in order to use Secret. Firefox, Opera, Webkit (after 10th Feb 09)");
return}var e=0;var c=this.fnCreate(d);for(var b=0;b<c.length;b++){for(var a=0;a<c[b].length;
a++){if(c[b][a].cChar!=" "){e=this.fnObtainCharacter(c[b][a]);if(e==-1){break}}if(e==-1){break
}}}if(e!=-1){Secret.fnPositionChars(c,0,0)}else{Secret.fnDisplayError('Could not find the characters on the page to display "'+d+'"')
}},fnDisplayError:function(e){var c=this.fnGetScrollingPosition();var b=this.fnViewPortSize();
var a=document.createElement("div");a.style.position="absolute";a.style.top="50%";
a.style.left="50%";a.style.width="500px";a.style.height="40px";a.style.marginTop="-20px";
a.style.marginLeft="-250px";a.style.background="#FFE3E3";a.style.border="1px solid #FF9292";
a.style.padding="20px";a.style.textAlign="center";a.innerHTML=e;YAHOO.util.Dom.setStyle(a,"opacity",0);
document.body.appendChild(a);var f=new YAHOO.util.Anim(a,{opacity:{to:1}},3,YAHOO.util.Easing.easeBoth);
var d=new YAHOO.util.Anim(a,{opacity:{to:0}},3,YAHOO.util.Easing.easeBoth);f.onComplete.subscribe(function(){d.animate()
});d.onComplete.subscribe(function(){a.parentNode.removeChild(a)});f.animate()},fnPositionChars:function(c,a,b){this.fnPositionChar(c[a][b]);
if(typeof c[a][b+1]!="undefined"){if(this.iCharDelay==0){this.fnPositionChars(c,a,b+1)
}else{setTimeout(function(){Secret.fnPositionChars(c,a,b+1)},this.iCharDelay)}}else{if(typeof c[a+1]!="undefined"){if(this.iCharDelay==0){this.fnPositionChars(c,a+1,0)
}else{setTimeout(function(){Secret.fnPositionChars(c,a+1,0)},this.iCharDelay)}}else{if(this.bAutoOut){setTimeout(function(){Secret.fnExit(c,0,0)
},5000)}}}},fnPositionChar:function(c){if(c.nDisplay){var b=this.fnGetScrollingPosition();
YAHOO.util.Dom.setStyle(c.nDisplay,"opacity",0);var a=document.createElement("div");
a.style.position="absolute";a.style.top="-20px";a.style.left="-46px";a.style.height="60px";
a.style.width="100px";a.style.background="url(http://www.sprymedia.co.uk/secret/fade.png)";
c.nDisplay.innerHTML='<div style="position:relative;">'+c.nDisplay.innerHTML+"</div>";
c.nDisplay.insertBefore(a,c.nDisplay.childNodes[0]);c.nDisplay.style.display="block";
c.yuiOpacity=new YAHOO.util.Anim(c.nDisplay,{opacity:{to:1}},1,YAHOO.util.Easing.easeBoth);
c.yuiMotion=new YAHOO.util.Motion(c.nDisplay,{points:{to:[c.iLeft+b.iLeft,c.iTop+b.iTop],control:this.fnRandomCoords(c)},fontSize:{to:20,unit:"px"}},4,YAHOO.util.Easing.easeBothStrong);
c.yuiOpacity.onComplete.subscribe(function(){c.yuiMotion.animate()});c.yuiOpacity.animate()
}},fnExit:function(c,a,b){this.fnKillChar(c[a][b]);if(typeof c[a][b+1]!="undefined"){if(this.iExitDelay==0){this.fnExit(c,a,b+1)
}else{setTimeout(function(){Secret.fnExit(c,a,b+1)},this.iExitDelay)}}else{if(typeof c[a+1]!="undefined"){if(this.iExitDelay==0){this.fnExit(c,a+1,0)
}else{setTimeout(function(){Secret.fnExit(c,a+1,0)},this.iExitDelay)}}}},fnKillChar:function(b){if(b.nDisplay){var a=new YAHOO.util.Anim(b.nDisplay,{opacity:{to:0},top:{by:50}},1,YAHOO.util.Easing.easeBoth);
a.onComplete.subscribe(function(){b.nDisplay.parentNode.removeChild(b.nDisplay)});
a.animate()}},fnRandomCoords:function(g){var b;var j;var c;var f;var e=[];var a=this.fnViewPortSize();
var d=this.fnGetScrollingPosition();e[0]=[this.fnRandom(a.iWidth)+d.iLeft,this.fnRandom(a.iHeight)+d.iTop];
b=(2*g.iLeft)/3;j=(2*g.iTop)/3;c=(2*a.iWidth)/3;f=(2*a.iHeight)/3;e[1]=[this.fnRandom(b,b+c)+d.iLeft,this.fnRandom(j,j+f)+d.iTop];
b=g.iLeft/3;j=g.iTop/3;c=a.iWidth/3;f=a.iHeight/3;e[2]=[this.fnRandom(b,b+c)+d.iLeft,this.fnRandom(j,j+f)+d.iTop];
return e},fnCreate:function(g){var b=g.split(" ");var f=[[]];var a=0;var h=-1;var c=0;
var e,d;for(e=0;e<b.length;e++){if(f[a].length+b[e].length>this.iCharsPerLine){a++;
f[a]=[]}if(h==a){f[a].push({cChar:" ",iWord:-1,iLine:a,iTop:0,iLeft:0,nDisplay:null})
}var k=b[e].split("");for(d=0;d<k.length;d++){f[a].push({cChar:k[d],iWord:c,iLine:a,iTop:0,iLeft:0,nDisplay:null})
}c++;h=a}this.fnPositionY(f);this.fnPositionX(f);return f},fnPositionY:function(e){var d=e.length;
var c=this.fnViewPortSize();var g=c.iHeight/2;var a=g-((d/2)*this.iLineHeight)+(this.iLineHeight/2);
for(var f=0;f<e.length;f++){for(var b=0;b<e[f].length;b++){e[f][b].iTop=a+(this.iLineHeight*f)
}}},fnPositionX:function(e){var d=e.length;var c=this.fnViewPortSize();var g=c.iWidth/2;
for(var f=0;f<d;f++){var a=e[f].length;var h=g-((a/2)*this.iCharSpacing)+(this.iCharSpacing/2);
for(var b=0;b<e[f].length;b++){e[f][b].iLeft=h+(this.iCharSpacing*b)}}},fnViewPortSize:function(){var b=document.body.offsetHeight;
var c=document.body.offsetWidth;var a=document.documentElement.clientHeight;var d=document.documentElement.clientWidth;
return{iWidth:c,iHeight:a}},fnObtainCharacter:function(k,d){if(typeof d=="undefined"){d=false
}var b=k.cChar;var e=this.fnGetVisTextNodes(document.body,d);var h=[];for(var f=0;
f<e.length;f++){var g=this.fnGetDisplayInfo(e[f]);if(g.length!==0){h=h.concat(g)}}var c=0;
for(f=0;f<h.length;f++){if(typeof h[f].oChars[b]!="undefined"){c+=h[f].oChars[b]}}var m=this.fnRandom(c);
var l=this.fnLocateChar(h,b,m);if(l==null){if(d){this.fnLog("Could not find character "+b+" in whole document");
return -1}else{this.fnLog("Could not find character "+b+" in visible document");return this.fnObtainCharacter(k,true)
}}var a=this.fnInsertTextSpan(l.oNode.sText,l,b);var j=this.fnInjectDom(l.oNode.nNode,a);
k.nDisplay=this.fnDuplicateCharNode(j);return 0},fnDuplicateCharNode:function(c){if(c){var e=c.cloneNode(true);
var b=this.fnGetScrollingPosition();var d=c.getBoundingClientRect();e.style.position="absolute";
e.style.top=(d.top+b.iTop)+"px";e.style.left=(d.left+b.iLeft)+"px";e.style.color="#f00";
e.style.display="none";var a=document.defaultView.getComputedStyle(c,null);e.style.fontSize=a.fontSize;
e.style.fontWeight=a.fontWeight;e.style.fontFamily=a.fontFamily;document.body.appendChild(e);
return e}return null},fnInjectDom:function(b,c){var d;var a=document.createElement("span");
a.innerHTML=c;for(i=a.childNodes.length-1;i>=0;i--){if(a.childNodes[i].nodeName=="SPAN"){d=a.childNodes[i]
}b.parentNode.insertBefore(a.childNodes[i],b.nextSibling)}b.parentNode.removeChild(b);
return d},fnInsertTextSpan:function(d,c,b){var a="";var e=d;aLocal=e.split(b);for(i=0;
i<aLocal.length-1;i++){if(i==c.iOccurrence){a+=aLocal[i]+"<span>"+b+"</span>"}else{a+=aLocal[i]+b
}}a+=aLocal[aLocal.length-1];return a},fnGetDisplayText:function(b){var d="";for(var c=0;
c<b.childNodes.length;c++){switch(b.childNodes[c].nodeType){case Node.TEXT_NODE:d+=b.childNodes[c].nodeValue+"    ";
break;case Node.ELEMENT_NODE:var a=document.defaultView.getComputedStyle(b.childNodes[c],null);
if(a.display!="none"&&a.visibility=="visible"){d+=this.fnGetText(b.childNodes[c])
}break;default:break}}return d},fnGetDisplayInfo:function(d){var c=[];if(d.childNodes){for(var e=0;
e<d.childNodes.length;e++){switch(d.childNodes[e].nodeType){case Node.TEXT_NODE:c.push({sText:d.childNodes[e].nodeValue,nNode:d.childNodes[e],oChars:this.fnCountChars(d.childNodes[e].nodeValue)});
break;case Node.ELEMENT_NODE:var b=document.defaultView.getComputedStyle(d.childNodes[e],null);
if(b.display!="none"&&b.visibility=="visible"){var a=this.fnGetDisplayInfo(d.childNodes[e]);
if(a.length>0){c=c.concat(a)}}break;default:break}}}return c},fnLocateChar:function(f,a,d){var c=0;
for(var b=0;b<f.length;b++){var e=typeof f[b].oChars[a]!="undefined"?f[b].oChars[a]:0;
if(d<c+e){return{oNode:f[b],iOccurrence:d-c}}else{c+=e}}return null},fnRandom:function(b,a){if(typeof a=="undefined"){return parseInt(Math.random()*b,10)
}else{return parseInt((Math.random()*(a-b))+b,10)}},fnCountChars:function(a){var d=a.split("");
var b={};for(var c=0;c<d.length;c++){if(typeof b[d[c]]=="undefined"){b[d[c]]=1}else{b[d[c]]++
}}return b},fnGetVisTextNodes:function(b,c){var j=[];var f=this.fnGetScrollingPosition();
var d=f[1];var h=f[0];var k=document.documentElement.clientHeight;var m=document.documentElement.clientWidth;
if(c=="undefined"){c=false}for(var e=0;e<b.childNodes.length;e++){if(b.childNodes[e].nodeType==Node.ELEMENT_NODE){var g=b.childNodes[e].getBoundingClientRect();
if((g.top>0&&g.bottom<k)||c){j.push(b.childNodes[e])}else{var l=document.defaultView.getComputedStyle(b.childNodes[e],null);
if(l.display!="none"&&l.visibility=="visible"){var a=this.fnGetVisTextNodes(b.childNodes[e],c);
if(a.length>0){j=j.concat(a)}}}}}return j},fnGetScrollingPosition:function(){var a={};
if(typeof window.pageYOffset!="undefined"){a.iTop=window.pageYOffset;a.iLeft=window.pageXOffset
}else{if(typeof document.documentElement.scrollTop){a.iTop=document.documentElement.scrollTop;
a.iLeft=document.documentElement.scrollLeft}}return a},fnLog:function(a){if(typeof console!="undefined"&&typeof console.log!="undefined"){console.log(a)
}}}})();
