
var PagePopup=
{
	Holder	:null,
	Back	:null,
	Front	:null,
	Frame	:null,
	Close	:null,
	Scroll	:{X:0,Y:0},
	Timer	:null,
	Width	:0,
	Height	:0,
	CurTime	:0,
	TimeFade:0,
	TimeSize:0,
	Opacity	:0,
	
	Open:function(Url,Width,Height,Background,Opacity,TimeFade,TimeSize)
	{
		var Self=this;

		this.CreateElements();
		
		this.Scroll.X=(document.body.parentNode.scrollLeft	?document.body.parentNode.scrollLeft:document.body.scrollLeft);
		this.Scroll.Y=(document.body.parentNode.scrollTop	?document.body.parentNode.scrollTop	:document.body.scrollTop);

		document.body.parentNode.style.overflow	='hidden';
		document.body.parentNode.scrollLeft		=document.body.scrollLeft		='0';
		document.body.parentNode.scrollTop		=document.body.scrollTop		='0';

		this.Url		=Url;
		this.Width		=Width;
		this.Height		=Height;
		this.Opacity	=Opacity;
		this.TimeFade	=TimeFade;
		this.TimeSize	=TimeSize;
		this.CurTime	=0;

		this.Frame.src='about:blank';
		this.Close.style.display='none';

		PagePopup.Update();
		
		window.onresize=function(){ Self.Resize(); }
		
		this.Resize();

		this.Holder.style.display	='block';
		this.Front.style.display	='block';
		this.Back.style.background	=Background;

		this.Frame.style.width	=Math.round(this.Width)+'px';
		this.Frame.style.left	=-Math.round(this.Width/2)+'px';
	},
	
	Resize:function()
	{
		this.Holder.style.width		=this.Back.style.width	=((document.body.parentNode.clientWidth?document.body.parentNode.clientWidth:document.body.clientWidth)-20)+'px';
		this.Holder.style.height	=this.Back.style.height	=(document.body.parentNode.clientHeight?document.body.parentNode.clientHeight:document.body.clientHeight)+'px';
	},
	
	ClosePage:function()
	{
		var Ratio	=1-((this.CurTime/this.TimeFade)>1?1:((this.CurTime/this.TimeFade)<0?0:(this.CurTime/this.TimeFade)));
		var Opacity	=Math.round(Ratio*this.Opacity);

		this.Back.style.opacity		=(Opacity/100);
		this.Back.style.mozOpacity	=(Opacity/100);
		this.Back.style.KhtmlOpacity=(Opacity/100);
		this.Back.style.filter		='alpha(opacity='+Opacity+')';

		this.CurTime+=50;

		if(this.CurTime<=this.TimeFade)
		{
			clearTimeout(this.Timer);
			setTimeout(function(){ PagePopup.ClosePage(); },50);
		}
		else
		{
			this.Holder.style.display				='none';
			this.Front.style.display				='none';
			document.body.parentNode.style.overflow	='auto';
			document.body.parentNode.scrollLeft		=document.body.scrollLeft		=this.Scroll.X;
			document.body.parentNode.scrollTop		=document.body.scrollTop		=this.Scroll.Y;
		}
	},
	
	Update:function()
	{
		var Width	=0;
		var Height	=0;

		if(this.CurTime<=this.TimeFade)
		{
			var Ratio	=(this.CurTime/this.TimeFade)>1?1:((this.CurTime/this.TimeFade)<0?0:(this.CurTime/this.TimeFade));
			var Opacity	=Math.round(Ratio*this.Opacity);

			this.Back.style.opacity		=(Opacity/100);
			this.Back.style.mozOpacity	=(Opacity/100);
			this.Back.style.KhtmlOpacity=(Opacity/100);
			this.Back.style.filter		='alpha(opacity='+Opacity+')';
		}
		else
		{
			Width	=((this.CurTime-this.TimeFade)/this.TimeSize)*this.Width;
			Width	=Width<2?2:(Width>this.Width?this.Width:Width);
			Height	=((this.CurTime-this.TimeFade)/this.TimeSize)*this.Height;
			Height	=Height<2?2:(Height>this.Height?this.Height:Height);
		}

		if(this.CurTime>=this.TimeFade+this.TimeSize)
		{
			this.Close.style.display='block';
			this.Close.style.top	=-Math.round(this.Height/2)+'px';
			this.Close.style.left	=Math.round(this.Width/2-16)+'px';
			setTimeout(function(){ PagePopup.Frame.src=PagePopup.Url; },50);
		}

		this.Frame.style.height	=Math.round(Height)+'px';
		this.Frame.style.top	=-Math.round(Height/2)+'px';

		this.CurTime+=50;

		if(this.CurTime<=this.TimeFade+this.TimeSize)
		{
			clearTimeout(this.Timer);
			setTimeout(function(){ PagePopup.Update(); },50);
		}
	},

	CreateElements:function()
	{
		if(!this.Holder && !this.Back && !this.Front && !this.Frame)
		{
			this.Holder=document.createElement('div');
			this.Holder.style.display	='none';
			this.Holder.style.position	='absolute';
			this.Holder.style.top		=this.Holder.style.left		='0px';
			this.Holder.style.width		=this.Holder.style.height	='100%';
			this.Holder.style.float		='none';
			this.Holder.style.padding	=this.Holder.style.margin=this.Holder.style.border='0px';
			this.Holder.style.zIndex	='1000';

			this.Back=document.createElement('div');
			this.Back.style.position	='absolute';
			this.Back.style.top			=this.Back.style.left	='0px';
			this.Back.style.width		=this.Back.style.height	='100%';
			this.Back.style.float		='none';
			this.Back.style.padding		=this.Back.style.margin=this.Back.style.border='0px';
			this.Back.style.zIndex		='1';
      this.Back.onclick			= function(){ PagePopup.ClosePage(); };

			this.Front=document.createElement('div');
			this.Front.style.position	='absolute';
			this.Front.style.top		=this.Front.style.left	='50%';
			this.Front.style.width		=this.Front.style.height='1px';
			this.Front.style.float		='none';
			this.Front.style.padding	=this.Front.style.margin=this.Front.style.border='0px';
			this.Front.style.zIndex		='2';

			this.Frame=document.createElement('iframe');
			this.Frame.style.position	='absolute';
			this.Frame.style.top		=this.Frame.style.left	='0px';
			this.Frame.style.width		=this.Frame.style.height='1px';
			this.Frame.frameBorder		='0';
			this.Frame.style.float		='none';
			this.Frame.style.padding	=this.Frame.style.margin='0px';
			this.Frame.style.background	='#FFFFFF';

			var TextHolder=document.createElement('div');
				TextHolder.style.position	='absolute';
				TextHolder.style.left		=TextHolder.style.bottom='0px';
				TextHolder.style.width		='18px';
				TextHolder.style.height		='18px';
				TextHolder.style.overflow	='hidden';
				TextHolder.style.border		='1px solid #555555';
				TextHolder.style.margin		='0px';
				TextHolder.style.padding	='0px 0px 0px 2px';
				TextHolder.style.background	='#FFFFFF';
				
			var Text=document.createElement('span');
				Text.style.position		='absolute';
				Text.style.left			=Text.style.bottom='2px';
				Text.style.color		='#555555';
				Text.style.fontFamily	='arial';
				Text.style.fontWeight	='800';
				Text.style.fontSize		='18px';
				Text.style.lineHeight	='11px';
				Text.style.background	='transparent';
				Text.innerHTML			='x';

			this.Close=document.createElement('div');
			this.Close.style.position	='absolute';
			this.Close.style.width		='16px';
			this.Close.style.height		='16px';
			this.Close.style.overflow	='hidden';
			this.Close.style.float		='none';
			this.Close.style.margin		='0px';
			this.Close.style.padding	='0px';
			this.Close.style.background	='#FFFFFF';
			this.Close.style.border		='0px';
			this.Close.style.cursor		='pointer';
			this.Close.onmouseover		=function(){ TextHolder.style.background='#CCCCCC'; };
			this.Close.onmouseout		=function(){ TextHolder.style.background='#FFFFFF'; };
			this.Close.onclick			=function()
			{ 
				PagePopup.CurTime=0;
				PagePopup.Front.style.display='none';
				PagePopup.ClosePage();
			};
			
			//fix for ie6 bug and select tag
			var iFrame = document.createElement('iframe');
			iFrame.className = 'iframe_fix_bug';
			
			this.Holder.appendChild(iFrame);
			//end of fix
	
			TextHolder.appendChild(Text);
			this.Close.appendChild(TextHolder);
			this.Front.appendChild(this.Frame);
			this.Front.appendChild(this.Close);
			this.Holder.appendChild(this.Back);
			this.Holder.appendChild(this.Front);
			document.body.appendChild(this.Holder);
		}
	}
}

