popoverShown = false;

function showPopover(url) {
	popoverShown = true;
	
	_.visible('theflash',false);
	_.visible('theflash1',false);
	_.visible('theflash2',false);
	
	_.id('popover_content').src = url;
	var c = _.id('popover_shadow');
	var p = _.id('popover');
	_.opacity(p,0);
	_.opacity(c,0);
	_.size(c,0,0);
	
	resetPopover();
	resizePopover();
	
	_.fadeIn(c,function() {
		_.fadeIn(p,function() {
		},0.2,1,30);
	},0.25,0.75,30);
}

function hidePopover() {
	_.visible('popover_shadow',false);
	_.visible('popover',false);
	popoverShown = false;
	_.visible('theflash',true);
	_.visible('theflash1',true);
	_.visible('theflash2',true);
}

resizePopover = function() {
	if (popoverShown) {
		var w = _.getWindowSize();
		var s = _.getScroll();
		var d = _.getPageSize();
		
		var scrolltop = (document.all)? s.y:0; //add scrolltop to document height for IE
		var h = document.all? Math.max(d.h,w.h) + scrolltop : '100%';
		
		if (window.innerHeight) {
			if (window.innerHeight>Math.max(d.h,w.h)) {
				h = window.innerHeight;
			}
			else {
				h = Math.max(d.h,w.h);
			}
		}
		_.size('popover_shadow', d.w+s.x, h);
	}
}

resetPopover = function() {
	if (popoverShown) {
		var p = _.id('popover');
		var s = _.getScroll();
		//alert('sy='+s.y);
		_.pos(p,0,100+s.y);
		
	}
}

_js.onLoad(function() {
	_.addEvent(_.id('popover_shadow'),'click',function() {
		hidePopover();
	});
	
	// to load a popover asap
	//showPopover('popover1.html');
});

window.onscroll = resetPopover;
window.onresize = resizePopover;