var setUpScrollAnimations = function(aTags, duration) {
    // creates a smooth animation to the a tag's href anchor
    if(duration === undefined) duration = 500;
    aTags.click(function(e){
        e.preventDefault();
        var aTag = $(this);
        var elementID = aTag.attr('href');
        var targetDiv = $(elementID);
        var targetOffset = targetDiv.offset().top;
        $('html, body').animate({scrollTop: targetOffset}, duration);
    });
};

$(function(){
    // // home page logo cycle
    // var logos = $("#homepage-logos");
    // if(logos.length > 0) {
    //     logos.cycle({
    //         speed: 500,
    //         nowrap: true,
    //         cleartypeNoBg: true
    //     });
    // }
    // 
    // // slideshow cycle
    // var slideshow = $("#slideshow");
    // if(slideshow.length > 0) {
    //      slideshow.cycle({
    //         speed: 500
    //     });
    // }

    // homepage feature cycle
    var homepagefeature = $("#homepage-feature");
    if(homepagefeature.length > 0) {
		// homepagefeature.before('<div id="feature-nav">')
		homepagefeature.cycle({
			fx: 'fade',
			delay:  7000,
			timeout: 6000,
		    pager: '#feature-nav'
        });
    }
    
    // logo anchor smoothness
    var logos = $(".logos li a");
    if(logos.length > 0) setUpScrollAnimations(logos);
    
    // scroll to top anchor smoothness
    var scrollLinks = $(".scroll-top");
    if(scrollLinks.length > 0) setUpScrollAnimations(scrollLinks);

});


$(document).ready(function() {

	$("#navigation li").prepend("<span></span>"); //Throws an empty span tag right before the a tag

	$("#navigation li").hover(function() {	//On hover...
		$(this).find("span").stop().animate({
			height: "20" //Find the <span> tag and move it up 40 pixels
		}, 300);
	} , function() { //On hover out...
		$(this).find("span").stop().animate({
			height: "10"  //Move the <span> back to its original state (0px)
		}, 300);
	});

});


