var IE6=navigator.appVersion.indexOf("MSIE 6")!=-1;
var AUTOSIZE = 1;
var Fullscreen={
    init:function(){
		var _this=this;
        (this.fs=document.createElement("div")).className="fs";
        (this.fs.appendChild(document.createElement("blockquote"))).onclick=function(){_this.hide()};
        this.fs.appendChild(this.fs.block=document.createElement("div"));
        (this.fs.block.appendChild(document.createElement("a"))).onclick=function(){_this.hide()};
        this.fs.block.appendChild(this.fs.content=document.createElement("span"));
        document.body.appendChild(this.fs);
        this.fs.scrollSize=this.scrollSize();
        return 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;
    },
	IE6_centered:function(){
		if(!this.isOpen) return false;
		//fs.style.height=document.documentElement.scrollHeight+"px";
		this.fs.style.width=document.documentElement.scrollWidth+"px";
		this.fs.style.marginTop=-document.body.offsetTop+"px";
		this.fs.style.marginLeft=-document.body.offsetLeft+"px";
		this.fs.block.style.top=Math.round(document.documentElement.scrollTop+((document.documentElement.offsetHeight)/2))+"px";
		this.fs.block.style.left=Math.round(document.documentElement.scrollLeft+((document.documentElement.offsetWidth)/2))+"px";
	},
	show:function(url, w, h, ol, ot){
		if(!this.fs) this.init();
        this.isOpen=1;
        this.fs.style.height=document.documentElement.scrollHeight+"px";
        this.fs.style.display="block";
        this.write(url,{width:w, height:h}, ol, ot);
        return false;
    },
	tracer:function(param1){
		alert(param1);
	},
	setBackground:function(newColor){
		document.body.style.backgroundColor=newColor;
	},
	hide:function(){
        this.isOpen=0;
        this.fs.style.display="none";
        this.fs.content.innerHTML='';
    },
	write:function(url, ifile, ol, ot){
        var _this=this;
        if(!ifile.width || !ifile.height) return false;
		if(IE6) this.IE6_centered();
        this.fs.content.style.overflow="visible";
          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-this.fs.scrollSize;
               if(AUTOSIZE){ifile.height=h-20; ifile.width=Math.round(ifile.height*di); w=ifile.width+20;} //resize image
               else{this.fs.content.style.overflow="auto"; w+=this.fs.scrollSize;} //for scroller size
          }
          if(w>de.offsetWidth){
               w=de.offsetWidth-this.fs.scrollSize;
               if(AUTOSIZE){ifile.width=w-20; ifile.height=Math.round(ifile.width/di); h=ifile.height+20;} //resize image
               else{this.fs.content.style.overflow="auto"; h+=this.fs.scrollSize;} //for scroller size
          }
          this.fs.block.style.marginLeft=-Math.round((w+20)/2)+(ol?ol:0)+"px";
          //this.fs.block.style.marginTop=-Math.round((h+20)/2)+(ot?ot:0)+"px";
		  if(ot){
			this.fs.block.style.top=0;
			this.fs.block.style.marginTop=(ot?ot:0)+"px";
			}
		  else{
			this.fs.block.style.top="50%";
			this.fs.block.style.marginTop=-Math.round((h+20)/2)+"px";
			}
          this.fs.content.style.width=Number(w-20)+"px";
          this.fs.content.style.height=Number(h-20)+"px";

        if(url){
            if(/.+.(jpg)|(gif)$/i.test(url)) this.fs.content.innerHTML='<img src="'+url+'" width="'+ifile.width+'" height="'+ifile.height+'" />';
            else this.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>';
        }
    }
}
