
function _get_method(o_,fct_) {
	var arg = ( _get_method.arguments.length > 2 ) ? _get_method.arguments[2] : null;
	return (function() { o_[fct_]( arg ) });
}

var $Cookie = {
	set: function( name, value, o ) {
		var expires = ( typeof o.expires != "undefined" ) ? o.expires : null;
		var path = ( typeof o.path != "undefined" ) ? o.path : "/";
		var domain = ( typeof o.domain != "undefined" ) ? o.domain : window.location.hostname;
		var secure = ( typeof o.secure != "undefined" ) ? o.secure : false;
		document.cookie = name + "=" + escape (value) + 
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
		((path == null) ? "" : ("; path=" + path)) +  
		((domain == null) ? "" : ("; domain=" + domain)) +    
		((secure == true) ? "; secure" : "");
	}, 
	get: function (name) {
		var arg = name + "=";
		var alen = arg.length;
		var clen = document.cookie.length;
		var i = 0;
		while (i < clen) {
			var j = i + alen;
			if (document.cookie.substring(i, j) == arg) {
				return this._get_val(j);
			}
			i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0) {
				break;
			}
		}
		return 0;
	}, 
	_get_val: function (offset) {
		var endstr = document.cookie.indexOf (";", offset);
		if (endstr == -1)
		endstr = document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
	}
};

Element.addMethods( { 
	setPosition: function( element, _x, _y ) {
		if ( _x == 'left' ) {
			_x = document.viewport.getScrollOffsets().left;
		} else if ( _x == 'right' ) {
			_x = document.viewport.getWidth() - element.getWidth() + document.viewport.getScrollOffsets().left - 25;
		} else if ( _x == 'center' ) {
			_x = (document.viewport.getWidth() - element.getWidth()) / 2 + document.viewport.getScrollOffsets().left;
		} else {
			_x = document.viewport.getScrollOffsets().left + parseInt( _x );
		}
		if ( _y == 'top' ) {
			_y = document.viewport.getScrollOffsets().top;
		} else if ( _y == 'bottom' ) {
			_y = document.viewport.getHeight() - element.getHeight() + document.viewport.getScrollOffsets().top;
		} else if ( _y == 'center' ) {
			_y = (( document.viewport.getHeight() - element.getHeight() ) / 2 ) + document.viewport.getScrollOffsets().top;
		} else {
			_y = document.viewport.getScrollOffsets().top + parseInt( _y );
		}
		element.setStyle( {
			top: _y + 'px', 
			left: _x + 'px'
		} );
	}, 
	replaceClassName: function( element, class_remove, class_add ) {
		element.removeClassName( class_remove );
		element.addClassName( class_add );
	}
} );

var fade_background = Class.create({
	initialize: function( name, opacity, color ) {
		this.name = name;
		this.opacity = opacity;
		this.color = color;
		this.create( );
	}, 
	create: function() {
		if ( ! $( this.name ) ) {
			var f = document.createElement('div');
			f.id = this.name;
			f.style.position = 'absolute';
			f.style.backgroundColor = this.color;
			f.style.zIndex = 200;
			document.body.insertBefore( f, document.body.firstChild ) ;
			this.size();
			this.hide();
			$( this.name ).setOpacity( this.opacity );
			this.place();
			this.bplace = this.place.bindAsEventListener( this );
			Event.observe( window, 'scroll', this.bplace );
			Event.observe( window, 'resize', this.bplace );
		}
	}, 
	size: function() {
		$( this.name ).setStyle( {
			width: document.viewport.getDimensions().width + 'px', 
			height: document.viewport.getDimensions().height + 'px'
		} );
	}, 
	show: function() {
		$( this.name ).show();
	},
	hide: function() {
		$( this.name ).hide();
	}, 
	place: function() {
		this.size();
		$( this.name ).setPosition( 'center', 'center' );
	}, 
	remove: function() {
		Event.stopObserving( window, 'scroll', this.bplace );
		Event.stopObserving( window, 'resize', this.bplace );
		$( this.name ).remove();
	}
});

var $Dhtml = {
	show: function( name ) {
		if ( !Prototype.Browser.IE ) {
			document.body.style.overflow = 'hidden';
		}
		this.create( name );
		this.place( name );
		this.background.show();
		
	},
	hide: function ( name ) {
		Event.stopObserving( window, 'scroll', this.bplace );
		Event.stopObserving( window, 'resize', this.bplace );
		this.background.remove();
		this.remove( name );
		if ( !Prototype.Browser.IE ) {
			document.body.style.overflow = 'auto';
		}
	}, 
	create: function( name ) {
		if ( $( name ) ) {
			this.background = new fade_background( name + "_bg", 0.5, "#000" );
			$( name ).setStyle( { 
				position: 'absolute', 
				zIndex: 201,
				display: 'block'
			} );
			this.bplace = this.place.bindAsEventListener( this );
			Event.observe( window, 'scroll', this.bplace );
			Event.observe( window, 'resize', this.bplace );
		}
	}, 
	place: function( name ) {
		$( name ).setPosition( 'center', 'center' );
	}, 
	remove: function( name ) {
		$( name ).setStyle( { display: 'none' } );
	}
};