var win = new Class({
	Implements: [ Events, Options],	
	options:{
		width:450,
		height:300,
		background: 'transparent',
		id: 'window_element',
		url: ''
	},
	initialize: function(options){
		this.setOptions(options);
	},
	show: function(url){
		content = '<tr class="win_header"><td class="win_topleft"></td><td class="win_top"></td><td class="win_topright"></td></tr><tr class="win_body"><td class="win_left"></td><td class="win_center"><div class="win_close"></div><div class="win_content"></div></td><td class="win_right"></td></tr>			<tr class="win_footer"><td class="win_btmleft"></td><td class="win_btm"></td><td class="win_btmright"></td></tr>';

		
		// pozadi
		pozadi = new Element('div')
			.setProperties({
				id: this.options.id + '_bg'
			})
			.setStyles({
				position: 'absolute',
				left: 0,
				top: 0,
				width: window.getScrollSize().x,
				height: window.getScrollSize().y,
				background: '#000',
				opacity: 0.3,
				'z-index' : 9000
			})
			.addEvent('click',this.close.bind(this));
				
			if (Browser.Engine.trident){
				
				pozadi.inject($('addon'));
			} else {
				pozadi.inject($('addon'));
			}
		
		
		if (Browser.Engine.trident){
			IE_content = '<table id="'+this.options.id+'" class="win_table">'+content+'</table>';
			IE_HACK_DIV = new Element('div').inject($('addon'));
			IE_HACK_DIV.setHTML(IE_content);
			
			IE_HACK_DIV.getElement('table').setStyles({
					width: this.options.width,
					height: this.options.height,
					background: this.options.background,
					position: 'absolute',
					//border: '1px solid #ff3333',
					'z-index' : 9001
				})
			
		} else {
			var table = new Element('table')
				.setProperties({
					id: this.options.id,
					'class':'win_table'
				})
				.setStyles({
					width: this.options.width,
					height: this.options.height,
					background: this.options.background,
					position: 'absolute',
					//border: '1px solid #ff3333',
					'z-index' : 9001
				})
				.inject($('addon'));
			//table.getElement('tbody').setHTML(content);
			var tbody = new Element('tbody').inject(table);
			tbody.setHTML(content);
		}

			
		
		
		this.center();
		
		if (!url)
			url = this.options.url
			
		new Request.HTML({
			update: $(this.options.id).getElement('.win_content'),
			url: url
		}).send();
		
		$(this.options.id).getElement('.win_close').addEvent('click', this.close.bind(this));
		
	},
	center: function(){
		var el = $(this.options.id);
			
		ws = window.getSize();
		es = el.getSize();
		
		el.setStyles({
			left: ws.x/2 - es.x/2,
			top:  (ws.y/2 - es.y/2) + window.getScroll().y
		});
	},
	close: function(){
		$(this.options.id).dispose();
		$(this.options.id + '_bg').dispose();
	}
});

window.addEvent('load',function(){
		var el = $('obal').getElement('.balicky');
		if (el){
			var sub_window = new win();
			el.getElements('a').addEvent('click', function(e){
				new Event(e).stop();
				sub_window.show(this.getProperty('href'));
		
			});
		}
});