


function popup( url, title)
{
	var width = 800;
	var height = 660;
	var left = ( screen.width - width ) / 2;
	var top = ( screen.height - height ) / 2;
	var optionsSup = "menubar=no, status=no, scrollbars=no, resizable=no";
	var options = 'width=' + width + 'px, height=' + height + 'px,  top=' + top + ', left=' + left + ', ' + optionsSup;
	document.open( url, title, options );
}

function videoPopup(video,thumbDiv)
{
	var dim  = getPageSize();
	var dim2  = getViewSize();
	var left = parseInt((dim2[0] - 800)/2);
	
	var scroll = getScrollXY();
	
	var top = scroll[1]; 
	$("overlay").setStyle({width: dim[0], height: dim[1]});
	$("videoBox").clonePosition(thumbDiv);
	
	$('innoagendaFlashBanner').style.visibility = 'hidden';	
	
	new Effect.Appear($("overlay"), { duration: 0.2, from: 0.0, to: 0.8,
		afterFinish: function () {
			
	
			new Effect.Appear($("videoBox"), { duration: 0.3, from: 0.0, to: 1,
				afterFinish: function () {
					new Effect.Morph('videoBox', {
					style: {
							width: '800px',
							height: '620px',
							top: top+'px',
							left: left+'px'
						}, // CSS Properties
						duration: 0.8, // Core Effect properties
						afterFinish: function () {
							var html = "<div id='closeVideoBox' onclick='closeBox()'><div class='closeVideoBox2'></div></div><iframe frameborder='0' src='videoMp4.php?video="+video+"' class='videoiframe'></iframe>";
							$("videoBox").update(html);
						}
					});
				}
			});
		}
	});

	Event.observe(window, 'resize', resizeWindow);
}

function imagePopup(image,thumbDiv)
{
	var url = "inc/getImageSize.php";
	new Ajax.Request(url, {
		method: 'post',
		parameters: {image: image},
		onSuccess: function(transport) {
			var output = transport.responseText.evalJSON();
			var imageWidth = output.width;
			var imageHeight = output.height+20;
			imagePopupWH(image,thumbDiv,imageWidth,imageHeight)
		}
	});

}

function imagePopupWH(image,thumbDiv,width,height)
{
	var dim  = getPageSize();
	var dim2  = getViewSize();
	var left = parseInt((dim2[0] - width)/2);
	var top = (dim2[1] > 650)?20:0;

	var scroll = getScrollXY();
	//alert(scroll[0]+" "+scroll[1]);
	
	top = scroll[1];
	
	$("overlay").setStyle({width: dim[0], height: dim[1]});
	$("videoBox").clonePosition(thumbDiv);
	
	$('innoagendaFlashBanner').style.visibility = 'hidden';
	
	 new Effect.Appear($("overlay"), { duration: 0.2, from: 0.0, to: 0.8,
		afterFinish: function () {
			new Effect.Appear($("videoBox"), { duration: 0.3, from: 0.0, to: 1,
				afterFinish: function () {
					new Effect.Morph('videoBox', {
					style: {
							width: width+'px',
							height: height+'px',
							top: top+'px',
							left: left+'px'
						}, // CSS Properties
						duration: 0.8, // Core Effect properties
						afterFinish: function () {
							var html = "<div id='closeVideoBox' onclick='closeBox()'><div class='closeVideoBox2'></div></div><img src='"+image+"' onclick='closeBox()' />";
							$("videoBox").update(html);
						}
					});
				}
			});
		}
	});

	Event.observe(window, 'resize', resizeWindow);
}

function closeBox() {
		Event.stopObserving(window, 'resize', resizeWindow);
		$("videoBox").update("");
		new Effect.Fade($("videoBox"),{
			duration: 0.5,
			afterFinish: function() {
				$("videoBox").hide();			
				new Effect.Fade($("overlay"), { 
					duration: 0.5,
					afterFinish: function () {
						$('innoagendaFlashBanner').style.visibility = 'visible';	
					}
				});
			}
		});
		
}

function resizeWindow() {
	var dim  = getPageSize();
	var dim2  = getViewSize();
	$("overlay").setStyle({width: dim[0], height: dim[1]});
	var left = parseInt((dim2[0] - 800)/2);
	var top = 20;
	//if (Prototype.Browser.IE) top += 150;
	$("videoBox").setStyle({left: left, top: top});
	
}

function getPageSize() {
	        
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	}
	
	function getViewSize() {
		if (document.body)
		{
			var width = document.body.clientWidth;
			var height = document.body.clientHeight;
		}
		else
		{
			var width = window.innerWidth;
			var height = window.innerHeight;
		}
		return [width,height];
	}
	
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 ];
}




document.observe("dom:loaded", function() {
  $('main').insert('<div id="overlay" style="display: none"></div>');
	$('main').insert('<div id="videoBox" style="display: none"></div>');
});




