
function toggleTags(tag, show) {
	tag = tag.toUpperCase();
	var flist = document.body.getElementsByTagName(tag);
	for (var x=0, l=flist.length; x<l; ++x) {
		if (!$(flist[x]).hasClassName('view_select_menu'))
		{
			if (show)
				$(flist[x]).show();
			else
				$(flist[x]).hide();
		}
	}
}

function showShadow() {
	var dimensions = $(document.body).getDimensions();
	shadow = $('shadowcontainer');
	if (!shadow) {
		shadow = $(document.createElement("DIV"));
		shadow.id = 'shadowcontainer';
		shadow.setStyle({display: 'none'});
		document.body.appendChild(shadow);
	}
	shadow.setStyle({
		backgroundColor: 'black',
		height: document.documentElement.scrollHeight+'px',
		width: document.documentElement.clientWidth+'px',
		position: 'absolute',
		top: 0,
		left: 0,
		zIndex: 100
	});
	//document.documentElement.clientHeight+'px',
	Event.observe(window, 'resize', shadowResize);
	Event.observe(shadow, 'click', hideShadow);
	if (navigator.platform!='Win32') toggleTags("EMBED", false);
	toggleTags("SELECT", false);
	new Effect.Appear(shadow, {duration: 0.5, from: 0, to: 0.7});
	return shadow;
}

function hideShadow() {
	shadow = $('shadowcontainer');
	new Effect.Fade(shadow, {duration: 0.5, from: 0.7, to: 0, afterFinish: function() {
		if (navigator.platform!='Win32') toggleTags("EMBED", true);
		toggleTags("SELECT", true);
	}});
}

function shadowResize() {
	var dimensions = document.body.getDimensions();
	$('shadowcontainer').setStyle({
		height: dimensions.height+'px',
		width: dimensions.width+'px'
	});
}

function openDiv(idDiv) {
	showShadow();
	var element=$(idDiv);
	Event.observe('shadowcontainer', 'click', function() {closeDiv(idDiv)});
	if (navigator.appVersion.indexOf('MSIE')!=-1) {
		var origWidth = element.getWidth();
		document.body.appendChild(element);
		element.setStyle({width: origWidth});
		if (navigator.appVersion.indexOf('MSIE 6.0')!=-1) {
			element.style.position='absolute';
		}
	}
	centerDiv(idDiv,0);
	element.show();
}

function centerDiv(idDiv, ey) {
	var element=$(idDiv);

	var msieIndex = navigator.appVersion.indexOf('MSIE');
	var msie6Index = navigator.appVersion.indexOf('MSIE 6');

	if (msie6Index==-1)
	{
		element.setStyle({
			position: 'fixed',
			zIndex: 101,
			top: (document.documentElement.clientHeight/2-element.getHeight()/2)+'px',
			left: (document.documentElement.clientWidth/2-element.getWidth()/2)+'px'
		});
	} else {
		element.setStyle({
			position: 'absolute',
			zIndex: 101,
			top: (document.documentElement.clientHeight/2-element.getHeight()/2)+'px',
			left: (document.documentElement.clientWidth/2-element.getWidth()/2)+'px'
		});		
		
	}

	/*if (msieIndex != -1) {
		var msieVersion = parseFloat( navigator.appVersion.substring(msieIndex+5) );
		if (msieVersion < 7) {
			var var_ey=0;
			if (ey>0)
			{
				if (ey<1024) var_ey=document.documentElement.clientHeight/2;
				else var_ey=ey-element.getHeight();
				fixedPosition = 'absolute';
				element.setStyle({
					position: fixedPosition,
					zIndex: 101,
					top: var_ey+'px',
					left: (document.body.offsetWidth/2-element.getWidth()/2)+'px'
				});
			}
		}
	}*/

	Event.observe(window, 'resize', function() { centerDiv(idDiv, ey) });
}

function closeDiv(idDiv) {
	$(idDiv).hide();
	hideShadow();
}