// onload_defaut.js
// simon - egzakt.com
// 2008-05-01
function document_ready() {
	
	$('div.zone_deroulante').not('.garder_ouvert').hide();
	
	$('h3 a.lien_deroulant, h1 a.lien_deroulant').click(function() {
		if (!$(this).hasClass("selected")) {
			$('h3 a.lien_deroulant').each(function(i){
				$(this).parent().nextAll('div:first').slideUp();
				$(this).removeClass('selected');
			});
			
			$(this).parent().nextAll('div:first').slideToggle();
			$(this).toggleClass('selected');
		} else {
			$(this).parent().nextAll('div:first').slideUp();
			$(this).removeClass('selected');
		}
		return false;
	});

	// Images qui n'existent pas
	$(".fcktexte img").error(function() {
		$(this).hide();
	});
	
	// Rollover des logos Hewitt et Alt CAT
	$("#logos_hew_atl a").hover(function(){
		$("#logos_hew_atl_desc").html($(this).attr("title")).show();
	},function(){
		$("#logos_hew_atl_desc").hide();
	});

	// EquipRental
	$("#categorypreview .preview ul").hide();
	$("#categorypreview .preview a.previewlink").show();
	$("#categorypreview .preview").hover(function() {
		return showrentalsubcats(this,"hover");
	},function() {
		return showrentalsubcats(this,"out");
	});

	$("#equiprentallist .equiprental a.detail").click(function() {
		return showrentaldetail(this);
	});


	// Tableaux
	$(".fcktexte table").not(".specs").attr("cellSpacing","1").attr("border","0");
	var tr = 1;
	$(".fcktexte table tbody").each(function() {
		tr = 1;
		$(this).children("tr").each(function() {
			if ((tr % 2) == 0)
				$(this).addClass("paire");
			tr++;
		});
	});
	$(".fcktexte table tbody tr:first-child td, .fcktexte table tbody tr:first-child th").addClass("premier_ligne");
	$(".fcktexte table tbody tr td:first-child, .fcktexte table tbody tr th:first-child").addClass("premier_colonne");


	//Listes
	$(".fcktexte ul li:first-child").addClass("premier");
	
	// Liens : si externe, ouvrir en nouvelle fenetre
	$('.fcktexte a').each(function () {
		if ($(this).attr('href')) {
			if ($(this).attr('href').match(/locationhewitt.ca/) == null) {
				if ($(this).attr('target') == null)
					$(this).attr('target','_blank');
			}
		}
	});
	
	// Imprimer
	$('#webtools a.imprimer').click(function () {
		window.print();
		return false;
	});
	
	$('.selectbycategory .selection a.action').click(function() {
		$(this).next().toggle();
		return false;
	});
	
	$('.selectbycategory .selection a.action').bind('click', jsddm_open);
	$('.selectbycategory .selection').bind('mouseover', jsddm_canceltimer);
	$('.selectbycategory .selection').bind('mouseout', jsddm_timer);
	$('.selcategories').hide();

	document.onclick = jsddm_close;
	
	// Region (province) du client
	$('.logoclh').each(function() {
		var logoclh_src = $(this).attr('src');
		// Jeff - 2009-08-06
		// Ajout de la validation que l'API de Google nous retourne la position du client ("QC","US",etc..)
		if (google.loader.ClientLocation) {
			if (google.loader.ClientLocation.address.region.toUpperCase() == "QC") {
				$(this).attr('src',logoclh_src.replace(/\/(fr|en)\//,'/fr/'));
			} else {
				$(this).attr('src',logoclh_src.replace(/\/(fr|en)\//,'/en/'));
			}
		// Si l'API de Google nous retourne pas l'endroit du client, on set en anglais par défaut
		} else {
			$(this).attr('src',logoclh_src.replace(/\/(fr|en)\//,'/en/'));
		}
	});
	
	
	$('input.searchtxt').not('input[@name=codepostal]').focus(function() {
		if ($(this).val() == searchtxtval)
			$(this).val('');
	}).blur(function() {
		if ($(this).val() == '')
			$(this).val(searchtxtval);
	});
	
	// Code postal focus/blur toggle
	$('.wp1 input.searchtxt[@name="codepostal"]').focus(function() {
		if ($(this).val() == codepostal_val)
			$(this).val('');
	}).blur(function() {
		if ($(this).val() == '')
			$(this).val(codepostal_val);
	});
	
	$('.selectbycategory .selection .selcategories a').click(function() {
		$(this).parent().prev('a.action').html($(this).html());
	})
	
	$(".soumettre_2").hover(function() { $(this).addClass('soumettre2_selected'); },function() { $(this).removeClass('soumettre2_selected'); });
	$(".soumettre").hover(function() { $(this).addClass('soumettre_selected'); },function() { $(this).removeClass('soumettre_selected'); });
	
	// IE6 Bugs
	if (($.browser.msie)) {
		if ($.browser.version < 7) {
			$("#wrapper").addClass("msie");
		} else {
			$("#wrapper").addClass("msie7");
		}
		$('.btn_submit').addClass('btn_submit_ie6');
	}
	
	// JS onload Nos magasins
	if(typeof document_ready_store == 'function')
		document_ready_store();
	
	// JS onload Outils calculs
	if(typeof document_ready_outils == 'function')
		document_ready_outils();
		
	// JS onload Inscription formations
	if(typeof document_ready_training == 'function')
		document_ready_training();

	// JS onload Inscription formations
	if(typeof document_ready_compte == 'function')
		document_ready_compte();

	// JS onload equipused
	if(typeof document_ready_equipused == 'function')
		document_ready_equipused();

}
