//NOTE: Changes to this file must be made to dp.cars.menu.js until this file is no longer used.

// ==ClosureCompiler==
// @compilation_level SIMPLE_OPTIMIZATIONS
// @output_file_name new-cars-menu.min.js
// ==/ClosureCompiler==

var carHomePage;
var DHeight;
var DWidth;

var flashvars = {};
flashvars.xmlSrc = (carHomePage) ? '/cars/_assets/data/navigation/navigationCarHome.xml' : '/cars/_assets/data/navigation/navigation.xml';

var flashParams = {wmode: 'transparent', menu: 'false', allowscriptaccess: 'always', align: 'T', salign: 'T', quality: 'best', scale: 'noscale'};
var attributes = {id: 'newCarsMenuFlash', name: 'newCarsMenuFlash'};

swfobject.embedSWF('/cars/_assets/flash/verticalnav.swf', 'newCarsMenu', '200', '471', '9.0.0', '/_assets/flash/expressInstall.swf', flashvars, flashParams, attributes);

var carsMenuOver = 0;
var carsMenuTimeout;
function collapseMenu(){
	$('#newCarsMenuFlash').height(365);
	carsMenuOver = 0;
}

$(document).ready(function () {

	//Increase and decrease the height of flashMenuWrapper on
	//mouseover/mouseout to uncover promo buttons on cars homepage
	$('#flashMenuWrapper').bind('mouseover', function(){
		if(carsMenuOver === 1){
			clearTimeout(carsMenuTimeout);
		}
		$('#newCarsMenuFlash').height(471);
		carsMenuOver = 1;
	})
	$('#flashMenuWrapper').bind('mouseout', function(){
		carsMenuTimeout = setTimeout('collapseMenu()', 500);
	})

    //Create a hover layer and bind collapse to pages other than home
    var $flashMenuWrapper = $('#flashMenuWrapper');

    $flashMenuWrapper.before('<div id="flashMenuWrapperHover"></div>');
    $flashMenuWrapper.bind('mouseleave', function () {
        if (!carHomePage) {
            if (FL('newCarsMenuFlash')) { try { FL('newCarsMenuFlash').collapse() } catch (e) { } };
        }
    });

    // Apply CSS to initially collapsed menu pages other than home
    if (!carHomePage) {
        $flashMenuWrapper.css({ background: 'none', width: '210px', height: '23px', overflow: 'hidden' });

        if (!swfobject.hasFlashPlayerVersion('9.0.0')) $flashMenuWrapper.css({ width: '156px' })
    }

    // Apply CSS to hover layer and create hover binding
    $('#flashMenuWrapperHover').css({ zIndex: $flashMenuWrapper.css('zIndex') - 1, display: 'none', position: 'absolute', top: '0', left: '0', width: '400px', height: '600px' })
    $('#flashMenuWrapperHover').bind('mouseover', function () {
        closeMenu();
    });
});

/* Flash triggered */
function callbackNavReduced() {
    closeMenu();
}
function callbackNavExpanded() {
    openMenu();
}
/* JavaScript triggered */
function closeMenu() {
    $('#flashMenuWrapperHover').hide();
    $('#flashMenuWrapper').css({ height: '23px', zIndex: '40', marginLeft: '-520px' });
    if (FL('inspireFlash')) { try { FL('inspireFlash').startProcessing(); } catch (e) { } }
}
function openMenu() {
    if ($.browser.mozilla) {
        DHeight = $(document).height();
        DWidth = $(document).width();
        $('#flashMenuWrapperHover').height(DHeight).width(DWidth).show();
    }
    $('#flashMenuWrapper').css({ height: '460px', zIndex: '80' });
    if (FL('inspireFlash')) { try { FL('inspireFlash').stopProcessing(); } catch (e) { } }
}



