dojo.require("dojo.fx"); 	


function swapDiv( divNum, expanding )
{
	cdiv = dojo.byId("c" + divNum);
	ediv = dojo.byId("e" + divNum);
	fdiv = dojo.byId("f" + divNum);
	
    if (expanding)
    {
      
    	dojo.style(cdiv, "display", "none");
    	dojo.style(fdiv, "display", "block");
        dojo.style(ediv, "display", "block");

    }
    else
    {
       dojo.style(fdiv, "display", "none");
       dojo.style(ediv, "display", "none");
       dojo.style(cdiv, "display", "block");


    }
}


function repositionFooter()
{
    if(document.getElementById("nav")){
		var contentHeight = document.getElementById("content").offsetHeight;
		var navHeight = document.getElementById("nav").offsetHeight;
		if( contentHeight < navHeight){
			var newFooterTopMargin =  navHeight - contentHeight + 70;
			newFooterTopMargin = newFooterTopMargin + "px";
			document.getElementById("content").style.marginBottom = newFooterTopMargin;
			if(document.getElementById("footer")){
				document.getElementById("footer").style.marginTop = newFooterTopMargin;
			}
		
		}
	}
	 if(document.getElementById("rightcolumn")){
		var contentHeight = document.getElementById("leftcolumn").offsetHeight;
		var navHeight = document.getElementById("rightcolumn").offsetHeight;
		if( contentHeight < navHeight){
			var newFooterTopMargin =  navHeight - contentHeight + 70;
			newFooterTopMargin = newFooterTopMargin + "px";
			document.getElementById("leftcolumn").style.marginBottom = newFooterTopMargin;
			if(document.getElementById("footer")){
				document.getElementById("footer").style.marginTop = newFooterTopMargin;
			}
		
		}
	}
	
}

//functions for handling collapsed nav menus

				//simple function to collapse/hide menu items marked with the
				//collapse class  --we run it at load
				 function collapseMenu(){
 					dojo.query(".collapse").forEach(
 						function(collapsibleItem){
 				 			dojo.fx.wipeOut({ node: collapsibleItem, duration: 400}).play();
 						}
 					);
 				}
				
				function expandMenu(){
				  //this expands all the collapsed menu items labeled with
				  //the class collapse# where # is the menunumber
				  full_id = this.id;
				  idnumber = full_id.substring(4);
				  var collapselabel = ".collapse" + idnumber;
				  
				  dojo.query(collapselabel).forEach(
				  function(collapsibleItem){
				 			dojo.fx.wipeIn({ node: collapsibleItem ,duration: 300}).play();
						}
					);
				//hide the show text	
				 dojo.style(this, "display", "none");

				}
				
				function hookupNavExpander(){
					//this function hooks up each navExpander to 
					//and expandMenu call for that particular id number
					dojo.query(".navexpander").connect('onclick', expandMenu);

				}

function surveyFlyIn( currentPosition, destPosition, initialPosition ) {
	
	var sessionCookie = readCookie( "sercsurveydone" );
		if ( ! sessionCookie ) {
			var popupsurvey = document.getElementById( "popupsurvey" );
			if ( !currentPosition ) {
				popupsurvey.style.display = "block";
				popupsurvey.style.left = document.body.clientWidth + "px";
				destPosition = document.body.clientWidth - 600;
				currentPosition = initialPosition = document.body.clientWidth;
				surveyFlyIn( currentPosition, destPosition, initialPosition );
			}
			else if ( currentPosition > destPosition ) {
				currentPosition -= 7;
				popupsurvey.style.left = currentPosition + "px";
				popupsurvey.style.width = (initialPosition - currentPosition);
				setTimeout( "surveyFlyIn( " + currentPosition + ", " + destPosition + ", " 
					+ initialPosition + " )", 0 );
			}
		}
		 else{
		 	var popupsurvey = document.getElementById( "popupsurvey" );
		 	popupsurvey.style.display = "none";
		 }
}

function readCookie( name ) {
	var nameEQ = name + "=";
	var ca = document.cookie.split( ';' );
	for( var i = 0; i < ca.length; i++ ) {
		var c = ca[i];
		while ( c.charAt( 0 ) == ' ' ) 
			c = c.substring( 1, c.length );
		if ( c.indexOf( nameEQ ) == 0 ) 
			return c.substring(nameEQ.length,c.length);
	}
	return null;
}

				
				
dojo.addOnLoad(collapseMenu);
dojo.addOnLoad(hookupNavExpander);
dojo.addOnLoad(repositionFooter);
dojo.addOnLoad(surveyFlyIn);

