var footer_height = 215;
var main_picture = 1;
var slideshow = null;

/** Aloldalak betöltése **/
function load_page (page, id) {
	switch (page) {
		case "start": var color = "#18597f"; var site = "start"; break;
		case "company": var color = "#2c800c"; var site = "cegbemutato"; break;
		case "service": var color = "#dda017"; var site = "szolgaltatasok"; break;
		case "contact": var color = "#8a0651"; var site = "kapcsolat"; break;
		case "quality": var color = "#1c6e7a"; var site = "minosegiranyitas"; break;
		case "utility": var color = "#616161"; var site = "kozmuterkep"; break;
		case "carrier": var color = "#945600"; var site = "karrier"; break;
		case "reference": var color = "#8cbf02"; var site = "referenciak"; break;
		case "error": default: var color = "#ff2222"; var site = "nem_talalhato"; break;
	}

	$("#wrapper").animate ({ backgroundColor : color }, 1700, "backout");
	$('#content').fadeOut (850, function() {
		$('#menu a').removeClass();
		$('#menu_' + page).addClass ("menu_" + site + "_active");
		$('#content_handler').load ("/content/" + site + ".php", { subjob : id }, function() {
			$('#content').fadeIn (850);
			setTimeout ("resize_content();", 250);

			if (slideshow !== null) clearTimeout (slideshow);
			if (page == "start") {
				main_picture = 1;
				slideshow = setTimeout ("rotate_pictures();", 6000);
			}
			else {
				slideshow = null;
			}
		});
	});
}

/** Tartalmi rész méretezése, középre igazítása **/
function resize_content() {
	var inner_height = $('#content_handler').height();
	var outer_height = $(window).height() - footer_height;

	$('#content').height (outer_height);
	if (inner_height < outer_height)
		$('#content_handler').css ('top', parseInt ((outer_height - inner_height) / 2) + "px");
	else
		$('#content_handler').css ('top', "0px");
}

/** Kezdőoldal **/

function rotate_pictures() {
	$('#main_title_picture_' + main_picture).fadeOut (1200, function() {
		$('#main_title_picture_' + main_picture).hide (0);
		main_picture++;
		if (main_picture > 6) main_picture = 1;
		$('#main_title_picture_' + main_picture).fadeIn (1200);
	});
	slideshow = setTimeout ("rotate_pictures();", 4500);
}

/** Cégbemutató **/
function show_eu_table (show) {
	if (show) {
		$('#eu_table_container').width ($(window).width());
		$('#eu_table_container').height ($(window).height());
		$('#eu_table_container').fadeIn ('slow');
	}
	else {
		$('#eu_table_container').fadeOut ('slow');
	}
}

/** Közműtérkép **/

function send_order() {
	if (($.trim ($('#hsz').val()) == "" && $.trim ($('#szsz').val()) == "") || $.trim ($('#megrendelo').val()) == "") {
		alert ("Kérem töltse ki a megrendelő adatait és a címet vagy szelvényszámot is adja meg!");
	}
	else {
		$('#sender').attr ('disabled', "disabled");
		$('#sender').val ("Kis türelmet..");
		$.post ("/send_order.php", $("#form_order").serialize(), function (data) {
			if (data == 1) {
				alert ("Köszönjük megrendelését!");
				$('#hsz').val ("");
				$('#szsz').val ("");
				$('#meret').val ("");
				$('#formatum').val ("");
				$('#megrendelo').val ("");
			}
			else {
				alert ("Hiba a megrendelés küldése során!");
			}
			$('#sender').val ("Küldés");
			$('#sender').removeAttr ('disabled');
		});
	}
}

function show_utility (x, y, detailed) {
	if (detailed)
		data = { x : x, y : y };
	else if (x > 0 && y > 0)
		data = { mx : x, my : y };
	else
		data = null;
	$('#content_handler').load ("/content/kozmuterkep.php", data, function() {
		setTimeout ("resize_content();", 250);
	});
}

/** Inicializálás betöltéskor **/
$(function() {
	$(window).resize (function() {
		resize_content();
	});

	/** Főmenü elemei **/
	$('#menu_start').click (function() {
		load_page ('start');
		return false;
	});
	$('#menu_company').click (function() {
		load_page ('company');
		return false;
	});
	$('#menu_service').click (function() {
		load_page ('service');
		return false;
	});
	$('#menu_contact').click (function() {
		load_page ('contact');
		return false;
	});
	$('#menu_quality').click (function() {
		load_page ('quality');
		return false;
	});
	$('#menu_utility').click (function() {
		load_page ('utility');
		return false;
	});
	$('#menu_carrier').click (function() {
		load_page ('carrier');
		return false;
	});
	$('#menu_reference').click (function() {
		load_page ('reference');
		return false;
	});

	resize_content();
});

