


var box = {

	isOpen:false,
	//name : "flashbox",
	dv : null,
	bg : null,
	loader : null ,
	
	//headerText : '&nbsp;',
	//footerText : '<a href="#" onclick="flashBox.close(); return false;" class="link">zamknij okno</a>',

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	show : function(str, title, type, param)
	{
		if(this.isOpen)
			return false;
		
		this.dv = this.addDiv(null, null, 'box');
		this.dv.style.zIndex = 101;
		this.dv.style.position = 'absolute';
		
		param = param || {};

		this.isOpen = true;

		if(title)
			this.addDiv(this.dv, title, 'box_header');
		
		var main = this.addDiv(this.dv, null, 'box_main');
		this.addDiv(this.dv, '<a href="#" onclick="box.close(); return false;">zamknij [x]</a>', 'box_footer');
		
		type = type || this.getType(str);
		
		switch(type)
		{
			case 'img':
			
				//SetPos(this.dv, 50, 50);
				//$(this.name+"_content").innerHTML = '<img src="'+url+'">';
			
			break;
			
			case 'http':
			case 'url':
				
				this.bgSet(true);
				
				var req = mint.Request();
				var that = this;

				req.OnSuccess = function()
				{
					that.wait(-1);
					main.innerHTML = this.responseText;
					that.dv.style.display = "block";
					that.setPos();
					
				}

				this.dv.style.display = "none";
				this.wait();

				req.Send(str);
				//SetPos(this.dv, 250, 250);
				
			break;
			
			case 'iframe':
				
				this.bgSet(true);
				
				var width = param.width || 500;
				var height = param.height || 300;
				var name = param.name || 300;
				
				main.innerHTML = '<iframe width="'+width+'" height="'+height+'" name="'+name+'" src="'+str+'" frameborder="0" marginheight="0" marginwidth="0" scrolling="Yes"></iframe>';
				
				this.setPos();
				
			break;
			
			default:
				
				main.innerHTML = str;
				this.setPos();
		}
				
		
		
		//this.dv.style.display = "none";
		//this.dv.style.border = "1px dashed #999999";
		//this.dv.style.backgroundColor = "#cccccc";
		//this.dv.style.cursor = "move";
		//this.mov.setAttribute('id', this.name+"_mover");

		//document.body.appendChild(this.dv);
		
		//this.addDiv(this.dv, '3333333', 'as');

		//var head = $(this.name+"_header");
		//head.innerHTML = title || this.headerText;

		//this.dv.style.display = "block";

		/*
		mint.fx.Style(this.dv, "opacity", 0, 100, 10, 200);	
		this.is_after_mov = false;
		
		
		if(this.mov == null)
		{
			this.mov = document.createElement('div');

			var p = GetPos(head);
			var s = GetSize(this.dv);

			SetSize(this.mov, s.width, s.height);
			SetPos(this.mov, p.x, p.y);

			this.mov.innerHTML = "";
			this.mov.style.position = "absolute";
			this.mov.style.display = "none";
			this.mov.style.border = "1px dashed #999999";
			this.mov.style.backgroundColor = "#cccccc";
			this.mov.style.cursor = "move";
			this.mov.setAttribute('id', this.name+"_mover");

			document.body.appendChild(this.mov);
			var that = this;
			mint.gui.RegisterDragObject(this.mov);
			
			AddEvent(this.mov, 'mouseup', function(){	that.showMove(0, head);});
			AddEvent(head, 'mouseover', function(){	that.showMove(1, head);});
			AddEvent(this.dv, 'mouseout', function(){	that.showMove(-1, head);});
		}
		*/
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	bgSet : function(p)
	{
		if(p)
		{
			var ps = this.pageSize();

			this.bg = this.addDiv();
			//this.bg.style.display = 'none';
			this.bg.style.position = 'absolute';
			this.bg.style.top = '0px';
			this.bg.style.left = '0px';
			this.bg.style.zIndex = '99';
 			this.bg.style.width = '100%';
			this.bg.style.height = '100%';
			this.bg.className = "box_bg";

			this.bg.style.width = ps.pageWidth;
			this.bg.style.height = ps.pageHeight;
		}
		else
			document.body.removeChild(this.bg);
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	wait : function(x)
	{
		if(x == -1)
		{
			document.body.removeChild(this.loader);
			this.loader = null;
		}
		else
		{
			if(this.loader)
				return false;
			
			this.loader = this.addDiv(null, '<img src="images/loader.gif">');
			this.loader.style.position = "absolute";
			this.loader.style.zIndex = 100;
		
			this.setPos(this.loader);
		}
	},	
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	close : function(funct)
	{
		var that = this;

		mint.fx.Style(this.dv, "opacity", 100, 0, 10, 200, null, function()
		{
			document.body.removeChild(that.dv);
			that.isOpen = false;
			that.bgSet(false);
			if(funct)
			{
				//window.execScript(funct);
				eval(funct);
			}
		}
		);
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	getType : function(str)
	{
		if(str.match(/^\?/))
			return 'url';
		else
			return 'str';
	},
	
	/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	addDiv : function(obj, str, cName)
	{
		var d = document.createElement('div');
		
		if(str)
			d.innerHTML = str;
		
		if(cName)
			d.className = cName;
		
		(obj || document.body).appendChild(d);
		
		return d;
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	setPos : function(obj)
	{
		var x = 0; y = 0;
		var size = GetSize(obj || this.dv);
		var ps = this.pageSize();

		//this.loader.style.left = ps.windowWidth/2 - GetWidth(this.loader)/2;
		//this.loader.style.top = ps.windowHeight/2 + this.scroll();
		
		x = ps.pageWidth/2 - size.width/2;
		y = ps.windowHeight/2 - size.height/2 + this.scroll();

		SetPos(obj || this.dv, x, y);
		SetSize(obj || this.dv, size.width, size.height);
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	scroll : function()
	{
		// Core code from - quirksmode.org
		
		var yScroll;
	
		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
		}
	
		return yScroll;
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	pageSize : function()
	{
		// Core code from - quirksmode.org

		var xScroll, yScroll;
		var pageWidth, pageHeight, windowWidth, windowHeight;
	
		if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
	
		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
	
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else {
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}
	
		return {pageWidth:pageWidth, pageHeight:pageHeight, windowWidth:windowWidth, windowHeight:windowHeight};
	}	
	
};


