/**
 * This function will add a target _blank effect with the onclick attribute
 * on any css selector (i.e a.blank => all the a with the class blank)
 *
 * @author Francois Lavertu
 */

addTargetBlank = function(sCssSelector){
    $$(sCssSelector).invoke('observe', 'click', function(e){
        // check if the element as the href attribute
        if(this.href){
            window.open(this.href);
            Event.stop(e);
        }
    });
}

document.observe('dom:loaded', function() {

	/* ajouter une classe à un lien pour simuler un target=blank */
	addTargetBlank('a.blank');

	/* ajouter une classe pour simuler un pseudo-selector pour IE */
	$$('.contentHolder li:first-child').invoke('addClassName', 'noBorder');
	
	if($('search-make') && $('search-model')) {
		
		var oQS = window.location.href.toQueryParams();
		
		filterSelectBox($F('search-make'), 'search-model', '/includes/ajax/search-models.php', $H(oQS).get('search-model'), false);
		
		$('search-make').observe('change', function() {
			filterSelectBox($F('search-make'), 'search-model', '/includes/ajax/search-models.php', '', false);
		});
	}

	/* fonction d'accessibilité pour la typo */
	/*
	var config = {
		sCssBtnSizeChange: '#btn_fontResize',
		sCssContainer: '.content_holder',
		aCssFontClass: ['size1','size2'],
		sCssRteContainer: '.rte_texte'
	}
	var oFontSize = new FontSizeControl(config);
	*/
	
	// imagarotator on home page
	if($('bolides_flashHolder')){
		var flashvars = {
			file: 'bolide-en-vedette.xml.php',
			width: '328',
			height: '240',
			transition: 'fade',
			overstretch: 'false',
			showicons: 'false',
			shownavigation: 'true',
			rotatetime: '3'
	    }
	    var params = {allowFullScreen: 'true'};
	   	swfobject.embedSWF("/swf/imagerotator.swf", "bolides_flashHolder", "328", "240", "9.0.0", "/Commun/js/swfobject/2.0/expressInstall.swf", flashvars, params);
	}
	
	// flv player on home page
	if($('lacroixTV_flashHolder')){
		var flashvars = {
			file: 'lacroix-tv.xml.php',
			skin: '/Commun/flash/mediaplayer/skins/stylish/stylish.swf',
			controlbar: 'over',
			icons: 'false',
			fullscreen: 'true',
			image: '/css/commun/img/logo_lacroix-tv.jpg'
	    }
	    var params = {allowFullScreen: 'true'};
	   	swfobject.embedSWF("/Commun/flash/mediaplayer/4.3/player.swf", "lacroixTV_flashHolder", "319", "176", "9.0.0", "/Commun/js/swfobject/2.0/expressInstall.swf", flashvars, params);
	}
	
	
	// spinning tire in pageHeader
	if($('spinningTire_flashHolder')){
		var flashvars = { }
	    var params = {allowFullScreen: 'false'};
	   	swfobject.embedSWF("/swf/spinningTire.swf", "spinningTire_flashHolder", "45", "45", "9.0.0", "/Commun/js/swfobject/2.0/expressInstall.swf", flashvars, params);
	}
	
	// roues-virtuelles
	if($('roues-virtuelles_flashHolder')){
		var flashvars = { }
	    var params = {
		wmode: 'transparent',
		allowFullScreen: 'false'};
	   	swfobject.embedSWF("/swf/btn_roues-virtuelles.swf", "roues-virtuelles_flashHolder", "334", "183", "9.0.0", "/Commun/js/swfobject/2.0/expressInstall.swf", flashvars, params);
	}	
	
});