HtmlboxOptions = Object.extend({
		overlayOpacity: 0.8,
		resizeSpeed: 7,
		animate: true,
		startWidth: 250,
		startHeight: 250,
		endWidth: 800,
		endHeight: 350
}, window.HtmlboxOptions || {});

var Htmlbox = Class.create();

Htmlbox.prototype = {

    initialize: function() {    
        if (HtmlboxOptions.resizeSpeed > 10) HtmlboxOptions.resizeSpeed = 10;
        if (HtmlboxOptions.resizeSpeed < 1)  HtmlboxOptions.resizeSpeed = 1;
	    this.resizeDuration = HtmlboxOptions.animate ? ((11 - HtmlboxOptions.resizeSpeed) * 0.15) : 0;
	    this.overlayDuration = HtmlboxOptions.animate ? 0.2 : 0;  // shadow fade in/out duration
    },

	start: function(country_id) {

			$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' });
			$('selCountry').disable();
			var size = (HtmlboxOptions.animate ? 250 : 1) + 'px';
			$('html_content').setStyle({ width: size, height: size });
			$('html_overlay').hide().observe('click', (function() { this.end(country_id); }).bind(this));
			$('html_box').show();
			var arrayPageSize = this.getPageSize();
		    $('html_overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
		    new Effect.Appear($('html_overlay'), { duration: this.overlayDuration,
											from: 0.0,
											to: HtmlboxOptions.overlayOpacity,
											afterFinish: (function(){ this.resizeHtmlContainer(country_id); }).bind(this)
			});	
	},
	
	resizeHtmlContainer: function(country_id) {
		var arrayPageScroll = document.viewport.getScrollOffsets();
		var HtmlboxTop = arrayPageScroll[1] + (document.viewport.getHeight() / 10);
		var HtmlboxLeft = arrayPageScroll[0];
		$('html_content').setStyle({ top: HtmlboxTop + 'px', left: HtmlboxLeft + 'px'}).show();
		var xScale = (HtmlboxOptions.endWidth  / HtmlboxOptions.startWidth)  * 100;
		var yScale = (HtmlboxOptions.endHeight / HtmlboxOptions.startHeight) * 100;
		new Effect.Scale($('html_content'), yScale, {scaleX: false, duration: this.resizeDuration, queue: 'front'}); 
		new Effect.Scale($('html_content'), xScale, {
						   scaleY: false, duration: this.resizeDuration, delay: this.resizeDuration,
						   afterFinish: (function(){ $(country_id).setStyle({ fontSize: '10pt'}).show();})
		}); 
	},

	end: function(country_id) {
		$(country_id).hide();
		$('html_content').hide();
		$('html_box').hide();
		new Effect.Fade($('html_overlay'), { duration: this.overlayDuration });
		$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'visible' });
		$('selCountry').enable();
	},

	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 + yScroll;
			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];
	} 
}
var HtmlContainer = new Htmlbox(); 

	function urlToPage(url) {
		var pattern = new RegExp ("http");
		$('selCountry').target='';
		if (pattern.test(url)) {
			$('selCountry').target='_blank';
		}
		$('selCountry').action=url;
		$('selCountry').submit();
	}



