Animator.start = function() {
	switch (Animator.state++) {
	case 1:
		$("#textMargareta").css("top", -100).css("left", 0);
		$("#textKerteszetiTarsasag").css("left",
			$("#contentFrame").position().left + $("#contentFrame").width() );
			
		$("#innerFrameRolunk").hide();
		$("#innerFrameElerhetoseg").hide();
		
		$("body").css("background-color", "#4e0e0a");
		
		$("#loadingCover").fadeOut(2000, Animator.start );
		break;
	case 2:
		try {
			getMovie("SoundPlayer").soundPlay("feltoltes/_hangok/fooldal.mp3");
		} catch (err) { Logger.log("Flash not functioning:" + err.message); }
		function animateText(name) {
			$(name).animate({
				top: Animator.get(name).top * Animator.resizeRatio,
				left: Animator.get(name).left * Animator.resizeRatio
				}, 3000, Animator.start);
		}
		animateText("#textMargareta");
		animateText("#textKerteszetiTarsasag");
		break;
	case 4:
		$("#inner").animate({
			top: -($("#innerText").height())
			}, 3000, function () {
				$("#innerText").hide();
				$("#inner").css("top", 0);
				Animator.start();
			});
			
		break;
	case 5:
		function runBackgroundUp() {
			$("#backgroundRunning").animate({
				top: -( $("#backgroundRunning").height()
						-$("#backgroundRunningFrame").height() )
			}, 15000, "linear", runBackgroundDown);
		}
		function runBackgroundDown() {
			$("#backgroundRunning").animate({
				top: 0
			}, 15000, "linear", runBackgroundUp);
		}
		runBackgroundUp();
		break;
	}
};
	
Animator.stop = function() {
	switch(--Animator.state) {
	case 1:
		$("#loadingCover")
			.stop(false, false)
			.fadeIn(0);
		break;
	case 2:
	case 3:
		$("#textMargareta").stop().css("top", 0);
		$("#textKerteszetiTarsasag").stop().css("left",
			$("#contentFrame").position().left + $("#contentFrame").width());
		break;
	case 4:
		$("#inner").stop().css("top", 0);
		break;
	case 5:
		$("#backgroundRunning").stop().stop().stop();
		break;
	}
};

Animator.afterResize = function () {
	$("#backgroundCenter").css(
		"top",
		$("#backgroundUpper").height() + $("#backgroundUpper").position().top - 1
	);
};

var currentContent = "#innerFrame";

window.onload = function startPage() {
	// Define default content size
	Animator.setContent("#contentBorder")

	// Set some default CSS property easier than in HTML
	$("#backgroundRunningFrame").width( Animator.originalContent.width );
	$("#backgroundRunningFrame").height( 192-46 );
	
	// Add resizable objects to Animator
	
	Animator.add("#contentBorder", true);
	Animator.add("#contentFrame");
	Animator.add("#backgroundRunningFrame");
	Animator.add("#backgroundUpper");
	Animator.add("#backgroundCenter");
	Animator.add("#buttonRolunk");
	Animator.add("#buttonElerhetoseg");
	Animator.add("#buttonFooldal");
	Animator.add("#innerFrame");
	Animator.add("#innerFrameRolunk");
	Animator.add("#innerFrameElerhetoseg");


	Animator.add("#backgroundRunning");

	Animator.add("#iconAruda");
	Animator.add("#iconViragbolt");
	Animator.add("#iconEskuvo");
	Animator.add("#iconKertepites");

	Animator.add("#iconArudaText");
	Animator.add("#iconViragboltText");
	Animator.add("#iconEskuvoText");
	Animator.add("#iconKertepitesText");

	Animator.add("#iconArudaBackground");
	Animator.add("#iconViragboltBackground");
	Animator.add("#iconEskuvoBackground");
	Animator.add("#iconKertepitesBackground");

	Animator.add("#elerhetosegTextBlock");
	Animator.add("#inner");

	
	Animator.add("#textMargareta");
	Animator.add("#textKerteszetiTarsasag");

	// Set up GUI behaviour
	
	$("#buttonRolunk").click( function() {
		if ( currentContent != "#innerFrameRolunk") {
			$("#innerFrameRolunk").fadeIn(2000);
			$(currentContent).fadeOut(2000);
			currentContent = "#innerFrameRolunk";
		}
	});
	
	$("#buttonElerhetoseg").click( function() {
		if ( currentContent != "#innerFrameElerhetoseg") {
			$("#innerFrameElerhetoseg").fadeIn(2000);
			$(currentContent).fadeOut(2000);
			currentContent = "#innerFrameElerhetoseg";
		}
	});

	$("#buttonFooldal").click( function() {
		if ( currentContent != "#innerFrame") {
			$("#innerFrame").fadeIn(2000);
			$(currentContent).fadeOut(2000);
			currentContent = "#innerFrame";
		}
	});
	
	$("#gpsButtonKerteszet").hover(
		function (evt) {
			// store the button's position and size
			var top = parseInt($("#gpsButtonKerteszet").offset().top);
			var left = parseInt($("#gpsButtonKerteszet").offset().left);
			var width = parseInt($("#gpsButtonKerteszet").width());
			var height = parseInt($("#gpsButtonKerteszet").height());
			
			var popupString =
				"<div id=\"gpsFrameKerteszet\" style=\"" +
				"position: absolute; " +
				"z-index: 1000;" +
				"top: " + (top + height) + "px; " +
				"left: " + left + "px; " +
				//"width: 300px; " +
				//"height: 100px; " +
				"font-size: 12px; " +
				"background-color: brown; " +
				"\">" +
				"GPS kordináták:<br />" + 
				"szélesség (&phi;) 47°4´47.74´´= 47.0799275<br />" +
				"hosszúság (&lambda;) 17°54´54.23´´= 17.9150641<br />" +
				"</div>";
			$(popupString).appendTo( $("body") );
		},
		function (evt) {
			$("#gpsFrameKerteszet").remove();
		});
	
	$("#gpsButtonViraguzlet").hover(
		function (evt) {
			// store the button's position and size
			var top = parseInt($("#gpsButtonViraguzlet").offset().top);
			var left = parseInt($("#gpsButtonViraguzlet").offset().left);
			var width = parseInt($("#gpsButtonViraguzlet").width());
			var height = parseInt($("#gpsButtonViraguzlet").height());
			
			var popupString =
				"<div id=\"gpsFrameViraguzlet\" style=\"" +
				"position: absolute; " +
				"z-index: 1000;" +
				"top: " + (top + height) + "px; " +
				"left: " + left + "px; " +
				//"width: 300px; " +
				//"height: 100px; " +
				"font-size: 12px; " +
				"background-color: brown; " +
				"\">" +
				"GPS kordináták:<br />" + 
				"szélesség (&phi;) 47°4´52.16´´= 47.0811549<br />" +
				"hosszúság (&lambda;) 17°54´26.23´´= 17.9072857<br />" +
				"</div>";
			$(popupString).appendTo( $("body") );
		},
		function (evt) {
			$("#gpsFrameViraguzlet").remove();
		});

	$(".leaveSite").click( function() {
		$(":animated").stop();
	});
	
	function resizeOuterBackground() {
		pic_w = 1034;
		pic_h = 623;
		
		win_w = $(window).width();
		win_h = $(window).height();

		style = Animator.calculateFrameStyleForContent( win_w, win_h, pic_w, pic_h);
		$("#outerBackground").css("top", style.top);
		$("#outerBackground").css("left", style.left);
		$("#outerBackground").css("width", style.width);
		$("#outerBackground").css("height", style.height);
		
		$("#windowFrame").css("width", win_w + "px");
		$("#windowFrame").css("height", win_h + "px");
		
		Logger.log("outerBackground resized: win_w, win_h = " + win_w + ", " + win_h);
	};
	resizeOuterBackground();
	var resizeTimer = null;
	$(window).bind('resize', function() {
		if (resizeTimer) {
			clearTimeout(resizeTimer);
		}
		resizeTimer = setTimeout(resizeOuterBackground, 500);
	});
	
	//$('<div style="z-index: 999; background-color: blue;" ' +
	//	'<iframe width="640" height="480" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" ' +
	//		'src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=Veszpr%C3%A9m,+Botev+Street,+Hungary&amp;sll=47.079867,17.908104&amp;sspn=0.008271,0.01929&amp;ie=UTF8&amp;hq=&amp;hnear=8200+Veszpr%C3%A9m,+Botev+utca,+Hungary&amp;ll=47.079884,17.908144&amp;spn=0.028055,0.054932&amp;z=14&amp;iwloc=A&amp;output=embed"> ' +
	//	'</iframe></div>').appendTo( $("body") );
	
	if ($.support.opacity == true) {
		Animator.mouseInOutFader( "#buttonRolunk", 0.5 );
		Animator.mouseInOutFader( "#buttonElerhetoseg", 0.5 );
		Animator.mouseInOutFader( "#buttonFooldal", 0.5 );
	}

	Animator.mouseInOutFader( "#iconArudaText", 0.4, 0.6, "#iconArudaBackground" );
	Animator.mouseInOutFader( "#iconViragboltText", 0.4, 0.6, "#iconViragboltBackground" );
	Animator.mouseInOutFader( "#iconEskuvoText", 0.4, 0.6, "#iconEskuvoBackground" );
	Animator.mouseInOutFader( "#iconKertepitesText", 0.4, 0.6, "#iconKertepitesBackground" );
	
	Animator.start();
};

