$(document).ready(function(){
    /*
     * Home Page Carousel
     */
    if ($('#mycarousel').length > 0) {
        var homePageCarousel = $('#mycarousel');
        var carouselItem1 = $("#controller1");
        homePageCarousel.jcarousel({
            auto: 5,
            wrap: 'last',
            scroll: 1,
            initCallback: mycarousel_initCallback,
            itemVisibleInCallback: mycarousel_itemVisibleInCallback
        });
        carouselItem1.addClass("active");
    }
    
    /*
     * Home Page Feature Height
     */
     var top_height = 0;
     $(".feature").each(function() {
        var this_height = Number($(this).css("height").replace("px",""));
        if (this_height >= top_height) {
            top_height = this_height;
        }        
     });
     $(".feature").css("height",top_height);
     
     /*
      * Main Nav
      */
    $("#mainNav li").each(function(index) {            
        if (index % 4 == 3)
            $(this).addClass("last");
    });
    
    /*
     * Last elements
     */          
    $("#miniFeatures .feature:last").css("margin","0");    
    $("#sectionNav ul li a:last").css("border-bottom","none");
    $("#footerNav li:last").parent().parent().parent().css("margin-right","0");
    /*
     * Home Page "more" "links"
     */
    $(".carousel_teaser p span").mouseover(function() {
        $(this).addClass("hover");
    }).mouseout(function() {
        $(this).removeClass("hover");
    });
    /*
     * Force '&' to next line
     */
    $(".landing_banner_title").each(function() {
        var title = $(this).html();        
        title = title.replace("&amp;","<br />&amp;");        
        $(this).html(title);
    });
});
function mycarousel_initCallback(carousel)
{
    $("#jcarousel-control a").bind("click", function() {
        carousel.scroll(jQuery.jcarousel.intval($(this).text()));
        return false;
    });
    $("#jcarousel-scroll select").bind("change", function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });
    carousel.clip.hover(function() { // Pause auto-scrolling if the user moves with the cursor over the clip
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
}
function mycarousel_itemVisibleInCallback(carousel, item, idx, state) {
    if (state == 'init')
        return;
    var imgId = $('img', item).attr("id").replace("img","");
    $("#jcarousel-control ul li a").removeClass("active");
    $("#jcarousel-control ul li a#controller" + imgId).addClass("active");
}
