﻿var accordion = {
    init    : function(){
        this.run();
    },
    run     : function(){
        $("#homeAccordion").accordion();
    }
}


// Slideshow Controller
var homepageImageSwap = {
    init : function(){
        this.run();
    },
    run : function(){
        
        var $homeNav = $('#homeNav #newTrucks li');
        
        $homeNav.hoverIntent(function(){
            $('#homeNav #newTrucks li.on').removeClass('on');
            $(this).addClass('on');
            $('.homeSlide.on').stop(true, true).fadeOut('normal', function(){
                $(this).removeClass('on')
            });        
            $('.homeSlide').eq($homeNav.index($(this))).stop(true, true).fadeIn('normal', function(){
                $(this).addClass('on')
            });
        }, function(){});
                
        $('a.btn:first').click(function(){
            $('#homeNav #newTrucks li.on').removeClass('on');
            $('.homeSlide.on').stop(true, true).fadeOut('normal', function(){
                $(this).removeClass('on')
            }); 
            $('#new').stop(true, true).fadeIn('normal', function(){
                $(this).addClass('on')
            });            
        });
                
                
        $('a.btn:last').click(function(){
            $('.homeSlide.on').stop(true, true).fadeOut('normal', function(){
                $(this).removeClass('on')
            }); 
            $('#used').stop(true, true).fadeIn('normal', function(){
                $(this).addClass('on')
            });            
        });
    }
}


// Navigation Controller
var nav = {
    navLink     : Object,
    init        : function(){
        navLink = $('#homeUsedTruckBanner li a');
        this.run();
    },
    run         : function(){
    
        // Removes default highlight, adds span to attatch fade highlight
        navLink.each(function(){
            $(this).append('<span class="hover">&nbsp;</span>').parent().removeClass('highlight'); 
        });
        
        // Fade In/Out Highlight
        navLink.hover(function(){
            $(this).find('span').stop(true, true).fadeIn(400);
        }, function(){
            $(this).find('span').stop(true, true).fadeOut(400);
        });
    
    }
}



// Page Initialization
function homeInitialize(){
    accordion.init();
    homepageImageSwap.init();
    nav.init();
}


// Start
$(document).ready(function(){
    homeInitialize();
});