function callPopup(_url){
	openAjaxLayer(_url);
	deactivateContent("block")	
	checkHeight()
	return false;
}
function openSystemLayer(_type){
	var _layer = $('ajax_layer');
	_layer.className = "fixed";
	_layer.style.display = "block";

	var so = new SWFObject("../_resources/swf/system/"+_type+".swf", "io-link-ms", "900", "312", "8", "#cccccc");
	so.addParam("wmode", "transparent");
	so.write("ajax_layer_content");
//	deactivateAll("block")
	
	
	//checkHeight()
	
}


function openVideo(_url){

	var _layer = $('ajax_layer');
	_layer.className = "";
	_layer.style.display = "block";	
	$('ajax_layer').style.width = "340px";
	$('ajax_layer').style.height = "260px";

	
	// FLASH
	var so = new SWFObject(RESOURCES_PATH + "swf/VideoPanelPlayer.swf", "ccrfid-de", "320", "240", "8", "#cccccc");
	so.addVariable("width", "320")
	so.addVariable("height", "240")
	so.addVariable("flv_path", _url)
	
	so.addParam("allowFullScreen", "true")
	so.write("ajax_layer_content");
	
	
	deactivateContent("block");	
	//checkHeight()	
}

function deactivateContent(hide){
	var deact_all = $("deactivate");
	var pageSize = getPageHeight()
		yScroll = pageSize.pageHeight
	deact_all.style.height = yScroll +"px";
	if(hide=="block") deact_all.style.display = "block"	
	

	deact_all.style.zIndex = arguments[1] ? arguments[1] : 100;
	deact_all.onclick = closeAjaxLayer
}

function getPageHeight(){
	var scrollX,scrollY,windowX,windowY,pageX,pageY;
		if (window.innerHeight && window.scrollMaxY) {	
			scrollX = document.body.scrollWidth;
			scrollY = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			scrollX = document.body.scrollWidth;
			scrollY = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			scrollX = document.body.offsetWidth;
			scrollY = document.body.offsetHeight;
		}
		
		if (self.innerHeight) {	// all except Explorer
			windowX = self.innerWidth;
			windowY = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowX = document.documentElement.clientWidth;
			windowY = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowX = document.body.clientWidth;
			windowY = document.body.clientHeight;
		}	
		
		pageY = (scrollY < windowY) ? windowY : scrollY; // for small pages with total height less then height of the viewport
		pageX = (scrollX < windowX) ? windowX : scrollX; // for small pages with total width less then width of the viewport
	
		return {pageWidth:pageX,pageHeight:pageY,winWidth:windowX,winHeight:windowY};
	}

function gehtHeight(elem){
	if (window.innerHeight) {
    return window.innerHeight;
  } else if (document.body && document.body.offsetHeight) {
    return document.body.offsetHeight;
  } else {
    return 0;
  }

}
function setDeactSize(){
	var deact_all = $("deactivate");
	var pageSize = getPageHeight()
		yScroll = pageSize.pageHeight
	deact_all.style.height = yScroll +"px";
}
function activateContent(){
	$('deactivate').style.display = "none";
}
function openAjaxLayer(_url){
	var _layer = $('ajax_layer');
	_layer.className += " load";
	_layer.style.display = "block";
	$('ajax_layer_content').style.visibility = "hidden";
	var _ajax = new Ajax.Request(_url, {method:'post', parameters:"",
		onComplete:function(elem){
		
			$('ajax_layer_content').innerHTML = elem.responseText;
			_layer.className = ""
			
			$('ajax_layer_content').style.visibility = "visible";
			checkHeight()
			window.onresize ()
		}	
	});
}

function closeAjaxLayer(){
	activateContent()
	var _layer = $('ajax_layer');
	_layer.className = "load";
	_layer.style.display = "none";
}
function checkHeight(){
	var win_h = gehtHeight()
	var _layer = $('ajax_layer')
	var _elem_h = _layer.offsetHeight
	if(win_h<1000){
		_layer.className = "wide"
		_layer.style.width = "920px";
		_layer.style.marginLeft = "-450px";
	}else{
		_layer.style.width = "448px";
		_layer.style.marginLeft = "-234px";

		_layer.className = _layer.className.replace(/wide/, "")
	}
	var _top = (win_h-_elem_h)/2
	//$('debug').value = win_h+"+"+_elem_h;
	// CENTER IT
	if(_top<85) _top = 85;
	_layer.style.top = _top+"px";
	
	
	//$('ajax_layer').className = $('ajax_layer').className+" wide"; 
}

window.onresize = function (){
	checkHeight()
	setDeactSize()
}


