OverlayOptions = Object.extend({
	reload: true,
	iframe_path: "",
	iframe_content: "",
	iframeWidth: 500,
	iframeHeight: 500
}, window.OverlayOptions || {});

var Overlay = Class.create();

Overlay.prototype = {
	
	initialize: function() {   

	        var objBody = $$('body')[0];
	
		objBody.appendChild(Builder.node('div',{id:'overlay'}));
		objBody.appendChild(Builder.node('div',{id:'close_img'}));
		objBody.appendChild(Builder.node('div',{id:'iframe_brd'}));
	        $('iframe_brd').appendChild(Builder.node('iframe',{id:'frame_area', name:'frm_overlay', frameborder:'0', border:'0', marginwidth:'0', marginheight:'0', scrolling:'auto'}));
	
	        $('close_img').hide().observe('click', (function() { this.end(); }).bind(this));
		$('overlay').hide();
		$('iframe_brd').hide();
	},

	//  start()
	//  Display overlay and inframe.
	start: function() {    
	
		$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' });
		$$('iframe').each(function(node){ node.style.display = 'none' });
		$('frame_area').show();
		
		// Stretch overlay to fill page and fade in
		var arrayPageSize = this.getPageSize();
		$('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px', opacity: 0.5 });
		$('overlay').show();
		
		// Calculate top and left offset for the iframe
		var arrayPageScroll = document.viewport.getScrollOffsets();
		var iframeTop = arrayPageScroll[1] + (((document.viewport.getHeight() - OverlayOptions.iframeHeight) / 2) < 0 ? 10 : ((document.viewport.getHeight() - OverlayOptions.iframeHeight) / 2));
		var iframeLeft = (arrayPageSize[0] - OverlayOptions.iframeWidth) / 2;
		$('close_img').setStyle({ top: (iframeTop - 10) + 'px', left: (iframeLeft + OverlayOptions.iframeWidth + 5) + 'px'});
		$('close_img').show();
		$('frame_area').setStyle({ width: OverlayOptions.iframeWidth + 'px' , height: OverlayOptions.iframeHeight + 'px' });
		$('iframe_brd').setStyle({ width: OverlayOptions.iframeWidth + 'px' , height: OverlayOptions.iframeHeight + 'px' , top: iframeTop + 'px', left: iframeLeft + 'px' }).show();
		
		if (OverlayOptions.iframe_path == "") {
			Element.insert($('frame_area'), {after: OverlayOptions.iframe_content});
		}
		else {
			$('frame_area').src = OverlayOptions.iframe_path;
		}
	},

	//  end()
	end: function() {
		$('close_img').hide();
		$('iframe_brd').hide();
		$('overlay').hide();
		$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'visible' });
		if (OverlayOptions.reload == true) {
			window.location = window.location.toString().replace(/show=editor/, "");
		}
	},

	//  getPageSize()
	getPageSize: function() {
	        
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else 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
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				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 = xScroll;		
		} else {
			pageWidth = windowWidth;
		}
		
		return [pageWidth,pageHeight];
	}
}


DBoxOptions = Object.extend({
	iframe_path: "",
	iframeWidth: 500,
	iframeHeight: 500
}, window.DBoxOptions || {});

var DBox = Class.create();

DBox.prototype = {
	
	initialize: function() {   

	        var objBody = $$('body')[0];
	
		objBody.appendChild(Builder.node('div',{id:'overlay'}));
	        objBody.appendChild(Builder.node('div',{id:'div_area'}));
	
	
		$('overlay').hide();
		$('div_area').hide();
	},

	//  start()
	//  Display overlay and inframe.
	start: function() {    
	
		$$('select', 'object', 'embed', 'iframe').each(function(node){ node.style.visibility = 'hidden' });
		
		// Stretch overlay to fill page and fade in
		var arrayPageSize = this.getPageSize();
		$('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px', opacity: 0.5 });
		$('overlay').show();
			
		
		// Calculate top and left offset for the iframe
		var arrayPageScroll = document.viewport.getScrollOffsets();
		var iframeTop = arrayPageScroll[1] + (((document.viewport.getHeight() - DBoxOptions.iframeHeight) / 2) < 0 ? 0 : ((document.viewport.getHeight() - DBoxOptions.iframeHeight) / 2));
		var iframeLeft = (arrayPageSize[0] - DBoxOptions.iframeWidth) / 2;
		$('div_area').setStyle({ width: DBoxOptions.iframeWidth + 'px' , height: DBoxOptions.iframeHeight + 'px' , top: iframeTop + 'px', left: iframeLeft + 'px' }).show();
		$('div_area').update('<div class="clearfix"><div class="f_right pad_05"><a href="#" onclick="DB.end(); return false;" class="dark small bold">Inchide</a> <a href="#" onclick="DB.end(); return false;"><img src="/img/site/spacer.gif" class="img_exit absmid" /></a></div><img src="/img/site/logo_small.gif" style="margin-top: 0.5em; margin-left: 1em;" /></div> <div class="pad_1"><p>Hai cu noi in <b>Filmoteca</b> si afla totul despre <br /><b>filmele cool si filmele cult</b> de pe ecrane, <br />recomandarile zilei din <b>programul TV</b> si <br />ultimele <b>stiri</b> din lumea filmului!</p><p>Inregistreaza-te acum si vei putea vota pentru <br /><b>actorii si filmele preferate</b>, vei avea pagina<br /> ta personalizata cu <b>recomandarile</b> noastre<br /> si iti vei gasi <b>prieteni</b> cu gusturi comune in<br /> materie de cinema!</p></div> <div style="padding: 1em;"><a href="' + link_signup + '"><img src="/img/site/btn_overlay.gif" /></a></div></div>');
	},

	//  end()
	end: function() {
		$('div_area').hide();
		$('overlay').hide();
		$$('select', 'object', 'embed', 'iframe').each(function(node){ node.style.visibility = 'visible' });
	},

	//  getPageSize()
	getPageSize: function() {
	        
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else 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
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				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 = xScroll;		
		} else {
			pageWidth = windowWidth;
		}
		
		return [pageWidth,pageHeight];
	}
}

CBoxOptions = Object.extend({
	boxContent: "",
	boxWidth: 500,
	boxHeight: 500
}, window.CBoxOptions || {});

var CBox = Class.create();

CBox.prototype = {
	
	initialize: function() {   

	        var objBody = $$('body')[0];
	
		objBody.appendChild(Builder.node('div',{id:'overlay'}));
		objBody.appendChild(Builder.node('div',{id:'close_img'}));
	        objBody.appendChild(Builder.node('div',{id:'div_area'}));
		
	        $('close_img').hide().observe('click', (function() { this.end(); }).bind(this));
		$('overlay').hide();
		$('div_area').hide();
	},

	//  start()
	//  Display overlay and inframe.
	start: function() {    
	
		$$('select', 'object', 'embed', 'iframe').each(function(node){ node.style.visibility = 'hidden' });
		
		// Stretch overlay to fill page and fade in
		var arrayPageSize = this.getPageSize();
		$('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px', opacity: 0.5 });
		$('overlay').show();
			
		
		// Calculate top and left offset for the iframe
		var arrayPageScroll = document.viewport.getScrollOffsets();
		var boxTop = arrayPageScroll[1] + (((document.viewport.getHeight() - CBoxOptions.boxHeight) / 2) < 0 ? 0 : ((document.viewport.getHeight() - CBoxOptions.boxHeight) / 2));
		var boxLeft = (arrayPageSize[0] - CBoxOptions.boxWidth) / 2;
		$('close_img').setStyle({ top: (boxTop - 10) + 'px', left: (boxLeft + CBoxOptions.boxWidth - 10) + 'px'});
		$('close_img').show();
		$('div_area').setStyle({ width: CBoxOptions.boxWidth + 'px' , height: CBoxOptions.boxHeight + 'px' , top: boxTop + 'px', left: boxLeft + 'px' }).show();
		$('div_area').update(CBoxOptions.boxContent);
	},

	//  end()
	end: function() {
		$('close_img').hide();
		$('div_area').hide();
		$('overlay').hide();
		$$('select', 'object', 'embed', 'iframe').each(function(node){ node.style.visibility = 'visible' });
	},

	//  getPageSize()
	getPageSize: function() {
	        
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else 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
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				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 = xScroll;		
		} else {
			pageWidth = windowWidth;
		}
		
		return [pageWidth,pageHeight];
	}
}

