var isDOM = (document.getElementById ? true : false); 
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);

function getRef(id) {
	if (isDOM) return parent.document.getElementById(id);
	if (isIE4) return parent.document.all[id];
	if (isNS4) return parent.document.layers[id];
}

function toggleVisibility(code, parentType, layerName) {
	if (!getRef('mm_background_layer_mm')) {
		buildBackgroundLayer(layerName);
	}
	if (!getRef('mm_popup_layer_mm')) {
		buildPopUpLayer(code, parentType, layerName);
	}	
	underLayer = getRef('mm_background_layer_mm');
	overLayer = getRef('mm_popup_layer_mm');
	if (overLayer.style.zIndex == '3') {
		overLayer.style.zIndex = '-1';
		underLayer.style.zIndex = '-1';
		overLayer.style.visibility = 'hidden';
		underLayer.style.visibility = 'hidden';
	} else {
		overLayer.style.zIndex = '3';
		underLayer.style.zIndex = '2';
		overLayer.style.visibility = 'visible';
		underLayer.style.visibility = 'visible';
	}
}

function buildBackgroundLayer(layerName) {
	searchLayer = getRef(layerName);
	backgroundLayer = document.createElement('div');
	backgroundLayer.setAttribute("id", "mm_background_layer_mm");
	backgroundLayer.style.cssText = 'background:url("http://www.rapidimage.net/global_images/trans.gif");visibility:hidden;position:absolute;text-align:left;left:0px;top:0px;width:' + document.body.clientWidth + 'px;height:' + document.body.clientHeight  + 'px;';
	newDiv = searchLayer.parentNode.insertBefore(backgroundLayer,searchLayer);
}


function buildPopUpLayer(code, parentType, layerName) {
	theWidth = 600;
	theHeight = 464;
	searchLayer = getRef(layerName);
	popupLayer = document.createElement('div');
	popupLayer.setAttribute("id", "mm_popup_layer_mm");
	popupLayer.style.cssText = 'height:' + theHeight + 'px;width:' + theWidth + 'px;z-index:-1;border-width:1px;border-style:solid;border-color:#979FA5;text-align:right;visibility:hidden;position:fixed;margin:auto;background-color:white;';
	newDiv = searchLayer.parentNode.insertBefore(popupLayer,searchLayer);
	newDiv.innerHTML = '<input style="right:100%;padding:2px;" type="image" src="http://www.rapidimage.net/global_images/buttons/close_up.gif" name="mm_close_search" id="mm_close_search" value="mm_close_search" onMouseOver="this.src=\'http://www.rapidimage.net/global_images/buttons/close_over.gif\'" onMouseOut="this.src=\'http://www.rapidimage.net/global_images/buttons/close_up.gif\'" onClick="javascript:toggleVisibility(\'TINT\',\'close\',\'mm_search_base_layer1\');" /><br /><iframe src="http://rapid-www/media/_search_controller.php?album_code=' + code + '&parent_type=' + parentType + '&layer_name=' + layerName + '" id="mm_search_box_iframe" name="mm_search_box_iframe" frameborder="0" style="width:' + theWidth + 'px;height:' + (theHeight-14) + 'px;"></iframe>';
	setContentPos();
}

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function getWindowWidth() {
	var windowWidth = 0;
	if (typeof(window.innerWidth) == 'number') {
		windowWidth = window.innerWidth;
	}
	else {
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			if (document.body && document.body.clientWidth) {
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}
		
function setContentPos() {
	if (document.getElementById) {
		var contentElement = document.getElementById('mm_popup_layer_mm');
		var windowHeight = getWindowHeight();
		var windowWidth = getWindowWidth();
		if (windowHeight > 0) {
			var contentHeight = contentElement.offsetHeight;
			if (windowHeight - contentHeight > 0) {
				contentElement.style.position = 'fixed';
				contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + 'px';
			}
			else {
				contentElement.style.position = 'static';
			}
		}
		if (windowWidth > 0) {
			var contentWidth = contentElement.offsetWidth;
			if (windowWidth - contentWidth > 0) {
				contentElement.style.position = 'fixed';
				contentElement.style.left = ((windowWidth / 2) - (contentWidth / 2)) + 'px';
			}
			else {
				contentElement.style.position = 'static';
			}
		}
	}
}

window.onresize = function() {
	if (document.getElementById('mm_popup_layer_mm')) {
		setContentPos();
	}
}

function changeMediaDisplay()
{
document.getElementById("mediaDisplay").style.visibility = "hidden";
}

// enable bottoms
function enableButtoms(id){
	document.getElementById(id).disabled=false;
}

// enable id's
function enableIds(id){
	document.getElementById(id).style.visibility = "visible";
}

// disable id's
function disableIds(id){
	document.getElementById(id).style.visibility = "hidden";
}

// enable id's for display
function enableIdsBydisplay(id){
	document.getElementById(id).style.display = 'block';	
}

// change the class for Thumb Media on event onClick
function changeClassName(idClass,classNormal,idAtual,classVisited){
	document.getElementById(idClass).className=classNormal;
	document.getElementById(idAtual).className=classVisited;
	document.getElementById(0).className=classNormal;
	
// timeout for the class is 6 secounds
	window.setTimeout("changeClassName("+idAtual+",'linkopacityVisited')", 6000);
}
