
var clientWidth=0;
var clientHeight=0;
var tileViewer;
var leftNav;
var currentLeft=0;
var currentTop=0;
var currentPageIndex = 0;


//two column vs. one column view - if you do this through zoom, you won't need this variable
var viewType='default';
	
function ResizedNewspaper(e)
{
    if (navigator.userAgent.indexOf("Firefox") >= 0)
    {
	    var hashVal = window.location.hash;
	    hashVal = hashVal.replace("#", "");
	    var newLoc = window.location.href;
	    newLoc = newLoc.replace("&refresh=true", "");
    	
	    var hashIndex = newLoc.indexOf("#");	
	    newLoc = newLoc.substr(0,hashIndex-1);
	    newLoc = newLoc + "&refresh=true#" + hashVal;
	    window.location.href = newLoc;
	}
	else
	{
	    window.location.reload();
	}
}

function ResizedColumn(e)
{

	positionColumn();
}


function ResizedSmart(e)
{

	positionSmartControls();
}
	
function positionNewspaper()
{
    fitSinglePageZoom = 2;
    fitWidthZoom = 1;
    fitHeightZoom = 0;
    minZoom = 0;
	getWindowSize();
	
	//load mouseovers here when page loads
	//MM_preloadImages('images/icon_font_minus_on.gif', 'images/icon_font_plus_on.gif', 'images/icon_view_default_on.gif', 'images/icon_view_full_on.gif', 'images/icon_tooltip_on.gif', 'images/icon_prev_on.gif', 'images/icon_next_on.gif', 'images/icon_thumb_minus_on.gif', 'images/icon_thumb_plus_on.gif', 'images/icon_zoomout_on.gif', 'images/icon_zoomin_on.gif', 'images/icon_save_on.gif', 'images/icon_print_on.gif', 'images/icon_prevb_on.gif', 'images/icon_nextb_on.gif');

	/* get various objects on the page for resizing and manipulation*/ 

	//this is the left column, containing thumbs and headlines
	leftNav=document.getElementById('leftNavContainer');
	
	//this is the div containing the previous and next buttons at the top of the newspaper page
	prevNext=document.getElementById('prevNextDivTop');
	//prevNext.style.visibility = 'hidden';

	//this is the full newspaper pane, including nav and surrounding graphics
	paperPane=document.getElementById('mainPaneContainer');
	
	//this is the newspaper viewing window 
	tileViewer=document.getElementById('tileSetContainer');
	
	/*this is the div containing the tile images - it is the full size of the newspaper page, but is partially hidden depending on the size of its container  */
	tileDiv=document.getElementById('tileSet');

	//size all objects to fit at default zoom level
	sizeAll(0);

	//set initial variables so that it is possible to scroll divs
	initiateScroll();		
}

function sizeAll(zoomChange)
{
    //figure out the sizes of the different page areas based on browser window size and view
	setView();
		
	//zoom the tileset
	//zoom(zoomChange);				
}
		

	
//set width of the body in the results and content pages
function positionColumn()
{
	//figure out exact dimensions of browser window
	getWindowSize();
	setFont(0);
	sizeTopNav();
	document.getElementById('topBar').style.top="10px";
	document.getElementById('contentBody').style.top="5px";
	document.getElementById('topBar').style.display='block';
	//load mouseovers here when page loads
	MM_preloadImages('images/icon_font_minus_on.gif', 'images/icon_font_plus_on.gif',  'images/icon_tooltip_on.gif',  'images/icon_prevb_on.gif', 'images/icon_nextb_on.gif');
	
	//size to a maximum width for readability
	if (clientWidth>700)
	{
    	document.getElementById('contentBody').style.width='700px';
	}
	else
	{
		document.getElementById('contentBody').style.width='100%';
	}	
	
	document.getElementById('topBar').style.visibility = "visible";
	document.getElementById('contentBody').style.visibility = "visible";
	document.getElementById("topNavContainer").style.visibility = "visible";
	document.getElementById("bottomBar").style.visibility = "visible";
}
	
		
//set width of login window - it's a fixed width
function positionLogin()	
{
    if (document.getElementById('LEcontentBody') != null)
    {
	    document.getElementById('LEcontentBody').style.width='350px';
        document.getElementById('LEcontentBody').style.visibility = "visible";	
    }
	document.getElementById('usernameInput').focus();	
}	

//set width of login window - it's a fixed width
function positionPassword()	
{	
	document.getElementById('LEcontentBody').style.width='350px';
    document.getElementById('LEcontentBody').style.visibility = "visible";	
    document.getElementById('passwordPane').style.width='350px';
    if (document.getElementById('changePwordLabel') != null)
    {
        document.getElementById('changePwordLabel').style.width='350px';
    }

}	
	
function positionSmartControls()
{
    getWindowSize();	
	document.getElementById('LEcontentBody').style.width='100%';	
	document.getElementById('LEcontentBody').style.visibility = "visible";
	
	var tileViewer=document.getElementById('tileSetContainer');
    var paperPane = document.getElementById("mainPaneContainer");
    var smartDiv = document.getElementById("smartPlayerDiv");
    var smartContent = document.getElementById("smartContent");
    var smartMsgDiv = document.getElementById("smartMsgDiv");    
    
	var horizMargin=20;   
	var topHeight=35;	 

    //smartMsgDiv.style.width = clientWidth - horizMargin + "px";
    //smartMsgDiv.style.height = clientHeight - topHeight + "px";
    smartContent.style.width = clientWidth - horizMargin + "px";
    smartContent.style.height = clientHeight - topHeight + "px";
    
    paperPane.style.height = parseInt(smartContent.style.height) - 80 + "px";
    paperPane.style.width = parseInt(smartContent.style.width) - 20 + "px";    
    
	paperPane.style.top='20px';
	paperPane.style.left='0px';  
    
	paperPane.style.visibility = "visible";
	paperPane.style.display='inline';
	
	var viewerVDiff=65;		
	var viewerHDiff=10;

	tileViewer.style.height=(parseInt(paperPane.style.height)-viewerVDiff)+'px';
	tileViewer.style.width=(parseInt(paperPane.style.width)-viewerHDiff)+'px';	
  
    var statusDiv = document.getElementById("statusDiv");
    statusDiv.style.width = parseInt(smartContent.style.width) - 20 + "px";
    statusDiv.style.height = parseInt(smartContent.style.height) - 30 + "px";

    var sessionsReportDiv = document.getElementById("sessionsReport");
    sessionsReportDiv.style.width = parseInt(smartContent.style.width) - 40 + "px";
    sessionsReportDiv.style.height = parseInt(smartContent.style.height) - 100 + "px";

    var usersReportDiv = document.getElementById("usersReport");
    usersReportDiv.style.width = parseInt(smartContent.style.width) - 40 + "px";
    usersReportDiv.style.height = parseInt(smartContent.style.height) - 120 + "px";
    
    var articlesReportDiv = document.getElementById("articlesReport");
    articlesReportDiv.style.width = parseInt(smartContent.style.width) - 40 + "px";
    articlesReportDiv.style.height = parseInt(smartContent.style.height) - 60 + "px";  
    
    // Check for admin tabs to set -- to retain tab after postback
    var tabName = document.getElementById("aspAdminState").value;
    if (tabName != "")
    {
        switchAdminView(tabName);
    }

}
		

	
//switches view from default to full page and back
function switchView(view)
{
    maxZoom = 0;
    minZoom = 0;
    fitHeightZoom = 0;
    fitWidthZoom = 1;
    document.getElementById("viewType").value = view;
	viewType=view;
	//this actually keeps the same zoom level


	if (viewType != 'default')
	{
	    leftNav.style.display='none';
	    //tileViewer.style.float='none';		
	}

	setView();	
	initiateScroll();	
	//tileDiv.style.left = "0px";
	//currentLeft = 0;
    //setDefaultZoomLevel();
    PagePane.setViewType(view, view_callback);
}

function view_callback()
{
    //doNothing();
    return null;
}
	

function setView()
{
	// top nav sizing
	// var topHeight=25;	//the height of top bar (sections nav)
	var topHeight=35;	// ... adjust for showing down arrow at bottom
	var pubLogoHeight = document.getElementById("pubLogo").height;
	var pubLogoWidth = document.getElementById("pubLogo").width;
	var topBar = document.getElementById("topBar");
	var sectionListContainer = document.getElementById("sectionListContainer");
    topBar.style.width = (clientWidth - pubLogoWidth - 75) + "px";	
    sectionListContainer.style.width = parseInt(topBar.style.width)-35 + "px";	
    document.getElementById("toolbarIconsDiv").style.width = (clientWidth-214) + "px";	    

	var leftNavInitWidth=205;

	// dojo split container	
	var dojoSplitDiv = dojo.widget.byId("dojoSplitDiv");


	//paper pane sizing
	dojoSplitDiv.children[1].sizeMin = clientWidth-leftNavInitWidth-5; // mininum paper pane size  
	dojoSplitDiv.children[1].sizeActual = dojoSplitDiv.children[1].sizeMin;
    
    var viewerHDiff=33;	
	paperPane.style.width = dojoSplitDiv.children[1].sizeActual - 3 + "px"; 
	tileViewer.style.width=(dojoSplitDiv.children[1].sizeActual - viewerHDiff)+'px';
	
	if (clientHeight>500)
	{
		paperPane.style.height=(clientHeight-topHeight)+'px';	
	}
	else
	{
		paperPane.style.height='500px';	
	}

	// adjust tile viewable area
	var viewerVDiff=40;
	if (navigator.userAgent.indexOf("MSIE") >= 0)
	{
	    viewerVDiff=45;		
	}
	tileViewer.style.height=(parseInt(paperPane.style.height)-viewerVDiff)+'px';	




	//left nav sizing	
	dojoSplitDiv.children[0].sizeMin = 10; // minimum left nav size - set this to 20 so that the sliding bar is still accessible	
	dojoSplitDiv.children[0].sizeActual = leftNavInitWidth;
	
	var leftNavContent = document.getElementById("leftNavContent");
    var leftNavContentContainer = document.getElementById("leftNavContentContainer");
    var leftNavTabs = document.getElementById("leftNavTabs");
    var scrollDownDiv = document.getElementById("scrollLeftPaneDown");
    
	leftNav.style.height = parseInt(paperPane.style.height) - topHeight + "px"; 
	leftNav.style.top = "0px";
    leftNav.style.width=leftNavInitWidth+'px';

    leftNavContent.style.width = leftNav.style.width;
    leftNavContent.style.top = "25px";
	leftNavContentContainer.style.width = leftNav.style.width;	
	leftNavContentContainer.style.top = "25px";
    leftNavContentContainer.style.height = parseInt(leftNav.style.height) - parseInt(leftNavContentContainer.style.top) - 22 + "px";	
	document.getElementById("searchHeader").style.height = "50px";
	
    // line up the calendar with the arrow by finding the top,left position of the arrow in relation to the page.
    var calendarDown = document.getElementById("calendarDown");
    var topPos = findPosY(calendarDown);    
    var leftPos = findPosX(calendarDown);    
    var calendarDiv = document.getElementById("calendarDiv");
    calendarDiv.style.top = topPos + 4 + "px";
    calendarDiv.style.left = leftPos + 6 + "px";

	

    //Safari
    if (navigator.userAgent.indexOf("Safari") >= 0)
    {
        leftNav.style.top = parseInt(leftNav.style.top) + 5 + "px";	
        //leftNav.style.marginTop = "-2px";
        //paperPane.style.width=parseInt(bluePaneRoom-15)+'px';	
		//paperPane.style.marginTop = "-5px";   
	    scrollDownDiv.style.top = parseInt(leftNav.style.top) + parseInt(leftNav.style.height) - 22 + "px";	
	    document.getElementById("pagePaneToolsDivRight").style.marginTop = "0px";  
	    document.getElementById("searchDetails").style.top = "35px";
    }
    //Netscape
    else if (navigator.appName=='Netscape')
    {
        leftNav.style.top = parseInt(leftNav.style.top) + 5 + "px";	
		paperPane.style.marginTop = "-3px";   
	    scrollDownDiv.style.top = parseInt(leftNav.style.top) + parseInt(leftNav.style.height) - 20 + "px";	
	    document.getElementById("pagePaneToolsDivRight").style.marginTop = "-23px";	
    }
    //Firefox
    else if (navigator.userAgent.indexOf("Firefox") >= 0)
    {
        document.getElementById("searchDetails").style.top = "25px";
    }
    //IE
    else
    {
        leftNav.style.marginTop = "0px";
		//paperPane.style.width=(bluePaneRoom-5)+'px';	
		//paperPane.style.marginTop = "2px";
	    scrollDownDiv.style.top = parseInt(leftNav.style.top) + parseInt(leftNav.style.height) - 21 + "px";	
	    document.getElementById("horizontalRightArrow").style.marginTop = "-16px";	
	    document.getElementById("horizontalRightArrow").style.marginLeft = "10px";
	    document.getElementById("horizontalScrollbarBottomContainer").style.marginLeft = "-4px";  
	    document.getElementById("horizontalScroll").style.marginTop = "2px";  
	    document.getElementById("searchDetails").style.top = "5px";
    }



    

    // display both panes
 	leftNav.style.display='inline';
	paperPane.style.display='inline'; 

}
	
function resizeTileViewer()
{
    var dojoRightPane = document.getElementById("dojoRightPane");
    var viewerHDiff=33;	
    document.getElementById('mainPaneContainer').style.width = dojoRightPane.offsetWidth - 3 + "px";
    document.getElementById('tileSetContainer').style.width=(dojoRightPane.offsetWidth - viewerHDiff) + "px";
    initiateScroll();
}	


// determine the size of the browser window - cross/browser
function getWindowSize() {
	  if (typeof( window.innerWidth ) == 'number' ) 
	  {
		    //Non-IE
	        clientWidth = window.innerWidth;
	        clientHeight = window.innerHeight;
	  } 
	  else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) 
      {
            //IE 6+ in 'standards compliant mode'
            clientWidth = document.documentElement.clientWidth;
            clientHeight = document.documentElement.clientHeight-12;
	  } 
	  else if (document.body && (document.body.clientWidth || document.body.clientHeight)) 
	  {
	    //IE 4 compatible
	    clientWidth = document.body.clientWidth;
	    clientHeight = document.body.clientHeight;
	  }
}



