function $(id){return(document.getElementById(id));}
function correctPNG(){ // correctly handle PNG transparency in Win IE 5.5 or higher.
  if(document.all){
    for(var i=0; i<document.images.length; i++){
      var img = document.images[i];
      var imgName = img.src.toUpperCase();
      if(imgName.substring(imgName.length-3, imgName.length) == "PNG"){
        var imgID = (img.id) ? "id='" + img.id + "' " : "";
        var imgClass = (img.className) ? "class='" + img.className + "' " : "";
        var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
        var imgStyle = "display:inline-block;" + img.style.cssText;
        var imgAttribs = img.attributes;
        for(var j=0; j<imgAttribs.length; j++){
          var imgAttrib = imgAttribs[j];
          if(imgAttrib.nodeName == "align"){
            if (imgAttrib.nodeValue == "left") imgStyle = "float:left;" + imgStyle;
            if (imgAttrib.nodeValue == "right") imgStyle = "float:right;" + imgStyle;
            break;
          }
        }
        var strNewHTML = "<span " + imgID + imgClass + imgTitle;
        strNewHTML += " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";";
        strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader";
        strNewHTML += "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
        img.outerHTML = strNewHTML;
        i = i-1;
      }
    }
  }
}
//#########################
function setCookie (name, value, expiredays) {
  var pathname=location.pathname;
  //var myDomain=pathname.substring(0,pathname.lastIndexOf('/'))+'/';
    var date_exp = new Date();
    date_exp.setTime(date_exp.getTime()+(expiredays*24*3600*1000));
    document.cookie=name+"="+escape(value)+
        ((expiredays==null) ? "" : ("; expires="+date_exp.toUTCString()))+
        "";//"; path="+myDomain;
}
//#########################
function changeLG(newLG){
  setCookie('lg',newLG,60);
  location.href=location.href;
}
//#########################
function addEventHandler(obj, event, func){
  if (typeof obj.addEventListener != "undefined") obj.addEventListener(event, func, false);
  else if(typeof obj.attachEvent != "undefined") obj.attachEvent('on'+event, func);
}
//#########################
var backgroundText={
  timeStep:75,
  maxOpacity:100,
  items:[],
  areasPx:[],
  fontSize:10,
  index:0,
  
  init:function(texts, container, areas, fontSize, timeFade, timeOn, zIndex){
    this.container=container;
    this.areasPc=areas;
    for(i in this.areasPc) this.areasPx[i]={};
    this.fontSize=fontSize;
    this.timeFade=timeFade;
    this.timeOn=timeOn;
    this.zIndex=zIndex;
    this.opacityStep=(this.maxOpacity*this.timeStep)/this.timeFade;

    texts=texts.sort(function(){return Math.round(Math.random())});
    for(i in texts){
      var item=document.createElement('div');
      item.innerHTML=texts[i];
      item.className="backgroundText";
      item.style.display="none";
      item.style.position="absolute";
      item.style.zIndex=this.zIndex;
      item._opacity=0;
      item._on=false;
      this.container.appendChild(item);
      this.items.push(item);
    }
    this.resize();
    this.switchItem();
    this.run();
    addEventHandler(window, 'resize', backgroundText.resize);
  },
  
  resize:function(){
    for(i in backgroundText.areasPc){
      backgroundText.areasPx[i].x=(backgroundText.areasPc[i].x*backgroundText.container.offsetWidth)/100;
      backgroundText.areasPx[i].y=(backgroundText.areasPc[i].y*backgroundText.container.offsetHeight)/100;
      backgroundText.areasPx[i].w=(backgroundText.areasPc[i].w*backgroundText.container.offsetWidth)/100;
      backgroundText.areasPx[i].h=(backgroundText.areasPc[i].h*backgroundText.container.offsetHeight)/100;
      backgroundText.areasPx[i].fs=Math.floor((backgroundText.areasPx[i].w*backgroundText.fontSize)/1000);
    }
    for(i in backgroundText.items) backgroundText.items[i].style.display="none";
  },

  switchItem:function(){
    this.items[this.index]._on=false;
    this.index=(this.index+1)%this.items.length;
    var area=Math.floor(Math.random()*this.areasPx.length);
    with(this.items[this.index]){
      style.display="block";
      style.fontSize=backgroundText.areasPx[area].fs+"px";
      style.left=Math.floor(Math.random()*(this.areasPx[area].w-offsetWidth))+this.areasPx[area].x+"px";
      style.top=Math.floor(Math.random()*(this.areasPx[area].h-offsetHeight))+this.areasPx[area].y+"px";
    }
    this.items[this.index]._on=true;
    setTimeout("backgroundText.switchItem()", this.timeOn);
  },

  run:function(){
    for(i in this.items){
      with(this.items[i]){
        if(_on){
          if(_opacity<this.maxOpacity){
            _opacity+=Math.floor(this.opacityStep); if(_opacity>this.maxOpacity) _opacity=this.maxOpacity;
          }
        }
        else{
          if(_opacity>0){
            _opacity-=Math.floor(this.opacityStep); if(_opacity<0) _opacity=0;
          }
          if(_opacity==0) style.display="none";
        }
      }
      this.opacity(this.items[i],this.items[i]._opacity);
    }
    setTimeout("backgroundText.run()", this.timeStep);
  },
  
  opacity:function(o, opacity) {
    o.style.opacity = (opacity / 100);
    o.style.MozOpacity = (opacity / 100);
    o.style.KhtmlOpacity = (opacity / 100);
    o.style.filter = "alpha(opacity=" + opacity + ")";
  }
}



