var $team_height = 0;
var $product_height = 0;
var $product_timer = null;
var $team_timer = null;
var $isIE = false;

$(document).ready( function(){

	$(document).pngFix();

	$(".cee_link").ceebox({
		htmlWidth: 650,
		htmlHeight: 400,
		htmlGallery: false
	});

	$(".dealer_link").ceebox({
		htmlGallery: false,
		imageGallery: false,
		overlayOpacity: 0.9
	});

    /*
     * A work around for a bug in jQuery that has trouble
     * determining the actual height of a hidden element
     * resulting in a very ugly jump at the end of the slide.
     *
     * Dropdown is visible, but positioned way left in css
     * to prevent flickering on page load. Get the height,
     * save it, then hide the dropdown and put it back in
     * the correct position.
     *
     * Sliding in IE looks horrific, so we're just doing show/hide.
     */
    $team_height = $('#team_dropdown').height();
    $product_height = $('#product_dropdown').height();
    $('.dropdown').css("display", "none" ).css("z-index", 50);

    $('#products-hotspot').mouseenter( function(){
        if( $product_timer != null ){
            clearTimeout( $product_timer );
        }
        if( $('#product_dropdown').css("display") == "none" ){
            $('#product_dropdown').show();
            if( $('#team_dropdown').css("display") == "block" ){
                $('#team_dropdown').hide();
            }
        }
    });

    $('#products-hotspot').mouseleave( function(){
        $product_timer = setTimeout("$('#product_dropdown').hide()",125 );
    });

    $('#product_dropdown').mouseenter( function(){
        if( $product_timer != null ){
            clearTimeout( $product_timer );
        }
    });

    $('#product_dropdown').mouseleave( function(){
        $product_timer = setTimeout("$('#product_dropdown').hide()",125 );
    });

    $('#team-hotspot').mouseenter( function(){
        if( $team_timer != null ){
            clearTimeout( $team_timer );
        }
        if( $('#team_dropdown').css("display") == "none" ){
            if( $('#product_dropdown').css("display") == "block" ){
                $('#product_dropdown').hide();
            }
            $('#team_dropdown').show();
        }
    });

    $('#team-hotspot').mouseleave( function(){
        $team_timer = setTimeout("$('#team_dropdown').hide()", 125);
    });

    $('#team_dropdown').mouseenter( function(){
        if( $team_timer != null ){
            clearTimeout( $team_timer );
        }
    });

    $('#team_dropdown').mouseleave( function(){
        $team_timer = setTimeout("$('#team_dropdown').hide()",125 );
    });
});
