$(document).ready(function() {
	jQuery.ajaxSetup({ beforeSend: function(xhr) { xhr.setRequestHeader("AJAX", "true"); } });

	gMaps.init();

	Search.init();

	$(document).resize(function() { setSize(); });

	$('#page_content').css('visibility', 'visible');
	cross('logoMap').onmouseover = function() { $('#logoMain').css('opacity', .85).toggleClass('mouse'); };
	cross('logoMap').onmouseout = function() { $('#logoMain').css('opacity', 1).toggleClass('mouse'); };

	menuInit();
	IdealA();
});


$(window).load(function() {
	jBasic();

	if (p != 1) $("div.pHeadWrapper div.pHead").animate({ marginTop: 5 }, 500);

	switch (p) {
		case 1:
			waitStart = window.setTimeout("startFx();", 250);
			break;

		case 3:
			eventsInit();
			break;
			
		case 16:
			fedBoxSize();
			break;

		default:
			break;
	}

});

function jBasic() {
	_lastClass = "";											
	_fedFlags = $("#fedFlags img");								
	_flagsHidden = false;										

	_fedFlags.css({ opacity: .75 });

	_fedFlags.each(function() {
		$(this).click(function() { $(this).animate({ opacity: 0.25 }, 150); });
		$(this).hover(
			function() {
				if (!_flagsHidden) {
					_flagsHidden = true;
					_fedFlags.stop().animate({ opacity: .25 }, 350);
				}
				$(this).stop().animate({ opacity: 1 }, 100);
			},
			function() { $(this).animate({ opacity: .25 }, 50); }
		);
	});

	$("#fedFlags").hover(
		function() { _fedFlags.stop().animate({ opacity: .25 }, 500); _flagsHidden = true; },
		function() { _fedFlags.stop().animate({ opacity: .75 }, 150); }
	);

	//$("table.cal td.H").each(function() { calEvent(this) });
	//$("table.cal td.E").each(function() { calEvent(this) });
}



function startFx() {
	if (window.waitStart) clearTimeout(waitStart);

	$("#feedBox div.content").cycle({
		fx:				"scrollHorz",
		slideExpr:		"div",
		next:			"#feedPrev",
		prev:			"#feedNext",
		delay:			-1500,
		speed:			450,
		timeout:		5000,
		pause:			true
	});
}

function fedBoxSize() {
	if ($("div.NT").is(":visible")) {
		var maxHeight = 0;
		var T = $("div.NTh");
		var C = $("div.ECh");
		var N = $("div.NPh");

		if (T.height() > maxHeight) maxHeight = T.height();
		if (C.height() > maxHeight) maxHeight = C.height();
		if (N.height() > maxHeight) maxHeight = N.height();

		T.height(maxHeight);
		C.height(maxHeight);
		N.height(maxHeight);
	}
}
