// JavaScript Document
/* GESTION LISTE TEMPLATE */
function afficherListe(div_template,dataset){
	//dataset est un array multi-dimention de niveau 3    dataset[element[property]]
	html="";
	divliste = document.getElementById(div_template);
	template = divliste.innerHTML;
	for(i=0;i<dataset.length;i++){
		//nouvel élément
		tp=template;
		element = dataset[i];
		for(j=0;j<element.length;j++){
			property = element[j][0];
			value = element[j][1];
			if( property.search('date')!=-1){value = LibJour(value);}
			if( property.search('image')!=-1 && value==''){value = 'spacer.gif';}
			reg=new RegExp(property, "g");
			tp = tp.replace(reg,value.replace(/\'/g,"'"));
		}
		if(tp!=template){html+=tp;}
	}
	divliste.innerHTML=html;
}
/**/

function LibJour(ma_date) 
{ 
  jj= ma_date.substring(0,2);
  mm = ma_date.substring(3,5);
  	aa = ma_date.substring(6);
  ret = LibJourVrai(jj,mm,aa);
  return ret;
} 
function LibJourVrai(jj,mm,aa) 
{ 
	une_date=jj+'/'+mm+'/'+aa;
	navvers = navigator.appVersion.substring(0,1);
	if (navvers > 3)
	   navok = true;
	else
	   navok = false;
	
	if(une_date=='')
	{
		//Date messagerie
		today = new Date();
	}else{
		mois = une_date.split('/')[1]-1;
		if(mois==-1){ mois = 0; }
		today = new Date(une_date.split('/')[2],mois,une_date.split('/')[0]);
	}
	jour = today.getDay();
	numero = today.getDate();
	if (numero<10)
	   numero = "0"+numero;
	mois = today.getMonth();
	if (navok)
	   annee = today.getFullYear();
	else
	   annee = today.getYear();

	TabJour = new Array("Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi");
	TabMois = new Array("janvier","février","mars","avril","mai","juin","juillet","aout","septembre","octobre","novembre","décembre");
	messageDate = TabJour[jour] + " " + numero + " " + TabMois[mois] + " " + annee;
  return messageDate; 
} 
//Page indisponible
function nonDispo(){
	alert('Cette page sera bientôt disponible');	
}
//normalisation du target
function setTarget() {
if ( document.getElementsByTagName ) {
var x = document.getElementsByTagName('a');
for ( var i = 0; i < x.length; i++ ) {
if ( x[i].className.indexOf('external') == -1 ) continue;
navigator.appName == 'Microsoft Internet Explorer'
? x[i].setAttribute('onclick', function anonymous() { window.open(this.href);return false; })
: x[i].setAttribute('onclick', 'window.open(this.href);return false;');
}
}
}
if(document.all)
{
 window.attachEvent("onload", setTarget);
}
else
{
 window.addEventListener("load", setTarget, true);
}
/* Enlever click droit */
function disableRightClick(e)
{
  if(!document.rightClickDisabled)
  {
    if(document.layers) 
    {
      document.captureEvents(Event.MOUSEDOWN);
      document.onmousedown = disableRightClick;
    }
    else document.oncontextmenu = disableRightClick;
    return document.rightClickDisabled = true;
  }
  if(document.layers || (document.getElementById && !document.all))
  {
    if (e.which==2||e.which==3)
    {
      return false;
    }
  }
  else
  {
    return false;
  }
}
//disableRightClick();

/* changement des images du menu */
function menuDyn(){ 
	 for(i = 0; i < document.images.length; ++i)
 	 { 
		if(document.images[i].src.search('/b_')>0){
			//affecter l'image du menu
			document.images[i].style.cursor="pointer";
			document.images[i].onmouseover=function() { this.src= this.src.replace('/b_','/bs_'); };
			document.images[i].onmouseout=function() {  this.src= this.src.replace('/bs_','/b_'); };
			tmpimg= new Image();
			tmpimg.src=document.images[i].src.replace('/b_','/bs_');	
		}
	 }
}
/* affichage des flashs */
function filmIntro(){
	document.getElementById('film-intro').innerHTML='<object type="application/x-shockwave-flash" data="http://flv-player.net/medias/player_flv_maxi.swf" width="230" height="206"> <param name="movie" value="http://flv-player.net/medias/player_flv_maxi.swf" /> <param name="allowFullScreen" value="true" /> <param name="FlashVars" value="flv=http://www.festival-interceltique-2009.com/media/clipvideoencode.flv&width=230&height=206&loop=1&autoplay=1&volume=4&autoload=1&margin=2&showstop=1&showvolume=1&showtime=2&showloading=always&showfullscreen=1&showmouse=autohide" /> </object>';	
}
function filmPaysInvite1(){
	document.getElementById('filmPaysInvite').innerHTML='<object type="application/x-shockwave-flash" data="http://flv-player.net/medias/player_flv_maxi.swf" width="230" height="206"> <param name="movie" value="http://flv-player.net/medias/player_flv_maxi.swf" /> <param name="allowFullScreen" value="true" /> <param name="FlashVars" value="flv=http://www.festival-interceltique-2009.com/media/playervideo/BREADOFHEAVEN.flv&width=230&height=206&loop=1&autoplay=0&volume=4&autoload=1&startimage=images/start.jpg&margin=2&showstop=1&showvolume=1&showtime=2&showloading=always&showfullscreen=1&showmouse=autohide" /> </object>';	
}function filmPaysInvite2(){
	document.getElementById('filmPaysInvite2').innerHTML='<object type="application/x-shockwave-flash" data="http://flv-player.net/medias/player_flv_maxi.swf" width="230" height="206"> <param name="movie" value="http://flv-player.net/medias/player_flv_maxi.swf" /> <param name="allowFullScreen" value="true" /> <param name="FlashVars" value="flv=http://www.festival-interceltique-2009.com/media/playervideo/WALESDAYINLIFE.flv&width=230&height=206&loop=1&autoplay=0&volume=4&autoload=1&startimage=images/start.jpg&margin=2&showstop=1&showvolume=1&showtime=2&showloading=always&showfullscreen=1&showmouse=autohide" /> </object>';	
}
/*****************************************************************************
* BackToTheHtml Command
*///**************************************************************************
function BackToTheHtml(node)
{
	if(node == null)
		this.node = document; 
	else
		this.node = node; 
};
BackToTheHtml.prototype.node = null;

BackToTheHtml.prototype.execute = function()
{
	this.activateObject();
}

BackToTheHtml.prototype.activateObject = function(domObject)
{
	var aDomObject = this.node.getElementsByTagName('object');
	var activationObject;
	for(var i=0; i<aDomObject.length; i++)
		if
		(
			aDomObject[i].getAttributeNode('BackToTheHtml') == null
			&&
			(activationObject = this.getActivationObject(aDomObject[i])) != null
		)
			activationObject.execute();
};

BackToTheHtml.prototype.getActivationObject = function(domObject)
{
	var classid = domObject.classid.toUpperCase().substr('clsid:'.length);
	var mimeType = domObject.type.toLowerCase();

	switch(true)
	{
		case 
			classid == 'D27CDB6E-AE6D-11CF-96B8-444553540000' 
			||
			mimeType == 'application/x-shockwave-flash'
		:
			return new ActivateObjectFlash(domObject);

		default :
			return null;
	}
};

BackToTheHtml.uniqueID = function(prefix)
{
	var sPrefix;
	if(prefix == null)
		sPrefix = 'uniqueId';
	else
		sPrefix = prefix;
		
	var i=0;
	while(document.getElementById(sPrefix + (i++)))
		;
	return sPrefix + (i-1);
};

BackToTheHtml.isParentOf = function(parent,child)
{
	var found = false;
	for(var i=0; i<parent.childNodes.length; i++)
		if(parent.childNodes[i] == child)
			return true;
		else
			found = arguments.callee(parent.childNodes[i],child);

	return found;
}

/*****************************************************************************
* ActivateObject Command
*///**************************************************************************
function ActivateObject(domObject)
{
	this.domObject = domObject;
}

ActivateObject.prototype.domObject = null;
ActivateObject.prototype.classid = null;
ActivateObject.prototype.aHtmlAttribute = ['accessKey','align','alt','archive','border','code','codeBase','codeType','declare','dir','height','hideFocus','hspace','lang','language','name','standby','tabIndex','title','useMap','vspace','width'];
ActivateObject.prototype.aObjectProperty = null;

ActivateObject.prototype.execute = function()
{
	this.xndObjectId = BackToTheHtml.uniqueID();
	this.setTextHtml();
	this.writeObject();

	this.xndObject = document.getElementById(this.xndObjectId);
	this.setSpecialProperties();
	this.removeOriginalObject();
}

ActivateObject.prototype.setTextHtml = function()
{
	var str = '';
	str += '<object BackToTheHtml ' + '\n';
	str += ' classid="clsid:' + this.classid + '" ' + '\n';

	//Add HTML attributes to the <object> tag
	for(var i=0; i<this.aHtmlAttribute.length; i++)
	{
		var name = this.aHtmlAttribute[i];
		if(typeof this.domObject[name] != 'undefined' && this.domObject[name].toString() != '')
			str += '\t' + name + '="' + this.domObject[name].toString() + '" ' + '\n';
	}

	str += 'id="' + this.xndObjectId + '" ' + '\n';
	str += '>';

	for(var i=0; i<this.aObjectProperty.length; i++)
	{
		var name = this.aObjectProperty[i];
		if(typeof this.domObject[name] != 'undefined' && this.domObject[name].toString() != '' )
			str += '\t<param name="' + name + '" value="' + this.domObject[name].toString() + '"></param>' + '\n';
	}
	try{
	if(flashvars!=undefined){
		str+='<param name="flashvars" value="phrase='+flashvars+'">';	
	}
	}catch(e){}
	str += '</object>';

	this.textHtml = str;
};

ActivateObject.prototype.writeObject = function()
{
	this.domObject.insertAdjacentHTML("afterEnd",this.textHtml);
};

ActivateObject.prototype.setSpecialProperties = function()
{
	if(typeof this.domObject.className != 'undefined' && this.domObject.className.toString() != '')
		this.xndObject.className = this.domObject.className

	if(typeof this.domObject.style.cssText != 'undefined' && this.domObject.style.cssText.toString() != '')
		this.xndObject.style.cssText = this.domObject.style.cssText;

	if(typeof this.domObject.SWRemote != 'undefined' && this.domObject.SWRemote.toString() != '')
		this.xndObject.FlashVars = this.domObject.SWRemote;

	if(typeof this.domObject.codebase == 'undefined' || this.domObject.codebase.toString() == '')
		this.xndObject.codebase = 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,24,0';

	if(typeof this.domObject.id != 'undefined' && this.domObject.id.toString() != '')
		this.xndObject.id = this.domObject.id;

};

ActivateObject.prototype.removeOriginalObject = function()
{
	this.domObject.parentNode.removeChild(this.domObject);
};

/*****************************************************************************
* ActivateObjectFlash Command
*///**************************************************************************
function ActivateObjectFlash(domObject)
{
	ActivateObject.call(this,domObject);
}
ActivateObjectFlash.prototype = new ActivateObject;
ActivateObjectFlash.prototype.aObjectProperty = ['FrameNum','Playing','Quality','Quality2','Scalemode','Scale','AlignMode','SAlign','BackgroundColor','BGColor','Loop','Movie','WMode','Base','DeviceFont','EmbedMovie','SWRemote','FlashVars','AllowScriptAccess'];
ActivateObjectFlash.prototype.classid = 'D27CDB6E-AE6D-11CF-96B8-444553540000';


/*****************************************************************************
* Script initialisation
*///**************************************************************************
if(typeof ActiveXObject != 'undefined' && typeof Function.call != 'undefined')
{
	var styleId = BackToTheHtml.uniqueID();
	document.write('<style id="' + styleId + '" ></style>');
	var domStyle = document.getElementById(styleId);

	var isHead = false;
	var aHead = document.getElementsByTagName('head');
	for(var i=0; i<aHead.length; i++)
		if(BackToTheHtml.isParentOf(aHead[i],domStyle))
			isHead = true;

	if(isHead)
	{
		document.write('<style type="text/css">OBJECT{visibility:hidden;}</style>');
		document.onreadystatechange = function()
		{
			if(document.readyState == 'complete')
			{
				new BackToTheHtml().execute();
				document.styleSheets[document.styleSheets.length-1].addRule("OBJECT","visibility:visible;");
				//alert('head');
				//alert(document.body.innerHTML);
			}
		}
	}
	else
	{
		new BackToTheHtml().execute();
		//alert('body');
		//alert(document.body.innerHTML);
	}
	
	domStyle.parentNode.removeChild(domStyle);
}
/* ajuster les hauteurs */
function greatSize(chaine){
	ret = chaine;
	try{
		ret = chaine.substring(0,chaine.length-2);
	}catch(e){}
	return ret;
}
function getStyle(el,styleProp)
{
	if (el.currentStyle)
		var y = el.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp);
	if(document.all && styleProp== 'height'){ return el.offsetHeight; }else{ 	return y; }
	
}
function ajusterHauteur(){
	try{
	var el;
	if(document.getElementById('page-contenu-accueil')!=undefined){el=document.getElementById('page-contenu-accueil');}else{el=document.getElementById('page-contenu');}
	var hauteur_ref = parseInt(greatSize(getStyle(el,'height')));
	if(document.all){ hauteur_ref = hauteur_ref - 11; } //Ajuster IE
	if(document.getElementById('fiche-actu')!=undefined){ // actualite
		if(document.all){
			document.getElementById('fiche-actu').style.height = (hauteur_ref-245)+'px';
		}else{
			document.getElementById('fiche-actu').style.height = (hauteur_ref-235)+'px';	
		}
	}
	document.getElementById('fiche-droite').style.height = (hauteur_ref-116)+'px';
	}catch(ex){}
}
if(document.all)
{
 window.attachEvent("onload", ajusterHauteur);
}
else
{
 window.addEventListener("load", ajusterHauteur, true);
}
/**/