// Initialize

$(document).ready(function(){
	
	//Drop Downs
	$('#nav li').hoverIntent(
		function(){
			$(this).find('ul').slideDown('500').show();
		},
		function(){
			$(this).find('ul').slideUp('100');   
		});

	
	//Link Anchor Animation 

	function filterPath(string) {
        return string
  		.replace(/^\//, '')
		.replace(/(index|default).[a-zA-Z]{3,4}$/, '')
		.replace(/\/$/, '');
    }
    var locationPath = filterPath(location.pathname);
    $('a[href*=#]').each(function() {
        var thisPath = filterPath(this.pathname) || locationPath;
        if (locationPath == thisPath
		  && (location.hostname == this.hostname || !this.hostname)
		  && this.hash.replace(/#/, '')) {
            var $target = $(this.hash), target = this.hash;
            if (target) {
                var targetOffset = $target.offset().top;
                $(this).click(function(event) {
                    event.preventDefault();
                    $('html, body').animate({ scrollTop: targetOffset }, 800, function() {
                        location.hash = target;
                    });
                });
            }
        }
    });
	
	// Overlay Slider for Sub Content Images
    function overlaySlider(section, overlay, slideTime) {
        $(section).each(function() {
            var overlayHeight = $(this).find(overlay).height() + 25;
            var overlayHeight = '-' + overlayHeight + 'px'
            $(this).find(overlay).css({ 'bottom': overlayHeight });

            $(section).hoverIntent(
                function() {
                    //var overlayHeight = $(this).find('.overlay').height();
                    $(this).find(overlay).stop().animate({ bottom: '0px' }, { queue: false, duration: slideTime });
                },
                function() {
                    $(this).find(overlay).stop().animate({ bottom: overlayHeight }, { queue: false, duration: slideTime });
                }
            );
        });

    }

    //Call overlaySlider
    overlaySlider('.project', '.links', 300);
	
	$('#instructorLink .project-img').after('<ul id="instructorLinkNav" class="img-nav">').cycle({
		timeout: 0,
		pager: '#instructorLinkNav',
		pagerAnchorBuilder: function(idx, slide){
			return '<li><a href="#"><img src="' + slide.src + '" width="50" height="50" /></a></li>';	
		}
	});
						   
						   
});