// JavaScript Document
function pageConfig(menuItem) {
	$('#HorizontalMenu').find('a span:empty').closest('li').remove();
	if ($('#NewsArea').length) {
		$('#WaitingImage').hide();
		$('#rss1').show();
		if($('#RandomImages').length) {
			$('#NewsArea').attr('class', 'news-half-width');
		}else {
			$('#NewsArea').attr('class', 'news-full-width');
		}
	}
	$('#mnu' + menuItem).addClass('selected');
	if ($('#FronterMenu').length) {
		fixFrontermenu('y');
	}
}
function displayElements() {
	$('#Flash').show();
	$('#RandomImages').show();
}

function hideElements() {
	$('#Flash').hide();
	$('#RandomImages').hide();	// why on earth is these elements hided when
								// displayIframe is called?!
}

function displayIframe() {
	hideElements();
	$('#NewsArea').hide();
	$('#iframe').removeAttr('class').attr('class', 'normal-iframe');
}

function switchto(q) {
	if (q) {
		$('#passwordtext').hide();
		$('#passwd').show();
		$('#passwd').focus();
	} else {
		$('#passwd').hide();
		$('#passwordtext').show();
	}
}

function fixMenu(menuItem, frontpage) {
	$('#iframe').attr('src', $('#FronterMenu a:first').attr('href'));
	$('#HorizontalMenu').find('a span:empty').closest('li').remove();
	$('#mnu' + menuItem).addClass('selected');
	fixFrontermenu();
}

function fixFrontermenu(frontpage) {
	if (frontpage === 'y') {	
		$('#FronterMenu').find('a').each(function(k,v){
			$(this).attr('href', 'menu/'+$(this).attr('href'));
		});
	}
	if(!$('#NewsArea').is(':visible')){		
		$('#FronterMenu a:first').addClass('selected');
	}
	$('#FronterMenu').find('a').live('click', function(e){
		window.location.hash = 'm-' + $(this).parent().attr('id');
		displayIframe();
		cleanMenu(this);
	});
	
	var locationhash = window.location.hash;
	if (locationhash) {
		locationhash = locationhash.substring(3);
	}
	if (locationhash == 'frontpage_') {
		locationhash = null;
	}
	if(locationhash && $('#'+locationhash).length){
		displayIframe();
		$('#iframe').show().attr('src', $('[id="'+locationhash+'"]').children('a').attr('href'));
		cleanMenu($('[id="'+locationhash+'"]').children('a'));
	}
}

function cleanMenu(selected_menu) {
	$('#FronterMenu').find('.selected').removeClass('selected');
	$(selected_menu).addClass('selected');
}

/* iFrame SSI IV - iframe auto-resize height script
 * ©2008 John Davenport Scheuer
 * This notice must remain for legal use. */

function sizeFrame() {
	if (document.getElementsByTagName('frameset').length || !document.getElementsByTagName('iframe').length) {
		return;
	}
	var frEls = document.getElementsByTagName('iframe'),
	s = 'scrollHeight',
	frObs = window.frames,
	o = 'offsetHeight',
	b = 'body',
	de = 'documentElement';
	for (var cs, hb, hd, d = 'document', i = frEls.length - 1; i > -1; --i) {
		if (frObs[i][d][b].style.overflow) {
			cs = frObs[i][d][b].style.overflow;
		}
		frObs[i][d][b].style.overflow = 'hidden';
		frEls[i].height = 20;
		frEls[i].height = Math.max(frObs[i][d][b][o], Math.max(frObs[i][d][de][o], (hd = frObs[i][d][de][s]) != (hb = frObs[i][d][b][s]) ? Math.max(hd, hb) : 0)) + (frEls[i].height == frEls[i].offsetHeight && frEls[i].getAttribute('frameborder', 0) !== '0' ? 4 : 20);
		if (frEls[i].height < 430) {
			frEls[i].height = 450;
		}
		frObs[i][d][b].style.overflow = typeof cs == 'string' ? cs: '';
	};
	if (!sizeFrame.setup) {
		for (var u = frEls.length - 1; u > -1; --u) {
			sizeFrame.loadup(frEls[u]);
			sizeFrame.setup = true;
		}
	}

};

sizeFrame.loadup = function(o) {
	if (typeof window.addEventListener != "undefined") {
		o.addEventListener("load", sizeFrame, false);
	}
	else if (typeof window.attachEvent != "undefined") {
		o.attachEvent("onload", sizeFrame);
	}
	else {
		if (o.onload !== null) {
			var oldOnload = o.onload;
			o.onload = function(e) {
				oldOnload(e);
				sizeFrame();
			};
		}
		else {
			o.onload = sizeFrame;
		}
	}

};

