// sets up the show/hide functionality for the request information links on the featured page
document.observe("dom:loaded", function()
{
    // get all the div's we're going to show and hide

    var elements = $$("div.campusPopUp");

    elements.each(function(obj, index) {
    	var button = obj.previous();
	    button.observe('click', function(event) {
	        Event.stop(event);
	        obj.toggle();
	        // below makes the popup float
            try {
            	obj.absolutize();
            } catch(error) {
                // This is a Prototype IE exception bug dealing with _originalHeight
            }
	    });
    });

    // Related Campuses (View All Campuses)
    var relatedCampusElemenets = $$('.relatedCampusLink');
    relatedCampusElemenets.each(function(object, index) {
        // hidden div after "view all campuses" link
        var target = object.up().next();
        Event.observe(object, 'click', function(event) {
            Event.stop(event);
            target.toggle();
        })
    });

    // View all programs link
    var custSdpoNotVisible = $$('.activateInvisibleCSDPO');
    custSdpoNotVisible.each(function(object, index) {
        // hidden div after "view all programs offered link
        var target = object.up().next();
        Event.observe(object, 'click', function(event) {
            Event.stop(event);
            var anchorHTML = this.innerHTML;
            if (target.visible()) {
                anchorHTML = anchorHTML.replace("only", "all");
            } else {
                anchorHTML = anchorHTML.replace("all",  "only");
            }
            target.toggle();
            this.innerHTML = anchorHTML;
        })
    });

});

ASD.setHighlightLeftNav = function() {
	var leftlinks = $$('.asd .left-nav a');
    
	
	
	if ($('navigation-specialization') || $('navigation-degreetype')){
    	var spec = $('navigation-specialization').innerHTML;
        var deg = $('navigation-degreetype').innerHTML;
        var urlPath = ASD.getPathToHighlight(deg, spec);
        
    	URL=window.location.href.split("?");
    	pageURL=URL[0];
    	
    	if(pageURL.indexOf("online")<0){
    		if(deg!=""){
    			endOfURL=pageURL.indexOf(deg);
    			pageURL=pageURL.substring(0,endOfURL+deg.length);
    		}else if(spec!=""){
    			endOfURL=pageURL.indexOf(spec);
    			pageURL=pageURL.substring(0,endOfURL+spec.length);
    		}
    	}

    	// look for it in the anchor links
        var links = $$('.asd .left-nav a');
        if (links.size() > 0) {
            // all left-nav links
            var found = false;
            links.each(function(item) {
            	//item.observe('click', ASD.respondToClick);
            	if (!found && item.href==pageURL){
                    if(item.up().tagName!="H2"){
                    	item.up().id = "selected";
                    	found = true;
                    }
                }
            });
        }
        
    }
};


ASD.isSpecialOnlinePage = function() {
    var currUrl = window.location.href;
    var segments = currUrl.split("/");
    var isOnline = false;
    if ( segments.length >= 9 )
    {
	    var onlinePath = segments[8]; //http:, blank, domain, controllerPath, degree, specialization, state, city, online
        isOnline = onlinePath == "online";
    }
    return isOnline;
};




ASD.setSpecializationDropdown = function() {
    var specObj = $('navigation-specialization');
    var degObj = $('navigation-degreetype');
    if (specObj && degObj)
    {
        var spec = specObj.innerHTML;
        var deg = degObj.innerHTML;
        var selectbox = $$(".specialization-dropdown");
        var dropdown = null;
        
        if (selectbox){
            dropdown = selectbox.first();
        }
        if (dropdown != null && spec != null && deg != null)
        {
            var urlPath = "";
            if ( deg == "" )
            {
                urlPath += "all-degrees"
            }
            else
            {
                urlPath += deg;
            }

            if ( spec != "" )
            {
                urlPath += "/" + spec;
            }
            
            URL=window.location.href.split("?");
        	pageURL=URL[0];
        	
        	if(pageURL.indexOf("online")<0){
        		if(deg!=""){
        			endOfURL=pageURL.indexOf(deg);
        			pageURL=pageURL.substring(0,endOfURL+deg.length);
        		}else if(spec!=""){
        			endOfURL=pageURL.indexOf(spec);
        			pageURL=pageURL.substring(0,endOfURL+spec.length);
        		}
        	}

        	var i = pageURL.indexOf(".com/");
        	pageURL=pageURL.substr(i+5);
            var i = pageURL.indexOf("/");
            pageURL=pageURL.substr(i+1);
        	
            var options = dropdown.getElementsBySelector('option').each(
            function(item, index) {
            	if (item.value == pageURL) {
                    dropdown.selectedIndex = index;
                }
            });
        }
    }
};