var AUTOSIZE = 1;
function FullScreen(){
    var fs;
    this.init=function(){
        var _this=this;
        (fs=document.createElement("div")).className="fs";
        (fs.appendChild(document.createElement("blockquote"))).onclick=function(){_this.hide()};
        fs.appendChild(fs.block=document.createElement("div"));
        (fs.block.appendChild(document.createElement("a"))).onclick=function(){_this.hide()};
        fs.block.appendChild(fs.pager=document.createElement("var"));
        fs.block.appendChild(fs.desc=document.createElement("b"));
        fs.block.appendChild(fs.content=document.createElement("span"));
        
        document.body.appendChild(fs);
        fs.scrollSize=this.scrollSize();
        if(IE6){
            window.onscroll=function(){this.IE6_centered()}
            this.IE6_centered();
        }
        return this;
    }

    this.IE6_centered=function(){
          if(!this.isOpen) return false;
          fs.style.width=document.documentElement.scrollWidth+"px";
          fs.style.height=document.documentElement.scrollHeight+"px";
          fs.block.style.top=Math.round(document.documentElement.scrollTop+((document.documentElement.offsetHeight)/2))+"px";
          fs.block.style.left=Math.round(document.documentElement.scrollLeft+((document.documentElement.offsetWidth)/2))+"px";
    }

    this.scrollSize=function(){ //calc srroll size
        var div=document.createElement("div");
        div.style.width="50px";
        div.style.height="50px";
        div.style.overflow="auto";
        div.style.visibility="hidden";
        div.style.position="absolute";
        (div.appendChild(document.createElement("div"))).style.height="100px";
        document.body.appendChild(div);
        var size=div.offsetWidth-div.clientWidth;
        document.body.removeChild(div);
        return size;
    }
    
    this.show=function(obj,update){
        this.isOpen=1;
        if(!update) this.write('',{width:200, height:200})
        //fs.style.width=(_("root").offsetWidth+60)+"px";
        fs.style.height=document.documentElement.scrollHeight+"px";
        fs.style.display="block";
        var width = Number(obj.getAttribute('iwidth'));
        var height = Number(obj.getAttribute('iheight'));
        this.write(obj.href,{width: width,height: height,count:1,desc:""},0);
        
/*
        new AJAX({
            method:"http", 
            file:"site/index.php", 
            query:"sizeof="+obj.href+(obj.getElementsByTagName("img")[0]?"&desc="+obj.getElementsByTagName("img")[0].alt:""),
            onready:function(response){_this.write(obj.href,response,update)},
            send:1
        })
*/
        return false;
    }
    
    this.hide=function(){
        this.isOpen=0;
        fs.style.display="none";
        fs.content.innerHTML=fs.pager.innerHTML=fs.desc.innerHTML='';
    }
    
    this.write=function(url, ifile, update){
        var _this=this;
        if(!ifile.width || !ifile.height) return false;
        if(IE6) this.IE6_centered();
        fs.content.style.overflow="visible";
/*
        var w=ifile.width+40;
        var h=ifile.height+40;
        if(h>document.documentElement.offsetHeight){
            fs.content.style.overflow="auto";
            h=document.documentElement.offsetHeight-fs.scrollSize;
            w=w+fs.scrollSize;
        }
        if(w>document.documentElement.offsetWidth){
            fs.content.style.overflow="auto";
            w=document.documentElement.offsetWidth;
            h=h+fs.scrollSize;
        }
        fs.block.style.marginLeft=-Math.round(w/2)+"px";
        fs.block.style.marginTop=-Math.round(h/2)+"px";
        fs.content.style.width=Number(w-40)+"px";
        fs.content.style.height=Number(h-40)+"px";
*/
          var w=ifile.width+20;
          var h=ifile.height+20;
          var di=ifile.width/ifile.height;
          var de=document.documentElement;
          if(h>de.offsetHeight){
               h=de.offsetHeight-fs.scrollSize;
               if(AUTOSIZE){ifile.height=h-20; ifile.width=Math.round(ifile.height*di); w=ifile.width+20;} //resize image
               else{fs.content.style.overflow="auto"; w+=fs.scrollSize;} //for scroller size
          }
          if(w>de.offsetWidth){
               w=de.offsetWidth-fs.scrollSize;
               if(AUTOSIZE){ifile.width=w-20; ifile.height=Math.round(ifile.width/di); h=ifile.height+20;} //resize image
               else{fs.content.style.overflow="auto"; h+=fs.scrollSize;} //for scroller size
          }
          fs.block.style.marginLeft=-Math.round((w+20)/2)+"px";
          fs.block.style.marginTop=-Math.round((h+20)/2)+"px";
          fs.content.style.width=Number(w-20)+"px";
          fs.content.style.height=Number(h-20)+"px";

        if(url){
            if(/.+.(jpg)|(gif)$/.test(url)) fs.content.innerHTML='<img src="'+url+'" width="'+ifile.width+'" height="'+ifile.height+'" />';
            if(/.+.swf$/.test(url)) fs.content.innerHTML='<object type="application/x-shockwave-flash" data="'+url+'" width="'+ifile.width+'" height="'+ifile.height+'"><param name="movie" value="'+url+'" /><param name="quality" value="high" /></object>';
            if(!update){
                fs.desc.innerHTML=ifile.desc;
                if(ifile.count>1)
                    for(var i=1; i<=ifile.count; i++){
                        var a=document.createElement("a");
                        a.innerHTML=i;
                        a.href=url.replace(/_[0-9]./,"_"+i+".");
                        a.content=fs.content;
                        a.onfocus=function(){this.blur()}
                        a.onclick=function(){_act(this); this.content.innerHTML=''; return _this.show(this,1);}
                        fs.pager.appendChild(a);
                        if(i==1) _act(a)
                    }
            }
        }
    }
    return this.init();
}
