﻿panelID=new String();
panelCnt=0;
currXYIncrement=0;
pHeight=0;
pWidth=0;

 function createPanel(modalParam,w,h,objF,modalType,maskDensity){

    pHeight=h;
    pWidth=w;
 	panelCnt++;

	panelID="panel"+panelCnt;
	splitCoords=getCenterCoords(2).split("|");
 	var newPanel=document.createElement('div');
	newPanel.className="panel_element";
	newPanel.id=panelID;
	newPanel.style.height="auto";//h+"px";
	newPanel.style.width=w+"px";
	newPanel.style.position="absolute";
	newPanel.style.display="block";
	newPanel.style.overflow="auto";
	
	document.body.appendChild(newPanel);	
	
	if(modalType == "events")
	{
	    getEventsContent(modalParam,"events",panelID,0,1);
	}
	if(modalType == "potd")
	{
	    getPOTDContent(modalParam,"potd",panelID,0,1,w);
	}
	if(modalType == "introVideo")
	{
	    getIntroVideoContent(modalParam,"introVideo",panelID,0,1,w);
	}
	if(modalType=="largeFeaturedVideo")
	{
	    //getFV(modalParam,"largeFeaturedVideo",panelID,0,null,w);
	    newPanel.style.overflow="visible";
	
	    newPanel.style.height=h+"px";
	    newPanel.innerHTML="<table cellspacing='0' border='0' width='100%'><tr><td background='/theSite/resources/images/modal/top_left.png' width='6' height='6'></td><td background='/theSite/resources/images/modal/top_mid.png' height='6'></td><td background='/theSite/resources/images/modal/top_right.png' width='6' height='6'></td></tr><tr><td background='/theSite/resources/images/modal/left_mid.png' width='6'>&nbsp;</td><td background='/theSite/resources/images/modal/bg.png'><table background='/theSite/resources/images/modal/bg.png' class='modal_header' width='100%' border='0' cellpadding='0'><tr><td align='left'><b> </b></td><td align='right'><a href=javascript:closePanel('" + newPanel.id + "') title='close'><img src='/theSite/resources/images/modal/closer_x.png' border='0'></a></</td></tr></table><div id='modal_content_container_"+newPanel.id+"' class='panel_element_container'><div id='content_potd_modal_data' style='height:"+h+"px;'>"+modalParam+"</div></div></td><td background='/theSite/resources/images/modal/right_mid.png' width='6'>&nbsp;</td></tr><tr><td background='/theSite/resources/images/modal/btm_left.png' width='6' height='6'></td><td background='/theSite/resources/images/modal/btm_mid.png' height='6'></td><td background='/theSite/resources/images/modal/btm_right.png' width='6' height='6'></td></tr></table>";
	}

	objF.cl(panelID);
	objF.se("mask");
	if(document.all || document.getElementById){
	    objF.co("mask",maskDensity);
	}
 }
 
 function closePanel(pid)
 {
		document.getElementById(pid).style.display="none";
		document.getElementById('mask').style.display="none";
 }
  function closeIntroVideoPanel(pid)
 {
    	document.getElementById(pid).innerHTML="";
		document.getElementById(pid).style.display="none";
		document.getElementById('mask').style.display="none";
 }
 
 
 function load(url,modalID)
 {
    currMod=new String("modal_load_indicator_"+modalID);
    document.getElementById(currMod).style.display="";
    document.getElementById(currMod).innerHTML="<img src='resources/images/modal/radial_prog.gif'>&nbsp;loading...";
    window.location=url;
 }
 
  function getCenterCoords(retType){
 	sW=screen.width;
	sH=screen.height;
	sW=document.body.clientWidth;
	sH=document.body.clientHeight;
	switch(retType){
	case 0:
		return sW;
	break;
	case 1:
		return sH;
	break;
	case 2:
		//return sW+"|"+sH;
		return (sW+currXYIncrement)+"|"+(sH+currXYIncrement);
	break;
	}
 }
 
 function modalResize()
 {
	if(panelID != "")
	{
		splitCoords=getCenterCoords(2).split("|");
		document.getElementById(panelID).top=((splitCoords[1]/2)-(pHeight/2))+"px";
		document.getElementById(panelID).left=((splitCoords[0]/2)-(pWidth/2))+"px";

	}
 }
 
 function OnWindowResize()
{
	if(panelID != "")
	{
	// we only need to move the dialog based on scroll position if
	//   we're using a browser that doesn't support position: fixed, like < IE 7
	var left = window.XMLHttpRequest == null ? document.documentElement.scrollLeft : 0;
	var top = window.XMLHttpRequest == null ? document.documentElement.scrollTop : 0;
	var div = document.getElementById(panelID);
	
	div.style.left = Math.max(((GetWindowWidth() - div.offsetWidth) / 2), 0) + 'px';
	div.style.top = Math.max(((GetWindowHeight() - div.offsetHeight) / 2), 0) + 'px';
	}
}

function OnWindowScroll()
{
    alert("test");
}

function GetWindowWidth()
{
	var width =
		document.documentElement && document.documentElement.clientWidth ||
		document.body && document.body.clientWidth ||
		document.body && document.body.parentNode && document.body.parentNode.clientWidth ||
		0;
	return width;
}

function GetWindowHeight()
{
    var height =
    
		document.documentElement && document.documentElement.clientHeight+document.documentElement.scrollTop ||
		document.body && document.body.clientHeight+document.body.scrollTop ||
  		document.body && document.body.parentNode && document.body.parentNode.clientHeight+document.body.parentNode.scrollTop ||
  		
  		0;
  	return height;
}
 
 //FAC

function fac(){

this.drwbx=drawBox;
this.gobx=goBox;
this.cl=cenLay;
this.co=changeOpacity;
this.se=showElement;
this.he=hideElement;
this.sep=setElementPosition;
this.cb=cancelBox;
this.to=toObject;
this.ie6=(navigator.appVersion.indexOf("MSIE 6")>=0);
this.ie7=(navigator.appVersion.indexOf("MSIE 7")>=0);
this.opera=(navigator.appName=="Opera");


	function drawBox(){
		strout=new String();
			strout+='<TABLE id="'+this.boxName+'" BORDER=0 CELLPADDING=0 CELLSPACING=0 style="position:absolute;font-weight:bold;width:'+this.boxWidth+';height:'+this.boxHeight+';display:none;filter:alpha(opacity=100);-moz-opacity:1;font-size:10px">';
			strout+='<TR>';
			strout+='<TD background="img/fac/overLay_01.gif" WIDTH=16 HEIGHT=16>&nbsp;</TD>';
			strout+='<TD background="img/fac/overLay_02.gif" HEIGHT=16>&nbsp;</TD>';
			strout+='<TD background="img/fac/overLay_03.gif" WIDTH=15 HEIGHT=16>&nbsp;</TD>';
			strout+='</TR>';
			strout+='<TR>';
			strout+='<TD background="img/fac/overLay_04.gif" WIDTH=16>&nbsp;</TD>';
			strout+='<TD valign="top" bgcolor="#ffffff" align="center">';
			strout+='<div id="'+this.boxName+'_content" style="background-color:#ffffff;padding:20px;" class="facContent">';
			strout+= this.boxContent;
			strout+='</div>';
			strout+='</TD>';
			strout+='<TD background="img/fac/overLay_06.gif" WIDTH=15>&nbsp;</TD>';
			strout+='</TR>';
			strout+='<TR>';
			strout+='<TD background="img/fac/overLay_07.gif" WIDTH=16 HEIGHT=16>&nbsp;</TD>';
			strout+='<TD background="img/fac/overLay_08.gif" HEIGHT=16>&nbsp;</TD>';
			strout+='<TD background="img/fac/overLay_09.gif" WIDTH=15 HEIGHT=16>&nbsp;</TD>';
			strout+='</TR>';
			strout+='</TABLE>';
			
		if(!this.dynamic){
			document.write(strout);
		}else{
			toObject(this.dynoContainer).innerHTML=strout;
		}
		
	}
	function goBox(){
	 	this.co(this.boxName,100);
		this.co('mask',this.maskDensity);
			if(this.dynoContainer){
				this.to(this.dynoContainer).style.width=this.boxWidth;
				this.to(this.dynoContainer).style.height=this.boxHeight;
				this.se(this.dynoContainer);
				this.sep(this.dynoContainer);
			}else{
				this.sep(this.boxName);
			}
		this.se(this.boxName);
		this.se('mask');
	
	}
	function setElementPosition(e){
		this.cl(e);
	}
	function cancelBox(){
	 	this.co('mask',0);
	 	this.to('mask').style.display="none";
		if(this.dynoContainer){
		this.he(this.dynoContainer);
		}else{
	 	this.he(this.boxName);
		}
	}
	function showElement(e){
		this.to(e).style.display="";
	}
	function hideElement(e){
		this.to(e).style.display="none";
	}
	function changeOpacity(e,v){
		if(document.all){
			this.to(e).filters.alpha.opacity=v;
		}
		if(!document.all && document.getElementById){
			this.to(e).style.MozOpacity=v/100;
		}
		if(this.opera){
		this.to(e).style.opacity=v/100;
		}
	}
	function toObject(e){
		eoID=new String(e);
		return document.getElementById(eoID);
	}
	function cenLay(l){ 

		var maskWidth,maskHeight;
		var thelayerw,thelayerh,thelayer;
		var newleft,newtop,scrTop;
	    var h,w,st; 

		maskWidth=0;
		maskHeight=0;
		
		thelayerw=0;
		thelayerh=0;
		thelayer=0;
		
		newtop=0;
		newleft=0;
		scrTop=0;
		
		h=0; 
	    w=0; 
		st=0;
		
	    if(document.compatMode == "CSS1Compat"){ 
	        //IE Standard mode 
	       w=document.body.parentNode.scrollWidth; 
	       h=(document.body.parentNode.scrollHeight<document.body.parentNode.clientHeight)?document.body.parentNode.clientHeight:document.body.parentNode.scrollHeight; 
		   st=document.body.parentNode.scrollTop;
		   
		   
	    }else{ 
	        //IE Quirks Mode 
	       w=document.body.scrollWidth; 
	       h=(document.body.scrollHeight<document.body.clientHeight)?document.body.clientHeight:document.body.scrollHeight; 
		   st=document.body.scrollTop;
		   
	    } 
	    if(w==0){ 
	        //Netscape 
	        w = window.innerWidth; 
	        h = window.innerHeight; 
			st=document.body.scrollTop;
	    } 

//alert(w+"-"+h+"-"+st);

		thelayer=this.to(l);
		
	    thelayerw = parseInt(thelayer.style.width);
		thelayerh = parseInt(thelayer.style.height);
		
		maskWidth=(thelayerw>w)?thelayerw:w;
		maskHeight=(thelayerh>h)?thelayerh:h;

	    //newleft= ((w/2)-(thelayerw/2)); 
	    //newtop= ((h/2)-(thelayerh/2));
	    
	    newleft= ((w/2)-(thelayerw/2)); 
	    newtop= st+125; //(((h-st)/2)-(thelayerh/2));
		
		newleft=(newleft <= 0)?0:newleft;
		newtop=(newtop <= 0)?0:newtop;
		
		//if(parseInt(this.boxYOffset)>0){
		//newtop=((thelayerh+st)<h)?(st+parseInt(this.boxYOffset)):newtop;
		//}

		thelayer.style.left=newleft+"px";
		thelayer.style.top=parseInt(newtop)+"px";
		
		this.to("mask").style.width=maskWidth+"px";
		this.to("mask").style.height=maskHeight+"px";

	}

}

		var objFac=new fac();
		window.onresize = OnWindowResize;
		