function ajax_load(url, id, callback, payload) {
    var elem=$(id);
    elem.select('script.onunload').each(function(e) { eval(e.innerHTML); });
    new Ajax.Request(url, {
	    method: payload ? 'post' : 'get',
		postBody: payload,
		evalJS: false,
		onSuccess: function(xr) {
		elem.innerHTML=xr.responseText;
// 		new Effect.Highlight(elem, {
// 			startcolor: '#FFFFFF', 
// 			    endcolor: '#FFEECC', 
// 			    duration: dispatcher.effectspeed
// 			    });
		//hack for IE6 for Sidebar
		if (xr.responseText.indexOf('id="run_script"')>0){
			setTimeout("eval($('run_script').innerHTML);",1000);
		}

		elem.select('script.onload').each(function(e) {eval(e.innerHTML);});
		if (callback) callback(elem);
	    },
		onFailure: function (xr) {
		elem.innerHTML=xmlhttp.responseText;
		elem.style.background='#FF0000';
	    }
    });
}


var mariinsky=false;

function draw_window(id,classname,width) {
    tubiestop=true;
	toggleAll('div.embed_video');
	toggleAll('div.bigpic');
	toggleAll('div.tubie-killer');
    //no shadow for mariinsky
    if (mariinsky==false)
    {
	var shadow = document.createElement('div');
    shadow.id = 'SHADOW';
    document.body.appendChild(shadow);
    shadow.className = 'black-opaque';
    shadow.style.height=String(getRealTop(document.getElementById('bottom_anchor')))+'px';//Here we need full document height
    Event.observe(shadow, 'click', close_window);
    }
    var win = document.createElement('div');
    document.body.appendChild(win);
    win.className = classname;
    win.id = id;
    //Always center window
    if (!(width)){
		width=304;
    }
    win.style.left=String(Math.floor((Number(document.getElementById('body').style.width)-width)/2))+'px';
    var scroll_dist=window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
    win.style.top=String(scroll_dist)+'px';//String(Math.floor((Number(document.getElementById('body').style.height)-304)/2))+'px';
    //Event.observe(win, 'click', do_nothing);
//    document.body.style.overflow='hidden';
    return win;
}

function do_nothing(e) {
    e.stop();
}

function close_window(e) {
    tubiestop = false;
    if (mariinsky==false){
    $('SHADOW').remove();
    }
    $('white-window').remove();
	//show flash
	toggleAll('div.embed_video');
	toggleAll('div.bigpic');
	toggleAll('div.tubie-killer');
    //document.body.style.overflow='auto';
}

function getRealTop(elem) {	
	yPos = elem.offsetTop;
	tempEl = elem.offsetParent;
	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return yPos;
}

/*
 Hide Big Pic for stories with Video
*/
function toggleAll(names)
{
	var items = $$(names);
	for (var i=0;i<items.length;i++)
	{
		items[i].toggle();
	}
}


