jQuery(document).ready(function() {
	populate_select(jQuery('#f_galleries_make'), makes);
	jQuery('#f_galleries_make').change(function() {
		target = jQuery('#f_galleries_model').empty();
		make = this.value;
		for (model_key in makes[make]) {
			model = makes[make][model_key]['_'] || model_key;
			if (makes[make][model_key]['g'])
				jQuery(target).append('<option value="'+ makes[make][model_key]['g'] +'">'+ model +'</option>');
		}
	});
	jQuery('#f_galleries .submit').click(function() {
		window.location = site_w_path +'galleries/'+ jQuery('#f_galleries_model').find('option:selected').attr('value') +'/';
	});
	
	populate_select(jQuery('#f_wallpapers_make'), wp_makes);
	jQuery('#f_wallpapers_make').change(function() {
		o = jQuery('#f_wallpapers_model').empty();
		populate_select(o, wp_makes[this.value]);
	});

	jQuery('#f_wallpapers .submit').click(function() {
		try {
			m = wp_makes
				[jQuery('#f_wallpapers_make' ).find('option:selected').attr('value')]
				[jQuery('#f_wallpapers_model').find('option:selected').attr('value')]
				['id'];
			if (m) jQuery.ajax({
				url:      site_w_path +'async/wallpaper.php',
				data:     'id='+ m,
				beforeSend:    function() {
					jQuery('#result').html('<p><img src="/img/loading.gif" alt="" /> Veuillez patienter...</p>');
				},
				success:  function(html) {
					jQuery('#result').hide().html(html).slideDown();
				}
			});
		}
		catch(e) {}
	});
	
});
wp_makes = {"ArcticCat":{"ThunderCat2008":{"_":"ThunderCat 2008","id":"1170"},"_":"Arctic Cat"},"Can-Am":{"DS":{"id":"4995"},"Outlander":{"_":"Outlander ","id":"4988"},"Outlander2008":{"_":"Outlander  2008","id":"1173"},"Outlander2011":{"_":"Outlander  2011","id":"5165"},"Renegade":{"id":"4985"},"Renegade2010":{"_":"Renegade 2010","id":"5044"}},"Honda":{"TRX2008":{"_":"TRX 2008","id":"1174"}},"KTM":{"XCATV":{"_":"XC ATV","id":"4986"}},"Kawasaki":{"BruteForce2008":{"_":"Brute Force 2008","id":"1177"},"KFX2008":{"_":"KFX 2008","id":"1181"},"KFX2009":{"_":"KFX 2009","id":"5019"},"Teryx2008":{"_":"Teryx 2008","id":"453"},"Teryx2012":{"_":"Teryx 2012","id":"5195"}},"Kymco":{"Maxxer2011":{"_":"Maxxer 2011","id":"5185"}},"PGO":{"BugRacer":{"id":"1392"}},"Polaris":{"Outlaw2008":{"_":"Outlaw 2008","id":"1182"},"RangerRZR42011":{"_":"Ranger RZR4 2011","id":"5149"},"RangerRZR42012":{"_":"Ranger RZR4 2012","id":"5209"},"Sportman":{"id":"4994"}},"Suzuki":{"Eiger2008":{"_":"Eiger 2008","id":"1184"}},"Yamaha":{"Kodiak2012":{"_":"Kodiak 2012","id":"5155"},"Raptor":{"id":"4991"},"Raptor2009":{"_":"Raptor 2009","id":"4982"},"Rhino2008":{"_":"Rhino 2008","id":"1187"},"YFZ2008":{"_":"YFZ 2008","id":"1188"}}}
