if(typeof(Ext) != 'undefined'){
	Ext.BLANK_IMAGE_URL = '../ui/js/extjs/resources/images/default/s.gif';
	Ext.onReady(function(){
		//gestion de l'affichage de la pub pour les RDV
		if(Ext.get('pubRDV')){
			//on récupère l'image associée à la balise
			var image = Ext.get('pubRDV').dom.innerHTML;
			var id_artPubRDV = Ext.get('id_artPubRDV').dom.innerHTML;
			//on supprime le contenu de pubRDV
			Ext.get('pubRDV').dom.innerHTML = '';
			//testons si le cookie existe
			var monCookie = GetCookie('dernier_rappel_'+id_artPubRDV);
			if(!monCookie){
			
				var window = new Ext.Window({
					id: 'window_pubRDV',
					cls: 'simple_window',
					width: 715,
					height: 308,
					buttonAlign:'right',
					resizable: false,
					closable: false,
					draggable: false,
					shadow: true,
					html : image
				});
				window.on('show', function(){
					Ext.select('#window_pubRDV img').each(function(){
						this.fadeIn({
							endOpacity: 1, //can be any value between 0 and 1 (e.g. .5)
							easing: 'easeOut',
							duration: 2
						});
					});
				});
				window.show();
				Ext.select('#window_pubRDV img').each(function(){
					this.on('click', function(){
						this.fadeOut({
							endOpacity: 0, //can be any value between 0 and 1 (e.g. .5)
							easing: 'easeOut',
							duration: 2, 
							callback: function(){
								window.close()
							}
						});
					});
				});
			}
			//on créé alors le cookie, une fois que la pub a été affichée
			var pathname = location.pathname;
			var myDomain = pathname.substring(0,pathname.lastIndexOf('/')) +'/';
			var date_exp = new Date();
			date_exp.setTime(date_exp.getTime()+(15*24*3600*1000));
			// Ici on définit une durée de vie de 15 jours
			SetCookie('dernier_rappel_'+id_artPubRDV, 1,date_exp,myDomain);
		}
		Ext.select('.window_bd', true).each(function(){
			this.on('click', function(){
				var temp_id = this.dom.id.split('_');
				//id bande annonce
				var id_ba = temp_id[2];
				//site d'affichage de la bande annonce
				var site_ba = temp_id[1];
				var temp_contenu_ba = Ext.fly('c_'+site_ba+'_'+id_ba).dom.innerHTML.split('_');
				var contenu_ba = temp_contenu_ba[1];
				afficher_bandeAnnonce(this, id_ba, contenu_ba, 'window_mc_'+temp_contenu_ba[0], temp_contenu_ba[0], site_ba);
				return false;
			});
		});
	})
	
	function SetCookie (name, value) {
		var argv=SetCookie.arguments;
		var argc=SetCookie.arguments.length;
		var expires=(argc > 2) ? argv[2] : null;
		var path=(argc > 3) ? argv[3] : null;
		var domain=(argc > 4) ? argv[4] : null;
		var secure=(argc > 5) ? argv[5] : false;
		document.cookie=name+"="+escape(value)+
			((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
			((path==null) ? "" : ("; path="+path))+
			((domain==null) ? "" : ("; domain="+domain))+
			((secure==true) ? "; secure" : "");
	}
	
	function getCookieVal(offset) {
		var endstr=document.cookie.indexOf (";", offset);
		if (endstr==-1)
				endstr=document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
	}
	function GetCookie (name) {
		var arg=name+"=";
		var alen=arg.length;
		var clen=document.cookie.length;
		var i=0;
		while (i<clen) {
			var j=i+alen;
			if (document.cookie.substring(i, j)==arg)
							return getCookieVal (j);
					i=document.cookie.indexOf(" ",i)+1;
							if (i==0) break;}
		return null;
	}
	
	function afficher_bandeAnnonce(lien, id, contenu, classeCouleur, couleur, typeSite){
		if(typeSite == 'ft'){
			var contenu_final = '<object width="640" height="360"><param name="movie" value="http://www.player.filmtrailer.com/v3.4/player.swf?file=http://fr.player-feed.previewnetworks.com/cinema/'+id+'/331100134-1/&display_title=always&menu=true&enable_link=true&default_quality=xxlarge&controlbar=over&autostart=true&backcolor=000000&frontcolor=7F7F7F&share=1&repeat=always&volume=80&linktarget=_blank"/><param name="wmode" value="transparent" /><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><embed id="player" name="player" type="application/x-shockwave-flash" src="http://www.player.filmtrailer.com/v3.4/player.swf?file=http://fr.player-feed.previewnetworks.com/cinema/'+id+'/331100134-1/&display_title=always&menu=true&enable_link=true&default_quality=xxlarge&controlbar=over&autostart=true&backcolor=000000&frontcolor=7F7F7F&share=1&repeat=always&displayclick=play&volume=80&linktarget=_blank" width="640" height="360"allowFullScreen="true" allowScriptAccess="always"></embed></object><br /><p id="footer_window">'+contenu+'</p>';
		}else if(typeSite == 'allo'){
			var contenu_final = '<div style="width: 420px; height: 335px; margin: 0 auto;"><object width="100%" height="100%"><param name="movie" value="http://www.allocine.fr/blogvision/'+id+'"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.allocine.fr/blogvision/'+id+'" type="application/x-shockwave-flash" width="100%" height="100%" allowFullScreen="true" allowScriptAccess="always"/></object></div><br /><p id="footer_window">'+contenu+'</p>';
		}//creates window
		var window = new Ext.Window({
			id: 'window_ba',
			cls: 'simple_window '+classeCouleur,
			animateTarget: lien,
			width: 706,
			height: 491,
			buttonAlign:'right',
			resizable: false,
			closable: true,
			draggable: false,
			modal: true,
			title: '<img src="../IMG/ext_window/'+couleur+'_title.png" alt="Bande Annonce" />',
			html : '<div id="bodywindow_ba">'+contenu_final+'</div>'
		});
		window.show();
		Ext.select('.ext-el-mask', true).each(function(){
			this.on('click', function(){
				window.close();
			});
		});
		return false;
	}
}
window.onload=function(){
	if($('bloc_6affiches')){
		var collection_panneaux = $$('.panneau6Affiches');
		var taille_tableau = collection_panneaux.length;
		if(taille_tableau > 0){
			var panneau0 = $('panneau0');
			panneau0.setStyle({display: 'block'});
			var programme_suivant = $('programme_suivant');
			programme_suivant.setStyle({display: 'block'});
			programme_suivant.onclick = function(){
				return defilerPanneau();
			}
		}
	}
}

function defilerPanneau(){
	var collection_panneaux = $$('.panneau6Affiches');
	var taille_tableau = collection_panneaux.length;
	var indice = 0;
	var arr_indice = 0;
	collection_panneaux.each(function(panneau){
		if(panneau.getStyle('display') == 'block'){
			arr_indice = panneau.id.split('panneau');
		}
	});
	if(taille_tableau > 0){
		$('panneau' + arr_indice[1]).setStyle({display: 'none'});
		indice = parseInt(arr_indice[1]) + 1;
		if(indice <= taille_tableau -1){
			$('panneau' + indice).setStyle({display: 'block'});
		}else{
			$('panneau0').setStyle({display: 'block'});
		}
	}
	return false;
}
