var browserName=navigator.appName;  
window.isIE6 = false;
window.isOpened = false;
if (browserName=="Microsoft Internet Explorer") 
{ 
  var agt=navigator.userAgent.toLowerCase();
  var iePos  = agt.indexOf('msie');
  var browserVer = parseFloat(agt.substring(iePos+5,agt.indexOf(';',iePos)));

  if(browserVer < 7)   window.isIE6=true;
}

function getAvailSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth,myHeight];
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function popupShow(elemId,flvpath,swfpath,libpath,title,desc)
{			
	var arrayPageSize = $$('body')[0].getDimensions();
	var popupHolder = '', popupDesc = '';
	
	$('popup_overlay').setStyle({ width: arrayPageSize.width + 'px', height: arrayPageSize.height + 'px' });
	
	$('popup_window').appendChild(Builder.node('div',{id:'popup_decorCenter'}));
	
	if($(elemId+'_holder') && $(elemId+'_holder').innerHTML != "" && $(elemId+'_desc') && $(elemId+'_desc').innerHTML != "")
	{
		popupHolder = $(elemId+'_holder').innerHTML;
		popupDesc = $(elemId+'_desc').innerHTML;
		$(elemId).update(popupHolder + popupDesc);
		$('popup_decorCenter').update("");
	}
	
	$('popup_decorCenter').appendChild(Builder.node('div',{id:elemId+'_holder'}));
	$('popup_decorCenter').appendChild(Builder.node('ul',{id:elemId+'_desc'}));
	$('popup_decorCenter').appendChild(Builder.node('div',{id:elemId+'_descBottom'}));
	
	$(elemId+'_holder').update(popupHolder);
	$(elemId+'_desc').update(popupDesc);
		
	$(elemId).update("");
	
	positionPopup();
	
	if(isIE6)
	{
		$$('select').each(function(sel){
			if(typeof(sel.up('.popup_wnd')) == 'undefined') sel.style.visibility = 'hidden';
		});
	}
	
	$('popup_overlay').show();
	$('popup_window').show();
	
	var so_s = new SWFObject(swfpath, "flash_sender", "100%", "100%", "9");
	so_s.addParam("quality", "high");
	so_s.addParam("scale", "noscale");
	so_s.addParam("swLiveConnect", "true");
	so_s.addParam("allowFullScreen", "true");
	so_s.addPara,("allowScriptAccess", "always")
	so_s.addParam("wmode", "transparent");
	
	so_s.addVariable("en_flash_lib_path", libpath);
	so_s.addVariable("en_flash_title", title);
	
	so_s.addVariable("en_flash_flvName", escape(flvpath));
	so_s.write(elemId+'_holder');
	
	$(elemId+'_desc').innerHTML = '<li class="header">'+title+'<\/li>'+desc;
	
	window.isOpened = true;
}

function positionPopup()
{
	if(isIE6)
	{
		$('popup_window').style.marginLeft = '-'+$('popup_window').getWidth()/2 + 'px';
		
		if(getAvailSize()[1] < $('popup_window').getHeight())
		{
			$('popup_window').style.position = 'absolute';
			$('popup_window').style.top = getScrollXY()[1] + 'px';
			$('popup_window').style.marginTop = '0px';	
		}
		else
		{
			$('popup_window').style.position = 'absolute';
			$('popup_window').style.top = getScrollXY()[1] + (getAvailSize()[1]/2)- $('popup_window').getHeight()/2 + 'px';
			$('popup_window').style.marginTop = '0px';
		}
		
	}
	else
	{
		$('popup_window').style.marginLeft = '-'+$('popup_window').getWidth()/2 + 'px';
		
		if(getAvailSize()[1] < $('popup_window').getHeight())
		{
			$('popup_window').style.position = 'absolute';
			$('popup_window').style.top = getScrollXY()[1] + 'px';
			$('popup_window').style.marginTop = '0px';
		}
		else
		{
			$('popup_window').style.top = '50%';
			$('popup_window').style.position = 'fixed';
			$('popup_window').style.marginTop = '-'+$('popup_window').getHeight()/2 + 'px';
			
		}
	}
}
function popupClose()
{	
	$('popup_window').update('');
	$('popup_overlay').hide();
	$('popup_window').hide();
	
	window.isOpened = false;
	
	if(isIE6)
	{
		$$('select').each(function(sel){
		   if(typeof(sel.up('.popup_wnd')) == 'undefined') sel.style.visibility = 'visible';
		});
	}
}

function showTab(tabID, obj)
{
	$$('#tab_nav a').each(function(it){
		it.className = '';
	});

	$$('.tabCont').each(function(it){
		it.style.display = 'none';
	});
	
	$(obj).className = 'sel';
	$(tabID).style.display = 'block';
	
	positionPopup();
}


Event.observe(window, 'load', function () {
/*		new Insertion.Bottom(document.body,'<div id="popup_overlay"></div>');
new Insertion.Bottom(document.body,'<div id="popup_window"></div>');*/
document.body.appendChild(Builder.node('div',{id:'popup_overlay'}));
document.body.appendChild(Builder.node('div',{id:'popup_window'}));

$('popup_overlay').setStyle({'position': 'absolute', 'top': '0', 'left': '0', 'zIndex': '998', 'width': '100%', 'height': '100%', 'background': '#000', 'display':'none', 'opacity':'0.55'});

$('popup_window').setStyle({'position':'fixed', 'top':'50%', 'left':'50%', 'zIndex':'999', 'display':'none'});

if(isIE6)
{
	$('popup_window').style.position = 'absolute';

	Event.observe(window, 'scroll', function () {
	if(isOpened && getAvailSize()[1] >= $('popup_window').getHeight()) positionPopup();
  	});
}

Event.observe(window, 'resize', function () {
		positionPopup();
	});

});
