// On load

$(document).ready(function() {

/* Toggle Labels in Form Fields */

/*-----------------------------------------*/
$("input[name='user']").toggleVal({ populateFrom: "label", removeLabels: true });
$("input[name='pass']").toggleVal({ populateFrom: "label", removeLabels: true });
$("input[name='search-gwu']").toggleVal({ populateFrom: "label", removeLabels: true });
/*-----------------------------------------*/




/*-----------------------------------------*/

/* Close Panels */

/*-----------------------------------------*/
$('#panels .close').click(function() {
    closePanels();  
});
function closePanels() {
    $('#panels').slideUp(); 
    $("#primary-nav dt").removeClass("active");
};


/*-----------------------------------------*/

/* Load Feature Slideshow (Orbit) */

/*-----------------------------------------*/
 
$(window).load(function() {
$('#featured').orbit();
});


/*-----------------------------------------*/


/*-----------------------------------------*/
// Apple detection object  
var Apple = {};  
Apple.UA = navigator.userAgent;  
Apple.Device = false;  
Apple.Types = ["iPhone", "iPod", "iPad"];  
for (var d = 0; d < Apple.Types.length; d++) {  
    var t = Apple.Types[d];  
    Apple[t] = !!Apple.UA.match(new RegExp(t, "i"));  
    Apple.Device = Apple.Device || Apple[t];  
}  
/*-----------------------------------------*/

/* Home Page Slideshow Controls */

/*-----------------------------------------*/
if (Apple.Device = "iPhone" || "iPod" || "iPad") {
var myTimer={};
$('.hp-container').mouseleave(function() { 
    $.clearTimer(myTimer);
    $('.hp-feature-menu').fadeOut(); 
}); 
$('.hp-container').mouseenter(function() {
    myTimer = $.timer(1000,function(){
        $('.hp-feature-menu').fadeIn(); 
        // Optional function to call when timer is canceled
     },function(){
     }); 
});
}
$('.hp-slideshow').cycle({ 
    fx:     'scrollHorz', 
    timeout: 8000,
    before:  onBefore, 
        after:   onAfter
});
$('.hp-feature-copy').cycle({ 
    fx:     'scrollUp',
    timeout: 8000,
    delay:   600
});
function onBefore() { 
    var s = $('.hp-slideshow').index(this);
    $('.hp-feature-menu li').eq(s).addClass("active");
} 
function onAfter() { 
}

$('.feature-link-1').click(function() { 
    $('.hp-feature-copy').cycle(0);
    $('.hp-slideshow').cycle(0); 
    return false; 
}); 
$('.feature-link-2').click(function() { 
    $('.hp-feature-copy').cycle(1);
    $('.hp-slideshow').cycle(1); 
    return false; 
}); 
$('.feature-link-3').click(function() { 
    $('.hp-feature-copy').cycle(2);
    $('.hp-slideshow').cycle(2); 
    return false; 
}); 
$('.feature-link-4').click(function() { 
    $('.hp-feature-copy').cycle(3);
    $('.hp-slideshow').cycle(3); 
    return false; 
}); 
$('.feature-link-5').click(function() { 
    $('.hp-feature-copy').cycle(4);
    $('.hp-slideshow').cycle(4); 
    return false; 
}); 
$('.hp-feature-copy').mouseover(function() { 
    $('.hp-slideshow').cycle('pause'); 
    $('.hp-feature-copy').cycle('pause'); 
}); 
$('.hp-slideshow').mouseover(function() { 
    $('.hp-slideshow').cycle('pause'); 
    $('.hp-feature-copy').cycle('pause'); 
}); 
$('.hp-feature-menu').mouseover(function() { 
    $('.hp-slideshow').cycle('pause'); 
    $('.hp-feature-copy').cycle('pause'); 
}); 
$('.hp-feature-copy').mouseout(function() { 
    $('.hp-slideshow').cycle('resume'); 
    $('.hp-feature-copy').cycle('resume'); 
}); 
$('.hp-slideshow').mouseout(function() { 
    $('.hp-slideshow').cycle('resume'); 
    $('.hp-feature-copy').cycle('resume'); 
}); 
$('.hp-feature-menu').mouseout(function() { 
    $('.hp-slideshow').cycle('resume'); 
    $('.hp-feature-copy').cycle('resume'); 
}); 
/*-----------------------------------------*/

/* Autocomplete */

/*-----------------------------------------*/
$('input.gsc-input').autocomplete(people, {
        minChars: 3,
        width: 320,
        max: 10,
        scrollHeight: 400,
        matchContains: true,
        delay: 500,
        formatItem: function(row, i, max) {
        
        person = "";
            if (row.name != "" // || next name to exclude, must include spaces
            
            ) {
                person = person + "<strong>" + row.name + "</strong>";  
            
            if (row.campusphone == "406-2255") {
                person = person + "</strong><span class=\"right\">704-406-4348</span>" ;
            } else if (row.campusphone != "") {
                person = person + "</strong><span class=\"right\">704-" + row.campusphone + "</span>" ;
                }
            if (row.title != "") {
                person = person + "<br />" + row.title;
            }
            if (row.campusbox != "") {
                person = person + "<br />" + row.campusbox + "<br />Boiling Springs, NC 28017";
            }
            person = person + "<br />" + row.email;
            
            return person; 
            
            }
        },
        formatMatch: function(row, i, max) {
            return row.name + row.campusphone + row.email;
        },
        formatResult: function(row) {
            return row.name;
        }
    });

/*-----------------------------------------*/


/* Denote Last Column in HP Menu - was used for , no longer used */

/*-----------------------------------------*/
/*$(".hp-menu-column ul li:last-child").addClass("last");*/
/*-----------------------------------------*/

/* Majors Minors Toggle */

/*-----------------------------------------*/

$(".toggle-majors-minors").toggle(function() {
    $(".majors-minors-title").replaceWith('<h2 class="majors-minors-title">Undergraduate Minors</h2>');
    $(".toggle-majors-minors span").replaceWith('<span>Show Majors</span>');

    $(".only-major").animate({backgroundColor: '#cec4c3'},1000).slideToggle(10);
    $(".only-minor").css('background','#c6d1be');
    $(".only-minor").delay(800).slideToggle(10).animate({backgroundColor: '#ffffff'},5000);
}, function () {
    $(".majors-minors-title").replaceWith('<h2 class="majors-minors-title">Undergraduate Majors</h2>');
    $(".toggle-majors-minors span").replaceWith('<span>Show Minors</span>');
    
    $(".only-minor").animate({backgroundColor: '#cec4c3'},1000).slideToggle(10);
    $(".only-major").css('background','#c6d1be');
    $(".only-major").delay(2000).slideToggle(10).animate({backgroundColor: '#ffffff'},5000);
});

});

