﻿var CurrentOpenDiv="";
var backdiv;
var popUpDiv;
var noScroll=false;
var scrollPosX=null;
var scrollPosY=null;
var VideoDiv = null;
var thisOpenDiv = null;

function openSection(OpenDiv)
{

	
	
	if(backdiv==null)
	{		
		backdiv=document.createElement("div");
		backdiv.id="backdiv";
		backdiv.style.width="100%";
		backdiv.style.height="100%";
		backdiv.style.position="absolute";
		backdiv.style.zIndex="100";		
		backdiv.style.backgroundImage="url(\"/images/2010/grayoverlay.png\")";
		backdiv.style.backgroundRepeat="repeat";
		//backdiv.style.backgroundColor="transparent";
		backdiv.style.overflow="hidden";
		document.body.appendChild(backdiv);
	}	
	
	
	if(CurrentOpenDiv!="")
	{		
		thisObject=document.getElementById(CurrentOpenDiv);
		thisObject.style.visibility="hidden";
		thisObject.style.display="none";
		backdiv.style.visibility="hidden";
		backdiv.style.display="none";	
		window.onscroll=null;
		window.scrollTo(scrollPosX,scrollPosY);
		noscroll=false;
		
			
	}
	
	if(OpenDiv!=CurrentOpenDiv)
	{	
		
		getScrollPosition();
		//window.scrollTo(0,0);
		noScroll=true;
		
		window.onscroll = scrollStop;
//		window.setEvent("onscroll",scrollStop);
		
		thisObject=document.getElementById(OpenDiv);
		positionContent(thisObject);
		thisObject.style.visibility="";
		thisObject.style.display="";
		CurrentOpenDiv=OpenDiv;
		backdiv.style.visibility="";
		backdiv.style.display="";
		backdiv.onclick = function(){openSection(OpenDiv);};
		
		backdiv.style.top= (scrollPosY-1)+"px";
		backdiv.style.left="-1px";
		
	}
	else
	{
		CurrentOpenDiv="";
	}
}


function openVideo(EmbedCode)
{
	//alert(CurrentOpenDiv);
	
	if(VideoDiv==null)
	{
		//alert("initializing Videowrap");
		VideoDiv = document.getElementById("VideoContainer");
		thisOpenDiv= "VideoWrap";
		document.body.appendChild(document.getElementById("VideoWrap"));
	}
	
	if(CurrentOpenDiv!="")
	{
		
		if(VideoDiv!=null)
		{
			VideoDiv.innerHTML="closed";
		}
		//closeVidDescription(document.getElementById("moreInfoPopup"));
	}
	else
	{
		var replaceltEmbed = EmbedCode.replace(/&lt;/g,"<");
		var replaceltEmbed = replaceltEmbed.replace(/&gt;/g,">");
		var replaceltEmbed = replaceltEmbed.replace(/&quot;/g,"\"");
		var replaceltEmbed = replaceltEmbed.replace(/&amp;/g,"&");
		//alert(replaceedEmbed);
		VideoDiv.innerHTML=replaceltEmbed;
		//alert(VideoDiv.innerHTML);
	}
	
	openSection(thisOpenDiv);		
	backdiv.onclick = function(){openVideo(thisOpenDiv);};
	
}


function scrollStop()
{
if(noScroll)
	{
		window.scrollTo(scrollPosX,scrollPosY);	
	}
	
	if(CurrentOpenDiv=="")
	{
		noScroll=false;
	}
	
}

function getScrollPosition()
{
	scrollPosY = f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
	


	scrollPosX = f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
	
	//return thisX + "," + thisY;
}



function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function positionContent(thisframe)
{
	//var viewNewsBox = document.getElementById("ViewNews_" + thisUID);
	//alert(thisframe.id);
	thisframe.style.top = scrollPosY+(parseInt(returnWindowHeight())/2);
	thisframe.style.left = scrollPosX+(parseInt(returnWindowWidth())/2);
}

function returnWindowWidth()
{
	var theWidth;
	if (window.innerWidth)
	 	theWidth=window.innerWidth;
	else if (document.documentElement && document.documentElement.clientWidth)
		 theWidth=document.documentElement.clientWidth;
	else if (document.body)
	 	theWidth=document.body.clientWidth;
	return theWidth;
}

function returnWindowHeight()
{
	var theHeight;
	if (window.innerHeight)
	 	theHeight=window.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight)
		 theHeight=document.documentElement.clientHeight;
	else if (document.body)
		 theHeight=document.body.clientHeight;
	return theHeight;
}

