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 swapDivInline( 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", "inline");
        dojo.style(ediv, "display", "inline");

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


    }
}


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")){
         //this fixes thing for merlot and places where we have rightcolumns
                //var url = window.location.href;
                //console.log(url);
                if(document.getElementById("leftcolumn")){
                        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;
                                }		
                        }
                }
                
	}
         if(document.getElementById("upper")){
         //this fixes things for pkal chrome
                var url = window.location.href;
                if(url.search('/pkal/') != -1){
                        var contentHeight = document.getElementById("upper").offsetHeight;
                        var navHeight = document.getElementById("nav").offsetHeight;
                        if( contentHeight < navHeight+100){
                                var newFooterTopMargin =  navHeight - contentHeight + 160;
                                newFooterTopMargin = newFooterTopMargin + "px";
                                document.getElementById("upper").style.paddingBottom = newFooterTopMargin;
                                if(document.getElementById("footer")){
                                       console.log(newFooterTopMargin);
                                        document.getElementById("footer").style.marginTop = newFooterTopMargin;
                                }		
                        }
                }
	}

	if(document.getElementById("contentsidebar")){
	//for SENCER chrome
		var contentHeight = document.getElementById("contentfeature").offsetHeight;
		var navHeight = document.getElementById("contentsidebar").offsetHeight;
		if( contentHeight < navHeight){
			var newFooterTopMargin =  navHeight - contentHeight;
			newFooterTopMargin = newFooterTopMargin + "px";
			document.getElementById("contentfeature").style.marginBottom = 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);

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

