// JavaScript Document

function MM_openBrWindow(theURL,winName,features)
{ //v2.0
  window.open(theURL,winName,features);
}

$(document).ready(function()
{
    $('.profileImgs').cycle(
    {
        slideExpr: 'div',
        fx: 'fade',
        height: '292',
        speed: 1500,
        timeout: 12000
    });
    $('.profileCntnr').cycle(
    {
        slideExpr: 'div',
        fx: 'fade',
        height: '292',
        speed: 1500,
        timeout: 12000
    });
    $('.slideshowWrapper').cycle(
    {
        fx: 'fade',
        speed: '3000',
        height: '292',
        timeout: 12000
    });
    
    $(".searchField").focusin(function()
    {
        $(this).val("");
        $(this).css('color', '#000000');        
    });
    $(".searchField").focusout(function()
    {
        $(this).val('Search AU...');
        $(this).css('color', 'grey');
    });
    
    // MRI Center
    $("#mriFtrImgs").cycle(
    {
        fx: 'fade',
        height: '450',
        speed: 1500,
        timeout: 12000
    });
    
    //Current Students page
    $("#ftrImgs").cycle(
    {
        slideExpr: 'a',
        fx: 'fade',
        height: '248',
        speed: 1500,
        timeout: 12000
    });
    /* --------------------------------------------------------------- */

    function get_subDir(url)
    {
        // Variable Declarations
        var firstdotIndex = 0;
        var subdomain = "";
        var firstsubDirIndex = 0;
        var firstsubDir = "";
        var firstsubDirLen = 0;
        var scndsubDirIndex = 0;
        var scndsubDir = "";
        var thirdSubDirIndex = 0;
        var thirdSubDir = "";
        var startIndex = 0;
        var subDir = "";
        
        /* Find the subdomain of the url.*/
        var firstdotIndex = url.indexOf(".", 0);
        var subdomain = url.substr(7, 3);
        var startIndex = 0;
        
        if(subdomain == "eng")
        {
            startIndex = 22;
        }
        else
        {
            startIndex = 26;
        }
    
        var firstsubDirIndex = url.indexOf("/", startIndex);
        var firstsubDir = url.substr(startIndex, (firstsubDirIndex-startIndex));
        var firstsubDirLen = firstsubDir.length;
        var subDir = "";
        
        /* If no child directory exists then we're at the root level of the directory structure. */
        if(firstsubDirIndex == -1)
        {
            /* If we're at the site's root level then return a NULL value.*/
            if(firstsubDirIndex == url.length)
            {
                var pgNm = url.substr(startIndex, url.length);
                
                
                if(pgNm != -1)
                {
                        subDir = "";
                }
                else
                {
                    subDir = "";
                }
            }
            else
            {
                subDir = "";
            }
            
        }
        else if(firstsubDirLen >= 5)
        {
            /* If the name of the first child directory has a character length greater than 5 then 
               it's assumed that the first child directory is not a virtual alias for an academic
               program. If this assumption is proven correct then we determine if the first child
               has a descendant. (grandchild of the parent) */
               
            var scndsubDirIndex = url.indexOf("/", (firstsubDirIndex+1));
            var scndsubDir = url.substr((firstsubDirIndex+1), (scndsubDirIndex-1) - (firstsubDirIndex));
            
            
            if(scndsubDirIndex != -1)
            {
                /* If the first child has a descendant then check its name to determine if its name is either
                   centers or programs. If the first child doesn't have a descendant then return the name of 
                   the parent. */
                
                if((scndsubDir == "centers") || (scndsubDir == "programs"))
                {
                    /* If the descendant's name equals 'center' then determine if the descendant has a 
                       descendant of it's own. (great grandchild of the original parent)*/
                       
                    var thirdSubDirIndex = url.indexOf("/", (scndsubDirIndex+1));
                    var thirdSubDir = url.substr((scndsubDirIndex+1), (thirdSubDirIndex-1) - (scndsubDirIndex));
                    
                    /* If a great grandchild exists then set its name as the value of subDir. If not then
                       the value of subDir is set to the name of grand child.*/
                    if(thirdSubDir != -1)
                    {
                        subDir = thirdSubDir;
                    }
                    else
                    {
                        subDir = scndsubDir;
                    }
                }
                else
                {
                    subDir = scndsubDir;
                }
            }
            else
            {
                subDir = firstsubDir;
            }
            
        }
        else
        {
            if(firstsubDir == "comp")
            {
                subDir = "csse";
            }
            else if(firstsubDir == "elec")
            {
                subDir = "ece";
            }
            else if(firstsubDir == "txen")
            {
                subDir = "pfen";
            }
            else
            {
                subDir = firstsubDir;
            }
        }
        
        return subDir;
    
    }
    
    function getFullDeptName(deptfldrName)
    {
        var deptNmArray = new Array();
        var result = "";
        var found = 0;
        
        deptNmArray["ap-so-co-pgm"] = "Alabama Power/Southern Company Academic Excellence Program";
        deptNmArray["bo"] = "Business Office";
        deptNmArray["development"] = "Development Office";
        deptNmArray["ems"] = "Engineering Media Services";
        deptNmArray["erc"] = "Media Resource Center";
        deptNmArray["ess"] = "Engineering Student Services";
        deptNmArray["marketing"] = "Communications and Marketing";
        deptNmArray["news"] = "NEWSROOM";
        deptNmArray["newsroom"] = "NEWSROOM";
        deptNmArray["research"] = "Research";
        deptNmArray["research-new"] = "Research";
        
        /*================================================= */
        // Distance Learning
        deptNmArray["ce"] = "Continuing Education";
        deptNmArray["edge"] = "EDGE Program";
        /* ================================================= */
        // Academic Programs
        deptNmArray["aero"] = "Aerospace Engineering";
        deptNmArray["bsen"] = "Biosystems Engineering";
        deptNmArray["chen"] = "Chemical Engineering";
        deptNmArray["civil"] = "Civil Engineering";
        deptNmArray["comp"] = "Computer Science and Software Engineering";
        deptNmArray["csse"] = "Computer Science and Software Engineering";
        deptNmArray["ece"] = "Electrical and Computer Engineering";
        deptNmArray["elec"] = "Electrical and Computer Engineering";
        deptNmArray["insy"] = "Industrial and Systems Engineering";
        deptNmArray["matl"] = "Materials Engineering";
        deptNmArray["mech"] = "Mechanical Engineering";
        deptNmArray["pfen"] = "Polymer and Fiber Engineering";
        deptNmArray["txen"] = "Polymer and Fiber Engineering";
        deptNmArray["wireless"] = "Wireless Engineering";
        //deptNmArray["gei"] = "Global Opportunities";
        /* ================================================= */
        // Centers
        deptNmArray["ac-pabe"] = "Alabama Center for Paper and Bioresource Engineering";
        deptNmArray["amnstc"] = "Alabama Microelectronics Science and Technology Center";
        deptNmArray["audfs"] = "Auburn University Detection and Food Safety Center";
        deptNmArray["ose-ipp"] = "Occupational Safety, Egronomics and Injury Prevent Program";
        deptNmArray["mri"] = "Magnetic Resonance Imaging (MRI) Research Center";
        deptNmArray["hrc"] = "Highway Research Center";
        deptNmArray["impact"] = "Center for Innovations in Mobile, Pervasive, and Agile Computing Technologies";
        deptNmArray["iac"] = "Information Assurance Center";
        deptNmArray["mrec"] = "Materials Research and Education Center";            
        deptNmArray["microfibrous-materials"] = "Center for Microfibrous Materials Manufacturing";
        deptNmArray["BET"] = "Thomas Walter Center for Technology Management";
        deptNmArray["twc"] = "Thomas Walter Center for Technology Management";
        deptNmArray["werec"] = "Wireless Engineering Research and Education Center";
        
        result = deptNmArray[deptfldrName];
        
        if((result != "") && (typeof result != "undefined"))
        {
            found = 1;
        }
        
        if(found == 1)
        {
            return result;
        }
        else
        {
            return "No result";
        }
    }
    
    function getDeptPhone(deptfldrName)
    {
        var deptPhnArray = new Array();
        var deptPhnArrayIndex;
        var found = 0;
        
        // Academic Departments
        deptPhnArray["aero"] = "(334) 844-4874";
        deptPhnArray["bsen"] = "(334) 844-4180";
        deptPhnArray["chen"] = "(334) 844-4827";
        deptPhnArray["civil"] = "(334) 844-4320";
        deptPhnArray["comp"] = "(334) 844-4330";
        deptPhnArray["csse"] = "(334) 844-4330";
        deptPhnArray["ece"] = "(334) 844-1800";
        deptPhnArray["elec"] = "(334) 844-1800";
        deptPhnArray["insy"] = "(334) 844-4340";
        deptPhnArray["matl"] = "(334) 844-4822";
        deptPhnArray["mech"] = "(334) 844-4820";
        deptPhnArray["pfen"] = "(334) 844-4123";
        deptPhnArray["wireless"] = "(334) 844-8209";
        
        //Administration 
        deptPhnArray["ap-so-co-pgm"] = "(334) 844-2331";
        deptPhnArray["bo"] = "(334) 844-4302";
        deptPhnArray["do"] = "(334) 844-2308";
        deptPhnArray["ce"] = "(800) 446-0382";
        deptPhnArray["development"] = "(334) 844-2736";
        deptPhnArray["distance-learning"] = "(334) 844-4370";
        deptPhnArray["ems"] = "(334) 844-4804";
        deptPhnArray["ens"] = "(334) 844-2280";
        deptPhnArray["engce"] = "(334) 844-4370";
        deptPhnArray["erc"] = "(334) 844-5722";
        deptPhnArray["ess"] = "(334) 844-2309";
        deptPhnArray["edge"] = "(334) 844-5300";
        deptPhnArray["marketing"] = "(334) 844-2220";
        deptPhnArray["planning"] = "(334) 844-3329";
        deptPhnArray["news"] = "(334) 844-2220"; 
        
        //Centers
        deptPhnArray["ac-pabe"] = "(334) 844-2016";
        deptPhnArray["amnstc"] = "(334) 844-1887";
        deptPhnArray["audfs"] = "(334) 844-4822";
        deptPhnArray["ose-ipp"] = "(334) 844-1424";
        deptPhnArray["mri"] = "(334) 844-6747";
        deptPhnArray["hrc"] = "(334) 844-6297";
        deptPhnArray["impact"] = "(334) 844-4335";
        deptPhnArray["iac"] = "(334) 844-6360";
        deptPhnArray["mrec"] = "(334) 844-4822";            
        deptPhnArray["microfibrous-materials"] = "(334) 844-2023";
        deptPhnArray["twc"] = "(334) 844-4333";
        deptPhnArray["BET"] = "(334) 844-4333";
        
        result = deptPhnArray[deptfldrName];
        
        if((result != "") && (typeof result != "undefined"))
        {
            found = 1;
        }
        
        if(found == 1)
        {
            return result;
        }
        else
        {
            return "No result";
        }
        
    }

    $(".titleArea").html(function()
    {
        var locale = new String(window.location);
        var deptfldrNm = get_subDir(locale);
        var title = "";
        var tempResult;
        var finalResult = "";
        var found = 0;      
        
        tempResult = getFullDeptName(deptfldrNm);
        
        if(tempResult != "No result")
        {
            finalResult = tempResult;
            
            $(".mainHeading").before("<span class=\"orangeTxt\">"+finalResult+"</span>");
            $(".orangeTxt").addClass("mainHeading");
            $(".whiteTxt").removeClass("mainHeading").addClass("subHeading");
            
        }
        
    });
    
    $(".phone").html(function()
    {
        var locale = new String(window.location);
        var deptfldrNm = get_subDir(locale);
        var final_phnNum = new String();
                
        tempResult = getDeptPhone(deptfldrNm);
        
        if(tempResult != "No result")
        {
            final_phnNum = tempResult;
            $(this).html();
            $(this).html(final_phnNum);
        }

    });
    
    $(".nav a").each(function(i)
    {
        var locale = new String(window.location);
        var deptfldrNm = get_subDir(locale);
        var title = $(this).html();
        var finalURL = "";
        var fldr = "";
        
        
        switch(title)
        {
            case "Students":
                fldr = "students";
                break;
            
            case "Prospective Students":
                fldr = "students/prospective-students";
                break;
            
            case "Alumni/Friends":
                fldr = "alumni";
                break;
            
            case "Faculty/Staff":
                fldr = "faculty";
                break;
            
            case "Business and Government":
                fldr = "business";
                break;
            
            case "Visitors":
                fldr = "visitors";
                break;
            
            default:
                break;
        }
        
        if((deptfldrNm == "aero") || (deptfldrNm == "bsen") || (deptfldrNm == "chen") || (deptfldrNm == "civil") || (deptfldrNm == "ece") || (deptfldrNm == "insy") || (deptfldrNm == "matl") || (deptfldrNm == "mech") || (deptfldrNm == "pfen") || (deptfldrNm == "wireless"))
        {
            dept = 1;
        }
        else
        {
            dept = 0;
        }
        
        if(dept == 1)
        {
            if(fldr != "visitors")
            {
                if(fldr == "students/prospective-students")
                {
                    fldr = "prospective";
                }
                finalURL = "http://www.eng.auburn.edu/programs/"+deptfldrNm+"/"+fldr+"/index.html";
            }
            else
            {
                finalURL = "http://www.eng.auburn.edu/"+fldr+"/index.html";
            }
        }
        else if(dept == 0)
        {
            finalURL = "http://www.eng.auburn.edu/"+fldr+"/index.html";
        }
        else
        {
            finalURL = "#";
        }
        
        $(this).attr("href", finalURL);
    });
    

    
});

 google.load('search', '1', {language : 'en'});
  google.setOnLoadCallback(function(){
    var customSearchControl = new google.search.CustomSearchControl('012559906484653041309:7wz3_bdlfwy');
    customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
    customSearchControl.draw('coe-se-cse');
  }, true);



