 function showLayer(id, w, h) {
	var pic = $(id);
	// get the x and y coordinates to center the newsletter panel
	Position.prepare();
	xc = Math.round((document.body.clientWidth/2)-(w/2)) + Position.deltaX;
	yc = Math.round((document.body.clientHeight/2)-(h/2)) + Position.deltaY;
	// show the newsletter panel
	pic.style.left = xc + 'px';
	pic.style.top = yc + 'px';
	grayOut(true, {'zindex':'50', 'bgcolor':'#000000', 'opacity':'50'});
	pic.style.zIndex=100;
	pic.style.display = '';
	return false;
}


 function showPic2(id, w, h) {
	var pic = $('pic'+id);
	// get the x and y coordinates to center the newsletter panel
	Position.prepare();
	xc = Math.round((document.body.clientWidth/2)-(w/2)) + Position.deltaX;
	yc = Math.round((document.body.clientHeight/2)-(h/2)) + Position.deltaY;
	// show the newsletter panel
	pic.style.left = xc + 'px';
	pic.style.top = yc + 'px';
//	alert(Position.deltaX+'px*'+document.body.clientHeight+'px');
	grayOut(true, {'zindex':'50', 'bgcolor':'#000000', 'opacity':'50'});
	pic.style.zIndex=100;
	pic.style.display = '';
	return false;
}

var baloontimeout=false;
function showBaloon(section, id, el) {
	if (baloontimeout) clearTimeout(baloontimeout);	
	baloontimeout=false;
//	$('baloon').style.left=Position.cumulativeOffset(el)[0]+'px';
//	$('baloon').style.top=(Position.cumulativeOffset(el)[1] + 15) +'px';
	$('baloon').style.left=getBounds(el).left+'px';
	$('baloon').style.top=(getBounds(el).top + 15) +'px';
	$('baloon').innerHTML='<table>'+
'<tr><td colspan="2" style="background:url(/img/baloon_top.png) no-repeat 0 0;" class="title">&nbsp;</td></tr>'+
'<tr><td class="baloon_left" style="background:url(/img/baloon_left.png) repeat-y 0 0;"><div style="width:12px;height:1px;"><spacer type="block" width="12" height="1" /></div></td><td class=baloon_cnt><div>'+
'<blink>Загружается...</blink>'+
'<br clear=all>'+
'</div></td></tr>'+
'<tr><td colspan="2" style="background:url(/img/baloon_bottom.png) no-repeat 0 0;" class="baloon_bottom">&nbsp;</td></tr>'+
'</table>';
	$('baloon').style.display = '';
	//new Ajax.Updater('baloon', '/actions/baloon.php?section='+section+'&id='+id);
	makeRequest('/actions/baloon.php?section='+section+'&id='+id, update_baloon);

}

function update_baloon() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			//eval(http_request.responseText);
			$('baloon').innerHTML=http_request.responseText;
		}
	}

}

function update_player() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			//eval(http_request.responseText);
			$('video_info').innerHTML=http_request.responseText;
		}
	}

}

function hideBaloon() {
	baloontimeout=setTimeout("$('baloon').style.display = 'none'", 1000);
}

function grayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';                          
  } else {
     dark.style.display='none';
  }
}

    function makeRequest(page, func) {

        http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        http_request.onreadystatechange = func;
        http_request.open('GET', page, true);
	http_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=windows-1251');
        http_request.send(null);

    }
