
/*  
	Cyber Forge Sp z o.o.
	© All rights reserved
*/


var image_box = {

	initialized : false,
	animate : true,
	isopera : false,
	isie : false,
	animb : 0,
	fader : 0,
	perc : 0,
	bckgheight : 0,
	preimg : Object,
	box : Object,
	box_loading : Object,
	box_border : Object,
	box_imgdiv : Object,
	box_image : Object,
	box_caption : Object,
	box_capdiv : Object,
	
	init : function() {
		this.box = document.getElementById('imagebox');
		this.box_loading = document.getElementById('imageloading');
		this.box_border = document.getElementById('imageboxborder');
		this.box_imgdiv = document.getElementById('imageboximage');
		this.box_image = document.getElementById('imageboximg');
		this.box_caption = document.getElementById('imagecaption');
		this.box_capdiv = document.getElementById('imgcaption');
		this.isopera = (navigator.appName.indexOf("Opera")!=-1);
		this.isie = (navigator.appName.indexOf("Internet Explorer")!=-1);
		if(this.isopera) { this.box.style.overflow = "auto"; }
		this.preimg = new Image();
		this.initialized = true;
		if(this.animate)
		{
			this.preimg.onload = function() { image_box.animateshow(); }
		} else {
			this.preimg.onload = function() { image_box.normalshow(); }
		}
	},
	
	animborder_height : function() {
		if(this.animb<(this.preimg.height+49))
		{
		this.perc = Math.ceil((this.animb / (this.preimg.height+49)) * 100);
		
		if(this.perc<25)
		{
			this.fader = 35;
		}
		else if(this.perc<50)
		{
			this.fader = 30;
		}
		else if(this.perc<75)
		{
			this.fader = 25;
		}
		else if(this.perc<95)
		{
			this.fader = 12;
		}
		else
		{
			this.fader = 0;
		}
		this.animb+=5;
		this.animb+=this.fader;
		if(this.isopera)	{ this.box_border.style.visibility = "hidden"; }
		this.box_border.style.height = this.animb+"px";
		if(this.isopera)	{ this.box_border.style.visibility = "visible"; }
		setTimeout("image_box.animborder_height();",1);
		} else { 
			this.box_border.style.height = (this.preimg.height+49)+"px";
			this.animb = 0;
			this.animborder_width(); 
		}
	},
	
	animborder_width : function() {
		if(this.animb<(this.preimg.width+10))
		{
		this.perc = Math.ceil((this.animb / (this.preimg.width+10)) * 100);
		
		if(this.perc<25)
		{
			this.fader = 35;
		}
		else if(this.perc<50)
		{
			this.fader = 30;
		}
		else if(this.perc<75)
		{
			this.fader = 25;
		}
		else if(this.perc<95)
		{
			this.fader = 12;
		}
		else
		{
			this.fader = 0;
		}
		this.animb+=5;
		this.animb+=this.fader;
		if(this.isopera)	{ this.box_border.style.visibility = "hidden"; }
		this.box_border.style.width = this.animb+"px";
		if(this.isopera)	{ this.box_border.style.visibility = "visible"; }
		setTimeout("image_box.animborder_width();",1);
		} else { 
			this.box_border.style.width = (this.preimg.width+10)+"px";
			this.box_imgdiv.style.display = "block";
			this.box_imgdiv.style.opacity = ".0";
			this.box_imgdiv.style.filter = "alpha(opacity=0)"; 
			this.box_image.src = this.preimg.src;
			this.animb = 0;	
			this.fade_image();
			this.box_capdiv.style.visibility = "visible";
			}
	},
	
	fade_image : function() {
		if(this.animb<99)
		{
			if(this.animb<20)
			{
				this.fader = 15;
			}
			else if(this.animb<40)
			{
				this.fader = 13;
			}
			else if(this.animb<60)
			{
				this.fader = 11;
			}
			else if(this.animb<90)
			{
				this.fader = 8;
			}
			else
			{
				this.fader = 0;
			}
		this.animb++;
		this.animb+=this.fader;
		if(this.isopera)	{ this.box_border.style.visibility = "hidden"; }
		this.box_imgdiv.style.opacity = "."+this.animb;
		this.box_imgdiv.style.filter = "alpha(opacity="+this.animb+")";
		if(this.isopera)	{ this.box_border.style.visibility = "visible"; }
		setTimeout("image_box.fade_image();",1);
		} 
	},
	
	animateshow : function() {
		
		this.box_imgdiv.style.display = "none";
		this.box_loading.style.display = "none";
		this.box_border.style.display = "block";
		this.box_border.style.width = "0px";
		this.box_border.style.height = "0px";
		this.animb = 0;
		this.animborder_height();
	},
	
	normalshow : function() {
		if(this.isopera) {	this.box_border.style.visibility = "hidden"; }
		this.box_loading.style.display = "none";
		this.box_image.src = this.preimg.src;
		this.box_border.style.width = (this.preimg.width+10)+"px";
		this.box_border.style.height = (this.preimg.height+49)+"px";
		this.box_imgdiv.style.display = "block";
		this.box_border.style.display = "block";
		this.box_capdiv.style.visibility = "visible";			
		if(this.isopera) {	this.box_border.style.visibility = "visible"; }
	},
	
	show : function(pic,caption) {
		if (!this.initialized) { this.init(); }
		this.box_caption.innerHTML = caption;
		this.box.style.display = "block";
    scroll(0,0);
    if(document.documentElement.scrollHeight>document.documentElement.clientHeight)
    {
      this.box.style.height = document.documentElement.scrollHeight+"px";
    } else if (document.documentElement.clientHeight!=0) {
      this.box.style.height = document.documentElement.clientHeight+"px";
    }
    
		this.box_loading.style.display = "block";
		this.preimg.src = pic;
	},
	
	close : function() {
		this.box.style.display = "none";
		this.box_imgdiv.style.display = "none";
		this.box_border.style.display = "none";
		this.box_loading.style.display = "none";
		this.box_border.style.width = "0px";
		this.box_border.style.height = "0px";
		this.box_capdiv.style.visibility = "hidden";
		this.box_image.src = null;
		this.preimg.src = null;
	}
	

}
