	

	function tourserverFancyBox()
	{
		this.openFancyBox = function openFancyBox( url, height, width, scrolling, title, topPosition, lastUrl )
		{
			var top         = $(window).scrollTop() + 40;

			if ( title != "" )
			{
				titleFormat = true;
			}
			
			var windowHeight = $(window).height();

			if ( parseFloat( height ) > parseFloat( windowHeight ) )
			{
				$("body").css( "height"     , height );
				$("body").css( "min-height" , height );
				$("body").css( "max-height" , height );
				$("body").css( "overflow"   , "auto" );
				var centerOnScroll = false;
			}
			else
			{
				$("body").css( "height", windowHeight );
				$("body").css( "min-height", windowHeight );
				$("body").css( "max-height", windowHeight );
				$("body").css( "overflow", "hidden" );
				var centerOnScroll = true;
			}
			
			if ( !lastUrl )
			{
				$("body:first").attr( "lastUrl"         , "" );
				$("body:first").attr( "lastScrolling"   , "" );
				$("body:first").attr( "lastWidth"       , "" );
				$("body:first").attr( "lastHeight"      , "" );
				$("body:first").attr( "lastTopPosition" , "" );
			}
			
			$.fancybox(
			{
				'type'               : 'iframe',
				'padding'		     : 4, 
				'margin'		     : 0, 
				'height'		     : height, 
				'width'		         : width, 
				'scrolling'		     : scrolling, 
				'overlayShow'	     : true,
				'overlayColor'	     : "#efefef",
				'overlayOpacity'	 : 0.95,
				'transitionIn'	     : 'none',
				'speedIn'	         : 50,
				'speedOut'	         : 50,
				'centerOnScroll'	 : centerOnScroll,
				'hideOnContentClick' : false,
				'hideOnOverlayClick' : false,
				'showCloseButton'    : true,
				'autoScale'          : false,
				'autoDimension'      : false,
				'showNavArrows'      : true,
				'titleFormat'        : titleFormat,
				'title'              : title,
				'href'               : url,
				'onClosed'           : function()
				{
					$("body").css( "height", "" );
					$("body").css( "min-height", "" );
					$("body").css( "max-height", "" );
					$("body").css( "overflow", "" );
					$("a.backbutton").remove( );
				},
				'onStart'            : function()
				{
					// setPositionOfFancybox( top );
					$("body:first").attr( "lastUrl"         , lastUrl );
					
					if ( !lastUrl )
					{
						$("body:first").attr( "lastScrolling"   , scrolling );
						$("body:first").attr( "lastWidth"       , width );
						$("body:first").attr( "lastHeight"      , height );
						$("body:first").attr( "lastTopPosition" , topPosition );
					}
				},
				'onComplete'         : function()
				{
					// setPositionOfFancybox( top );
					if ( lastUrl )
					{
						myTourserverFancyBox.setHistoryBackButton();
					}
				}
			});
			
			// setPositionOfFancybox( top );
		}	
		
		this.getLastFancyUrl = function getLastFancyUrl(  )
		{
			lastUrl = "";
			
			try
			{
				lastUrl = $("#fancybox-inner iframe:first").attr( "src" );
			}
			catch( e )
			{
				
			}
			
			return lastUrl;
		}
		
		this.openFancyBoxHtml = function openFancyBoxHtml( url, width, closeButton, title, height )
		{
			titleShow = false
			
			if ( closeButton == undefined )
			{
				closeButton = true;
			}
			
			if ( title != undefined )
			{
				titleShow = true;
			}
			
			$.fancybox(
			{
				'content'            : url,
				'type'               : "html",
				'overlayColor'	     : "#efefef",
				'overlayOpacity'	 : 0.95,
				'autoScale'          : false,
				'autoDimensions'     : false,
				'hideOnContentClick' : false,
				'hideOnOverlayClick' : true,
				'showCloseButton'    : true,
				'width'              : width,
				'height'             : height,
				'left'               : 0,
				'titleShow'          : titleShow,
				'titlePosition'      : "inside",
				'title'              : title
			});
		}
		
		this.getIframePosition = function getIframePosition( objOfClick )
		{
			var topPos = 0;
			
			try
			{
				positionsIframe = $(objOfClick).position();
				topPos          = positionsIframe.top;
			}
			catch (e)
			{
				
			}
			
			return topPos;
		}
		
		this.setHistoryBackButton = function setHistoryBackButton()
		{
			$("a.backbutton").remove( );
			button = "<a title='Zur&#252;ck' id='fancybox-left-ico' class='backbutton' href='javascript:'></a>";
			$("body").append( button );
			myTourserverFancyBox.setPositionHistoryBackButton();
			
			$("a.backbutton").click( function() 
			{
				$("a.backbutton").remove( );
				lastUrl     = $("body:first").attr( "lastUrl" );
				
				if ( $("body:first").attr( "lastHeight" ).search( "%" ) == -1 )
				{
					height      = parseFloat( $("body:first").attr( "lastHeight" ) );
				}
				else
				{
					height      = $("body:first").attr( "lastHeight" );
				}
				
				width       = parseFloat( $("body:first").attr( "lastWidth" ) );
				scrolling   = $("body:first").attr( "lastScrolling" );
				topPosition = $("body:first").attr( "lastTopPosition" );
				title       = "";
				
				if ( lastUrl && lastUrl != "null" )
				{
					myTourserverFancyBox.openFancyBox( lastUrl, height, width, scrolling, title, topPosition, "" );
				}
			});
		}
		
		this.setPositionHistoryBackButton = function setPositionHistoryBackButton()
		{
			try
			{
				fancyPos = $("#fancybox-wrap").position();
				pos      = $("a#fancybox-close").position();
				leftPos  = pos.left + fancyPos.left -6;
				topPos   = fancyPos.top + 20;
				
				$("a.backbutton").css( "position", "absolute" );
				$("a.backbutton").css( "top", topPos+"px" );
				$("a.backbutton").css( "left", leftPos+"px" );
				$("a.backbutton").css( "z-index", "100000" );
			}
			catch(e)
			{
				
			}
		}
		
		function setPositionOfFancybox( position )
		{
			positionFancy        = $("#fancybox-wrap").position();
			newMarginTopPosition = -1 * ( positionFancy.top - position );
			$("#fancybox-loading").css( "margin-top", newMarginTopPosition+"px" );
			$("#fancybox-wrap").css( "margin-top", newMarginTopPosition+"px" );
			$("#fancybox-wrap").css( "margin-left", "-10px" );
		}
	}
	
	myTourserverFancyBox = new tourserverFancyBox();
	
	$(document).ready( function() 
	{
		$(window).bind('resize', function()
		{
			var resizeTimer = 0;
			
			if ( resizeTimer )
			{
				clearTimeout(resizeTimer);
			}
			
			resizeTimer = setTimeout( myTourserverFancyBox.setPositionHistoryBackButton, 20 );
		}); 
		
	});	
