//SwishMax Text Replacement by Alessandro Fulciniti
//related article here:

//released in Creative Commons - Commons Deeds
// http://creativecommons.org/licenses/by-nc-sa/2.0/deed.en

function STRDetect(){
if(!detectFlash(6) || !document.getElementsByTagName || !document.getElementById || !document.createElement)
    return(false);
if(Array.prototype.push == null){Array.prototype.push = function(){
      this[this.length] = arguments[0]; return(this.length);}}
isIE=window.ActiveXObject && navigator.userAgent.indexOf('Mac')==-1;
return(true);
}

function SwishReplace(selector,flashsource,w,h,bk,col,hcol){
var hx=getElementsBySelector(selector);
var k1,k2,opt="",el,v,mylink;
k1=TColor(col);
k2=TColor(hcol);
if(k1) opt="&k1="+k1;
if(k2) opt+="&k2="+k2;
for(var i=0;i<hx.length;i++){
    mylink="";
    el=hx[i];
    v=el.firstChild;
    if(v.nodeType==1 && v.tagName=="A")
        el=el.firstChild;
    if(el.tagName=="A"){
        v.style.display="block";
        mylink="&mylink="+el.href;
        }
    text=el.firstChild.nodeValue;
    var basetext=document.createElement("span");
    basetext.appendChild(document.createTextNode(text));
    basetext.style.height=h+"px";
    basetext.style.width=w+"px";
    basetext.className="strText";
    var fr=document.createElement("b");
    fr.className="strFlash";
    var htmlcode="";
    if(isIE){ //Internet Explorer PC
        htmlcode='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + w + '" height="'+ h + '" title="'+text+'">';
        htmlcode+='<param name="bgcolor" value="' + bk + '">';
        htmlcode+='<param name="src" value="' + flashsource + '">';
        htmlcode+='<param name="menu" value="false">';
        htmlcode+='<param name="flashVars" value="txt=' + text+opt+mylink;
        htmlcode+='"></object>';
        }
    else{
        htmlcode='<embed type="application/x-shockwave-flash" src="' +  flashsource  + '"' + ' width="' + w + '" height="' + h + '" title="'+text + '" bgcolor="' + bk + ' menu="false"' + '" flashVars="txt=' + text;
        htmlcode+=opt+mylink;
        htmlcode+='"></embed>';
        }
    fr.innerHTML=htmlcode;
    basetext.appendChild(fr);
    el.removeChild(el.childNodes[0]);
    el.appendChild(basetext);
    }
}

function detectFlash(ver){
var flashversion=0;
if(navigator.plugins && navigator.plugins.length){
    var x=navigator.plugins["Shockwave Flash"];
    if(x && x.description) {
        var y=x.description;
        flashversion=y.charAt(y.indexOf('.')-1);
        }
    }
else{
    for(var i=15; i>=3 && flashversion==0;i--){
        execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
        flashversion=i;
        }
    }
return(flashversion>=ver);
}

function getElementsBySelector(selector){
var i,selid="",selclass="",tag=selector,f,s=[],objlist=[];

if(selector.indexOf(" ")>0){  //descendant selector like "tag#id tag"
    s=selector.split(" ");
    var fs=s[0].split("#");
    if(fs.length==1) return(objlist);
    f=document.getElementById(fs[1]);
    if(f) return(f.getElementsByTagName(s[1]));
    return(objlist);
    }
if(selector.indexOf("#")>0){ //id selector like "tag#id"
    s=selector.split("#");
    tag=s[0];
    selid=s[1];
    }
if(selid!=""){
    f=document.getElementById(selid);
    if(f) objlist.push(f);
    return(objlist);
    }
if(selector.indexOf(".")>0){  //class selector like "tag.class"
    s=selector.split(".");
    tag=s[0];
    selclass=s[1];
    }
var v=document.getElementsByTagName(tag);  // tag selector like "tag"
if(selclass=="")
    return(v);
for(i=0;i<v.length;i++){
    if(v[i].className.indexOf(selclass)>=0){
        objlist.push(v[i]);
        }
    }
return(objlist);
}

function TColor(col)
{
var tcol="";
if(col){
    if(col.indexOf("#")>=0)
        col=col.substring(1,col.length);
    if(col.length==3)
        for(var j=0;j<3;j++)
            tcol=tcol+col.substr(j,1)+col.substr(j,1);
    else tcol=col;
    tcol="0x"+tcol;
    if(tcol=="0x000000") tcol="0x000001";
    }
return(tcol);
}