if (window.drivve === undefined)
{
    drivve = {};
}

drivve.navtools =
{
    initialize: function()
    {        
        jQuery("#carousel a.nav").bind("click", drivve.navtools.handle_button_jump);
        jQuery("#carousel .links a").bind("click", drivve.navtools.handle_button_jump);
        jQuery("#carousel .tabs li").bind("click", drivve.navtools.handle_tab_jump);

        if (document.location.search != "")
        {
            var params = document.location.search.slice(1).split("&");
            jQuery.each(params, function(i, param)
            {
                var kv = param.split("=");
                if (kv[0] == "s")
                {
                    drivve.navtools.jump_to(kv[1]);
                }
            });
        }
        else
        {
            var first_id = jQuery("#carousel ul#largePanel li:first").attr("id");
			drivve.navtools.jump_to(first_id);
        }
    },
    
    handle_button_jump: function(evt)
    {
        var target_slide = jQuery(this).attr("href").replace(/#/, "");
        drivve.navtools.jump_to(target_slide);
        return false;
    },
    
    handle_tab_jump: function(evt)
    {
        var target_slide = jQuery(this).attr("class");
        drivve.navtools.jump_to(target_slide);
        return false;
    },
    
    jump_to: function(target_slide)
    {
        var slide = jQuery("#carousel li#" + target_slide);
        var slide_left = slide.position().left;
        var cursor_top = jQuery("#carousel .tabs li." + target_slide).position().top + 40;

        jQuery("#carousel #largePanel").animate( {left: -slide_left}, 400 );
        jQuery("#carousel .cursor").animate( {top: cursor_top}, 400 );
        jQuery("#slider").animate( {height: slide.height() + 32}, 400);
    }
};

jQuery(document).ready(drivve.navtools.initialize);
