var WinMinube = Class.create();

WinMinube.prototype = {
	uri: String,
	id: String,
	parent: String,
	width: String,
	height: String,
	centered: String,
		
	initialize: function(id,uri,root,width,height,centered) {
		this.uri = uri;
		this.id = id;
		this.parent = root;
		this.width = width;
		this.height = height;
		this.centered = centered;		
		var objParent = $(root);
		var objInfo = document.createElement("div");
		objInfo.setAttribute('id',this.id);
		objParent.appendChild(objInfo);		
		var left = (objParent.getWidth()/2) - (width/2);
		
		if (centered) {
			var top = this.getScrollTop() + (this.getClientHeight()/2) - (height/2) + 50;
		} else {
			var top = 200;			
		}														
		$(this.id).setStyle({			
			display: 'none',
			position: 'absolute',
			background: 'transparent',
			left: left + 'px',
			top: top + 'px',				
			width: width + 'px',
			height: height + 'px'
		});	
	},	
	show: function() {
//		var scroll = this.getScrollTop();
//		if (scroll > 0) {
//			var top = scroll+50;
//			$(this.id).setStyle({			
//				top: top + 'px'				
//			});	
//		}
		if ($(this.id).innerHTML == "" ) {
			// creating IFRAME + show
			$(this.id).update('<iframe id="'+ this.id +'_iframe" src="'+ this.uri +'" scrolling="no" frameborder="0" width="100%" height="100%"></iframe>');
			$(this.parent).setStyle({			
				position: 'relative'
			});							
			$(this.id).show();							
		} else {
			// Just show
			$(this.id).show();			
		}
	},
	
	hide: function() {
		$(this.id).remove();
		this.initialize(this.id,this.uri,this.parent,this.width,this.height,this.centered);
	},
	
	resize: function(nWidth,nHeight) {			
		$(this.id).setStyle({			
			width: nWidth + 'px',
			height: nHeight + 'px'			
		});			
	},
	
	changeContent: function(nUri) {
		this.uri = nUri;
		$(this.id + "_iframe").src = this.uri;
	},
	
	getScrollTop: function () {
		return this.chooseValues (
			window.pageYOffset ? window.pageYOffset : 0,
			document.documentElement ? document.documentElement.scrollTop : 0,
			document.body ? document.body.scrollTop : 0
		);
	},
	
	getClientHeight: function () {
		return this.chooseValues (
			window.innerHeight ? window.innerHeight : 0,
			document.documentElement ? document.documentElement.clientHeight : 0,
			document.body ? document.body.clientHeight : 0
		);
	},
	getClientWidth: function () {
		return this.chooseValues (
			window.innerWidth ? window.innerWidth : 0,
			document.documentElement ? document.documentElement.clientWidth : 0,
			document.body ? document.body.clientWidth : 0
		);
	},			
	chooseValues: function (n_win, n_docel, n_body) {
		var n_result = n_win ? n_win : 0;
		if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
		return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
	}		
}