/*
 * Fading - Iframe Script > 2007.08.22 © Karácsony Máté
 * Version 0.1a
 * Based on prototype.js and moo.fx libraries
 */

	Event.observe(window, 'load', fadingiframe_initialize);
	
	function fadingiframe_initialize()
	{
		ReklamShop.FadingIframe.initialize();
	}

	if(Prototype.Browser.IE)
	{
		if (/MSIE ([0-9]{1,}[\.0-9]{0,})/.exec(navigator.userAgent) != null)
		Prototype.Browser.IEVersion = parseFloat(RegExp.$1);
	}
	
	var ReklamShop = {};
	ReklamShop.FadingIframe = {};
	ReklamShop.FadingIframe.initialize = function()
	{
		this.html = $(document.getElementsByTagName('html').item(0));
		this.body = $(document.getElementsByTagName('body').item(0));
		
		this.plane = $(document.createElement('div'));
		this.plane.setAttribute('id', 'fadingIframe_plane');
		this.plane.hide();
		this.body.appendChild(this.plane);
		
		this.horizon = $(document.createElement('div'));
		this.horizon.setAttribute('id', 'fadingIframe_horizon');
		this.body.appendChild(this.horizon);
	};
	
	ReklamShop.FadingIframe.show = function(url, frameWidth, frameHeight)
	{
		this.body.scrollTo();
		
		if(Prototype.Browser.IE)
		{
			this.body.unselectable = 'on';
			
			if(Prototype.Browser.IEVersion < 7)
			{
				$A(document.getElementsByTagName('select')).each(function(s){$(s).setStyle({visibility: 'hidden'});});
				this.body.setStyle({overflow: 'hidden'});
			}
		}
		
		plane_effect_complete = planeEffectComplete.bind(this);
		plane_effect = new Fx.Style('fadingIframe_plane', 'opacity', {duration: 700, transition: Fx.Transitions.quadOut, onComplete: plane_effect_complete}).set(0);
		this.plane.show();
		
		function planeEffectComplete()
		{		
			if($('fadingIframe_frame') == null)
			{
				this.iframe = $(document.createElement('iframe'));
				this.iframe.setAttribute('id', 'fadingIframe_frame');
			}
			else
			{
				this.iframe = $('fadingIframe_frame');
			}
			this.iframe.src = '';
			if(Prototype.Browser.IE)
			{
				this.iframe.frameBorder = 0;
			}
			this.iframe.setStyle({height: '2%', width: '2%'});
			this.iframe.hide();
			this.horizon.appendChild(this.iframe);
			
			var iframe_effect_1_complete = iframeEffect1Complete.bind(this);
			iframe_effect_1 = new Fx.Style('fadingIframe_frame', 'opacity', {duration: 700, transition: Fx.Transitions.expoOut, onComplete: iframe_effect_1_complete}).set(0);
			this.iframe.show();
			this.horizon.show();
			
			function iframeEffect1Complete()
			{
				iframe_effect_2_complete = iframeEffect2Complete.bind(this);
				iframe_effect_2 = new Fx.Style('fadingIframe_frame', 'height', {duration: 700, transition: Fx.Transitions.expoOut, onComplete: iframe_effect_2_complete});
				iframe_effect_2_margin = new Fx.Style('fadingIframe_frame', 'margin-top', {duration: 700, transition: Fx.Transitions.expoOut});
				iframe_effect_2_margin.start(0, - (frameHeight || this.plane.getHeight() * .96) / 2);
				
				function iframeEffect2Complete()
				{
					this.html.setStyle({overflow: 'hidden'});
				
					iframe_effect_3_complete = iframeEffect3Complete.bind(this);
					iframe_effect_3 = new Fx.Style('fadingIframe_frame', 'width', {duration: 700, transition: Fx.Transitions.expoOut, onComplete: iframe_effect_3_complete});
					iframe_effect_3_margin = new Fx.Style('fadingIframe_frame', 'margin-left', {duration: 700, transition: Fx.Transitions.expoOut});
					iframe_effect_3_margin.start(0, - (frameWidth || this.plane.getWidth() * .98) / 2);
					
					function iframeEffect3Complete()
					{
						this.iframe.setStyle({overflow: 'auto'});
						this.iframe.src = url;
						
						this.plane.innerHTML = '<a style="color: #FFFFFF; text-decoration: none;" href="#" onclick="javascript: ReklamShop.FadingIframe.hide(); return false;" title="Bezárás"><img src="images/closeButton.png" alt="bezárás" /><span>&copy;2007 Karácsony Máté</span></a>';
						
						opened_iframe = $(document.getElementsByTagName('iframe').item(0));
						
						if (opened_iframe.src == 'http://coolcollection.hu/')
						{
							this.plane.innerHTML = '<a style="color: #FFFFFF; text-decoration: none;" href="#" onclick="javascript: ReklamShop.FadingIframe.hide(); return false;" title="Bezárás">Felhasználónév: ahu100 - Jelszó: 36100 <img src="images/closeButton.png" alt="bezárás" /><span>&copy;2007 Karácsony Máté</span></a>';
						}
						
						if(!(Prototype.Browser.IE && Prototype.Browser.IEVersion < 7))
						{
							this.plane.setStyle({position: 'fixed'});
							this.horizon.setStyle({position: 'fixed'});
						}
					}
					iframe_effect_3.start(this.iframe.getWidth(), frameWidth || this.plane.getWidth() * .98);
				}
				iframe_effect_2.start(this.iframe.getHeight(), frameHeight || this.plane.getHeight() * .96);
			}
			iframe_effect_1.start(0, 1);
		}
		plane_effect.start(0, .8);
		
	};
	
	ReklamShop.FadingIframe.hide = function()
	{
		this.iframe.setStyle({overflow: 'hidden'});
		this.iframe.src = '';
		
		this.plane.innerHTML = '';
		
		var iframe_effect_1_complete = iframeEffect1Complete.bind(this);
		iframe_effect_1 = new Fx.Style('fadingIframe_frame', 'width', {duration: 700, transition: Fx.Transitions.expoOut, onComplete: iframe_effect_1_complete});
		iframe_effect_1_margin = new Fx.Style('fadingIframe_frame', 'margin-left', {duration: 700, transition: Fx.Transitions.expoOut});
		iframe_effect_1_margin.start(this.iframe.getStyle('margin-left'), 0);
		
		function iframeEffect1Complete()
		{
			this.html.setStyle({overflow: 'auto'});

			var iframe_effect_2_complete = iframeEffect2Complete.bind(this);
			iframe_effect_2 = new Fx.Style('fadingIframe_frame', 'height', {duration: 700, transition: Fx.Transitions.expoOut, onComplete: iframe_effect_2_complete});
			iframe_effect_2_margin = new Fx.Style('fadingIframe_frame', 'margin-top', {duration: 700, transition: Fx.Transitions.expoOut});
			iframe_effect_2_margin.start(this.iframe.getStyle('margin-top'), 0);
			
			function iframeEffect2Complete()
			{
				var iframe_effect_3_complete = iframeEffect3Complete.bind(this);
				iframe_effect_3 = new Fx.Style('fadingIframe_frame', 'opacity', {duration: 700, transition: Fx.Transitions.expoOut, onComplete: iframe_effect_3_complete}).set(1);
				
				function iframeEffect3Complete()
				{
					this.iframe.hide();
					this.horizon.hide();
					
					var plane_effect_complete = planeEffectComplete.bind(this);
					plane_effect = new Fx.Style('fadingIframe_plane', 'opacity', {duration: 700, transition: Fx.Transitions.expoOut, onComplete: plane_effect_complete});
					
					function planeEffectComplete()
					{
						this.plane.hide();

                        if(Prototype.Browser.IE)
                		{
	    	            	this.body.unselectable = 'off';

            		    	if(Prototype.Browser.IEVersion < 7)
    		            	{
            	    			this.body.setStyle({overflow: 'auto', width: this.body.getWidth(), height: this.plane.getHeight()});
		                	}
                		}

						$A(document.getElementsByTagName('select')).each(function(s){$(s).setStyle({visibility: 'visible'});});
					}
					plane_effect.start(parseFloat(this.plane.getStyle('opacity')), 0);
				}
				iframe_effect_3.start(1, 0);
			}
			iframe_effect_2.start(this.iframe.getHeight(), this.plane.getHeight() * .02);
		}
		iframe_effect_1.start(this.iframe.getWidth(), this.plane.getWidth() * .02);
		
		this.body.scrollTo();
	};