var getFeaturedVehicles;
var getTicker;
var getPromos;

jQuery(function(){
    var playerVersion = '9.0.20';
    if(swfobject.hasFlashPlayerVersion(playerVersion)){
	jQuery('#featuredVehicles').hide();
	jQuery('#ticker').hide();
	jQuery('#promos').hide();
    }

    var featuredVehicles = [];
    jQuery('#featuredVehicles > ul > li').each(
	function(){
	    featuredVehicles.push(
		{
		    'name'       : jQuery(this).find('h3').text(),
		    'src'        : jQuery(this).find('img').attr('src'),
		    'transition' : (jQuery(this).find('img').attr('data-transition') || ''),
		    'duration'   : (jQuery(this).find('img').attr('data-duration' || '')),
		    'links'      : getFVLinks(jQuery(this).find('ol > li > a')),
		    'description': (jQuery(this).find('img').attr('alt') || '')
		}
	    );
	}
    );

    function getFVLinks(jq){
	var links = [];
	jq.each(
	    function(){
		links.push(
		    {
			'title' : jQuery(this).text(),
			'href'  : jQuery(this).attr('href')
		    }
		);
	    }
	);
	return links;
    }

    getFeaturedVehicles = function(){ return featuredVehicles; };

    var params    = { 'wmode' : 'opaque', 'scale': 'noscale', 'salign': 'tl'};
    var attributes= { 'id'    : 'featuredVehiclesSwf' };
    var flashvars = {
	'title' : jQuery('#featuredVehicles > h2:first').text(),
	'appURL': '/media/featured-vehicles.swf',
	'getFeaturedVehiclesFun': 'getFeaturedVehicles'
    };

    swfobject.embedSWF(
	'/media/preloader.swf',
	'featuredVehicles', '700', '383', playerVersion, '/media/expressInstall.swf',
	flashvars, params, attributes);

	var ticker = [];
	jQuery('#ticker > ul > li').each(
	    function(){
	    	ticker.push( jQuery(this).html() );
	    }
	);
	getTicker = function(){ return ticker; };
	
	params    = { 'wmode' : 'opaque', 'scale': 'noscale', 'salign': 'tl'};
	attributes= { 'id'    : 'tickerSwf' };
	flashvars = {
	    'appURL': '/media/ticker.swf',
	    'getTickerFun': 'getTicker'
	};
	
	swfobject.embedSWF(
	    '/media/preloader.swf',
	    'tickerSwfHolder', '700', '35', playerVersion, '/media/expressInstall.swf',
	    flashvars, params, attributes);
    var promos = [];
    jQuery('#promos > ul > li').each(
	function(){
	    promos.push(
		{
		    'description': jQuery(this).find('h3').html(),
		    'link'       : jQuery(this).find('a').attr('href'),
		    'image'      : jQuery(this).find('img').attr('src')
		}
	    );
	}
    );
    
    getPromos = function(){ return promos; };

    params    = { 'wmode': 'opaque', 'scale': 'noscale', 'salign': 'tl', 'bgcolor' : '#000000' };
    attributes= { 'id'   : 'promosSwf' };
    flashvars = {
	'appURL': '/media/promos.swf',
	'getPromosFun': 'getPromos'
    };

    swfobject.embedSWF(
	'/media/preloader.swf',
	'promosSwfHolder', '700', '84', playerVersion, '/media/expressInstall.swf',
	flashvars, params, attributes);
});
