document.observe('dom:loaded', function() {
	
	add_sifr();
	
	$$('.contentHolder li:first-child').invoke('addClassName', 'noBorder');
	
	// initialise le flash de la page d'accueil
	var flashvars = {
	  fichier: "http://mediafilm.ca/regie.xml"
	};
	var params = {
	  fichier: "http://mediafilm.ca/regie.xml",
	  scale: "noscale"
	};
	
	swfobject.embedSWF("mediafilm-swf-regie.swf", "pageAccueilFlash", "709", "260", "9.0.0","includes/js/swfobject/2.1/expressInstall.swf", flashvars, params );
	
	var config = {
		sCssBtnSizeChange: '.btn_textResize',
		sCssContainer: '.contentHolder, #leftContent,#filmRecents,.btn_textResize',
		aCssFontClass: ['size1','size2']
	}
	
	if(typeof(FontSizeControl) != 'undefined') {
		var oFontSize = new FontSizeControl(config);
	}
	
	if($('btn_textPrint')) {
		$('btn_textPrint').observe('click', function(e){
			$j('.sIFR_tradegothic').sifr({ unsifr: true });
			window.print();
			
			var fRedoSifr = function() {
				add_sifr();
			}
			
			fRedoSifr.delay(2);
			
		});
	}
	
	setRechercheFilm();
	
	setLeftMenuHilightExternal();
});

function setRechercheFilm() {
	var sTexteRecherche = '';
	
	if($('link-recherche-globale')) {
		$('link-recherche-globale').observe('click', function(e){
			e.stop();
			setRecherche();
		});
		
		$('texteRecherche').observe('keypress', function(e) {
			if(e.keyCode == Event.KEY_RETURN) {
				e.stop();
				setRecherche();
			}
		});
		
		$('texteRecherche').observe('blur', function(e){
			setRechercheHint();
		});
		
		$('texteRecherche').observe('focus', function(e){
			$('texteRecherche').setStyle( { 'color' : '' } );
			
			var sHintText = $('text-search-when-blank').innerHTML;
			
			if( $F('texteRecherche') == sHintText ) {
				$('texteRecherche').value = '';
			}
		});
		
		setRechercheHint();
		
	}
	
}

/* initialise le replacement de la typo */	
function add_sifr(){
	$j(".sIFR_tradegothic").sifr({path: sWebsiteRoot + '/includes/js/sifr/font/', font:'TradeGothicBold', verticalAlign:'top', nPaddingRight:'80' });
	$j("h4.sIFR_tradegothic").sifr({path: sWebsiteRoot + '/includes/js/sifr/font/', font:'TradeGothicBold', verticalAlign:'top', aoY:'1' });
}

function showNote(title, message, colorBack, back, textColor, typeFont, sizeFont) {
  windowNote = window.open('','Note','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,' + 'width=400' + ',height=100');
  text = '<html><head><title>' + title + '</title></head><body background=' + '"' + back + '"' + ' bgcolor=' + '"' + colorBack + '">';

  text +='<font face="' + typeFont +'"';
  text += ' size=' + sizeFont; 
  text += ' color=' + '"' + textColor +'">';
  text += message + '</font>';
  text += '</body></html>';
  windowNote.document.write(text);
  windowNote.focus();
  windowNote.document.close();
  return false;
}

function setRecherche() {
	
	var oReRechercheFilms = /^http:\/\/72\.55\.128\.22[23]:8080\/rcq_cyber\/|http:\/\/recherche\.rcq\.gouv\.qc\.ca\/rcq_cyber\//i;
	var sHref = unescape(window.location.href);
	
	if(oReRechercheFilms.test(sHref)) {
		document.charset = 'iso-8859-1';
	}
	
	$('recherche-globale').submit();
}

function setRechercheHint() {
	var sHintText = $('text-search-when-blank').innerHTML;
	
	if($F('texteRecherche') == '' || sHintText == $F('texteRecherche')) {
		$('texteRecherche').setStyle( { 'color' : '#ccc' } );
		$('texteRecherche').value = sHintText;
	}
}

function setLeftMenuHilightExternal() {
	var oReRechercheSite = /^http:\/\/recherched\.gouv\.qc\.ca\/internet\//i;
	var sHref = unescape(window.location.href);
	
	if($('left-link-search-film') && $('advancedSearchMarker')) {
		$('left-link-search-film').addClassName('selected');
	}
	
	if($('left-link-search-site') && oReRechercheSite.test(sHref)) {
		$('left-link-search-site').addClassName('selected');
	}
}