// William & Mary Template
// Common utility scripts

// USER NAV
// Dropdown Script - adapted from Suckerfish
// http://www.htmldog.com/articles/suckerfish/dropdowns/ 
		
	set_user_nav_dropdown = function() {
	       		var target_element = document.getElementById("user-nav-dropdown-wrapper");
		
		// set mouseover events
		
		target_element.onmouseover=function() {  
			this.className+=" sfhover";
			}
			
		target_element.onmouseout=function() { 

			this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); 
			}
			
	}
		
	// attach dropdown event to window onload (only works in IE)
	
	if (window.attachEvent) window.attachEvent("onload", set_user_nav_dropdown);
        window.onload = set_user_nav_dropdown;
	
// PRIMARY NAV, ADMISSION NAV, ETC.
// Image Rollover Script

	function set_rollover(img_element, normal_filename, rollover_filename) {
	
		// preload image ?				
		
		// set mouseover event
		
     	img_element.onmouseover = function() { this.src=rollover_filename; }
        img_element.onmouseout = function() { this.src=normal_filename; }		
		
	}
	
// HOMEPAGE IMPACT WIDGET

	function show_hide_module(module_id) {
		var target_element = document.getElementById(module_id);

		if (target_element.style.display=="block") {
			target_element.style.display = "none";
		}
		else {
			target_element.style.display = "block";		
		}
	
		return false;
	
	}	


        // Used on the W&M Blog and Student Blog index pages.
        // Assumption: 
        //  - there is a div on the calling page named orderedContainer where the sorted divs will be moved

        function divIdSort(classtosort) {
		    var allDivs = document.getElementsByTagName("div");
		    var len = allDivs.length;
		    var sortDivArray = new Array();
                    var y = 0;
		    for(var x=0;x<len;x++){
			    if(allDivs[x].className == classtosort) {
				    // append to my class array
				    sortDivArray[y] = allDivs[x].id;
                                    y++;
			    }
		    }

		    sortDivArray.sort();
                    sortDivArray.reverse();
		    var len = sortDivArray.length;
                    var newlocation = document.getElementById("orderedContainer");
		    if (newlocation){
                            for(var x=0;x<len;x++){
			            var el = document.getElementById(sortDivArray[x]);
			            newlocation.appendChild(el);
		            }
                    }
        } 


