/*
 * Script a executer au Document Ready
 * Simon - 2009-04-20
 *
 */

var jScroll_setting = { scrollbarWidth: 13, scrollbarMargin: 20, showArrows: true, wheelSpeed: 36, animate: true };
var thickbox_width = 750;

function ready() {

	// ENTETE

	// MENU
	$("#menu ul.sf-menu").superfish({ delay: 500, dropShadows: false, onBeforeShow: function() { sfinit(this); }, onHide: function() { sfclose(this); } } );
	
	// INNER CONTENT
	
	$('.view_content').jScrollPane(jScroll_setting);
	$('#inner_content .handle a').click(function() { return animate_inner_content(this); });

	// Colorbox
	$(".formbox").colorbox({width:thickbox_width, height:"600", iframe:true});
	$(".imagebox").colorbox({ });

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


	//Listes
	$(".richtexte ul li:first-child").addClass("premier");
	
	// Liens
	$('a').each(function () {
		if (typeof $(this).attr('href') != "undefined") {
	
			// Emails
			if ($(this).attr('href').match(/mailto/)) {
				var mt = decode_emailfilter($(this).attr('href'));
				$(this).attr('href',mt);
				if ($(this).html() == "Activer javascript")
					$(this).html(mt.replace(/mailto:/g,''));

			// Liens : si externe, ouvrir en nouvelle fenetre
			} else if ($(this).attr('href').match(/(germaincalgary.com|^\/)/) == null) {
				if ($(this).attr('target') == '')
					$(this).attr('target','_blank');
			}
		}
	});

	// Roll block
	$('h3.roll a').each(function() {
		$(this).click(function() {
			return roll_click(this);
		});

		if ($.browser.msie && parseInt($.browser.version) == 6)
			$(this).addClass('roll_ie6');
	});
	
	// Formulaires
	if ($.browser.msie && parseInt($.browser.version) == 6)
		$('a.richlink').addClass('richlink_ie6');


	// Preload images
	var menuimage0=new Image();
	menuimage0.src='/images/ul/tuiles/menu-niv2.gif';
	var menuimage1=new Image();
	menuimage1.src='/images/ul/tuiles/menu-niv3.gif';
	var menuimage2=new Image();
	menuimage2.src='/images/ul/tuiles/inner_content_handle_up.png';
	var menuimage3=new Image();
	menuimage3.src='/images/ul/tuiles/menu-decoration-1.gif';
	
	if (typeof accueil_ready == "function")
		accueil_ready();
	if (typeof services_ready == "function")
		services_ready();
	if (typeof evenements_ready == "function")
		evenements_ready();
	if (typeof contact_ready == "function")
		contact_ready();

}

function popup_ready() {

	// Champs obligatoires
	$('input, textarea, select').each(function() {
		if ($(this).hasClass('requis')) {
			var label_text = $(this).parents('td').prev().children('label').html();
			if ($(this).parents('td').prev().children('label').children('span').length < 1)
				$(this).parents('td').prev().children('label').html(label_text+ ' <span class="requis">*</span>');
		}
	});
	
	if (document.colorbox_resize) $.fn.colorbox.resize($('#content'));
}