var ui = {};

ui.window = function(c,o){
	var self = this;
	var opt = {
		modal:true,
		background:'#EBE9EA url(img/bg_window.jpg) repeat-x',
		width:400,
		height:500
	};
	
	$.extend(opt,o);
	
	if(opt.modal){
		if($('#modal').length == 0){
			$('<div></div>').attr('id','modal').appendTo(c).hide().css({
				position:($.browser.msie) && ($.browser.version == '6.0') ? 'absolute' : 'fixed',
				top:0,
				margin:0,
				padding:0,
				left:0,
				background:'#000',
				width:'100%',
				height:'100%',
				opacity:0.5,
				zIndex:1000
			})
		}
	}
	
	$(document.body).css({'width':'100%','height':'100%'});	
	var win = $('<div></div>').appendTo(c).hide().css({
		background:opt.background,
		width:opt.width,
		height:opt.height,
		position:'absolute',
		zIndex:2000,
		top: 
		( $(window).height()/2 - opt.height/2 + $(window).scrollTop() < $(window).scrollTop() )			
		? $(window).scrollTop() + 10 
		: $(window).height()/2 - opt.height/2 + $(window).scrollTop(),
		left:
		( $(window).width()/2 - opt.width/2 + $(window).scrollLeft() < $(window).scrollLeft() ) 
		? $(window).scrollLeft() + 10 
		: $(window).width()/2 - opt.width/2 + $(window).scrollLeft()		
	});

	var date = new Date();
	this.id = 'x'+date.getTime();
	this.body = $('<div></div>').attr('id',this.id).appendTo(win).css({
		position:'relative',
		top:60,
		left:15,
		width:opt.width - 30,
		height:opt.height - 120
	});
	
	var title = $('<div></div>').html(opt.title).appendTo(win).css({
		position:'absolute',
		top:30,
		left:15,
		fontSize:14,
		fontFamily:'arial',
		color:'#000000',
		fontWeight:'bold',
		height:22,
		background:'url(img/line_title.gif) left bottom no-repeat',
		width:'100%'
	});
	
	var btn_cerrar = $('<div></div>').html('cerrar').appendTo(win).css({
		cursor:'pointer',
		background:'url(img/ico_cerrar.gif) right no-repeat',
		width:48,
		height:14,
		position:'absolute',
		right:10,
		top:10,		
		textDecoration:'underline',
		fontSize:11,
		fontFamily:'arial',
		color:'#000000'
	}).bind('click',function(){
		self.hide();
	});
	
	this.show = function(){
		$('#modal').fadeIn();
		win.fadeIn();
		$(document).bind('mousedown',function(e){
			if($(e.target).is('#modal')){
				self.hide();
			}
		});		
	};
	
	this.hide = function(){
		$('#modal').fadeOut();
		win.fadeOut();
		return false;
	};
		
}
