var JGNT_Upper = Class.create( {

	CurDelay: 0,
	strCurrentDivID: "",
	nOverlayState: 0,
	nEffectDuration: 0.2,
	nOverlayOpacity: 0.8,
	nInfoOpacity: 0.8,
	nStayVisibleDuration: 3000,
		
	initialize: function( UpperOptions ) {
		var objBody = $$('body')[0];
		objBody.appendChild(Builder.node('div',{id:'jgnt_upper_overlay'}));
		objBody.appendChild(Builder.node('div',{id:'jgnt_upper'}));
		
		$('jgnt_upper_overlay').hide();
		$('jgnt_upper').hide();
		
		// init all uppers
		$('jgnt_upper').appendChild( $('jgnt_up_autorize').remove() );
		$('jgnt_up_autorize').hide();

		$('jgnt_upper').appendChild( $('jgnt_up_subscribe').remove() );
		$('jgnt_up_subscribe').hide();

		$('jgnt_upper').appendChild( $('jgnt_up_subscribe_done').remove() );
		$('jgnt_up_subscribe_done').hide();

		$('jgnt_up_info').hide();
		
	    }, // initialize

    ShowOverlay: function( ) {    

		$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' });

        var arrayPageSize = this.getPageSize();
        $('jgnt_upper_overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
        
        new Effect.Appear($('jgnt_upper_overlay'), { duration: this.nEffectDuration, from: 0.0, to: this.nOverlayOpacity });

		this.nOverlayState = 1;

    }, // Show
    
    HideOverlay: function( ) {
		if( this.nOverlayState ){
			new Effect.Fade($('jgnt_upper_overlay'), { duration: this.nEffectDuration });
			$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'visible' });
			this.nOverlayState = 0;
		};

    }, // Hide

    Show: function( strDivID ) {    
    	if( ! strDivID ) return;
		$(strDivID).show();
		this.SetCurrentID( strDivID );
    	
        new Effect.Appear($('jgnt_upper'), { duration: this.nEffectDuration, from: 0.0, to: 1 });
		this.ShowOverlay();
		
    }, // Show

    ShowInfo: function( strDivID, strMessage ) {    
		
		$(strDivID+'_msg').update( strMessage );
    	
        new Effect.Appear($(strDivID), { duration: this.nEffectDuration, from: 0.0, to: this.nInfoOpacity, afterFinish: ( 
        	function( effect ){ 
        		this.CurDelay = setTimeout( function(){ this.HideNow(strDivID); }.bind(this), this.nStayVisibleDuration );
        		} 
        	).bind(this) });
		
    }, // Show

    Hide: function( ) {

		new Effect.Fade($('jgnt_upper'), { duration: this.nEffectDuration, afterFinish: ( function( ) { this.HideCurrentID(); } ).bind(this) });
		this.HideOverlay();

    }, // Hide

    HideNow: function( strDivID ) {
		clearTimeout( this.CurDelay );
		Effect.Fade( $(strDivID), { duration: this.nEffectDuration } );
		$('jgnt_upper').hide();
		this.HideCurrentID();
		this.HideOverlay();
    }, // Hide

    HideCurrentID: function( ) {
    	if( this.GetCurrentID() != '' )
    	$(this.strCurrentDivID).hide();
    	this.SetCurrentID( '' );
    }, // Hide

	SetCurrentID: function( strDivID ) {
		this.strCurrentDivID = strDivID;
	},

	GetCurrentID: function( ) {
		return this.strCurrentDivID;
	},
    
    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];
	}

} ); // JGNT_Upper

var myJGNT_Upper;

document.observe('dom:loaded', function () { 

	myJGNT_Upper = new JGNT_Upper(); 

});
