var mainPath = 'fileadmin/templates/';
var cookieName = 'showEdito3';
var cookieDomain = 'greenwall.fr';
var urlPopup = 'http://greenwall.fr/index.php?id=37&no_cache=1';

var Edito = {
	
	showPopup:true,
	
	init:function()
	{
		var that = this;
		this.overlay = new Element('div', {id:'editoOverlay'}).inject(document.body);
		this.edito = new Element('div', {id:'editoContainer'}).inject(this.overlay, 'after'); 
		this.edito.setHTML('');
		this.overlay.setStyle('display','none');
		this.overlay.setStyle('opacity',0);
		this.edito.setStyle('display','none');
		this.edito.setStyle('opacity',0);
		//Cookie.set(cookieName,0,{'duration':30, 'domain':cookieDomain, path:'/'});
		that.showEdito();
	},
	
	showEdito:function()
	{
		var that = this;
		this.overlay.setStyle('display','block');
		this.edito.setStyle('display','block');
		var tw = new Fx.Style(that.overlay, 'opacity').start(0,1).chain(function() {
			var f = new Fx.Style(that.edito, 'opacity').start(0,1);
		});
		
		this.template = this.loadPage(mainPath + 'EditoTemplate.html', {
			onComplete:function(r)
			{
				
				that.edito.setHTML(r);
				that.editoContent = that.edito.getElement('#editoContenu');
				
				that.content = that.loadPage(mainPath + 'pop_news3.html', {
				//that.content = that.loadPage(urlPopup, {
					onComplete:function(c)
					{
						that.editoContent.setHTML(c);
						// Ajout Yann -- DEBUT
						var flashvars =
						  {
							'soundFile': 'fileadmin/user_upload/mur-vegetal-videos/47terrien.mp3',
						  };
					
						  var params =
						  {
							  wmode:"transparent",
							'allowscriptaccess':  'always'
						  };
						swfobject.embedSWF("fileadmin/templates/flash/a_player.swf", "audioplayer", "240", "28", "9.0.0", false, flashvars, params);
						
						
						// Ajout Yann -- FIN
						
						
						
						that.closeBt = that.edito.getElement('#editoFermer');
						that.closeBt.addEvent('click', function(e)
						{
							new Event(e).stop(); 
							that.hideEdito();
						});
						that.dontShowBt = that.edito.getElement('#editoDontShowAgain');
						that.dontShowBt.addEvent('click', function(e)
						{
							new Event(e).stop(); 
							that.toggleShowOrNot(this);
						});
						that.checkEditoDontShowAgainStatus();
					}
				});
			}
		});
	},
	
	loadPage:function(url, options)
	{
		var myRequest = new Ajax (url,
		{
			method: 'get', encoding:'iso-8859-1',
			onSuccess:function(html)
			{
				if(options.onComplete)
				{
					options.onComplete(html);
				}
				if(options.target)
				{
					options.target.set('html', html);
				}
			},
			onFailure : function(t)
			{
				if(options.target)
				{
					options.target.set('html', '<h3>Impossible de charger le formulaire !');
				}
			}
		});
		myRequest.request();
	},
	
	hideEdito:function()
	{
		var that = this;
		
		this.edito.setStyle('height',350);
		this.edito.setHTML('');
		
		var tw = new Fx.Style(that.edito, 'opacity').start(1,0).chain(function() {
			var f = new Fx.Style(that.overlay, 'opacity').start(1,0);
		});

	},
	
	toggleShowOrNot:function(el)
	{
		if(this.showPopup)
		{
			Cookie.set(cookieName,0,{'duration':30, 'domain':cookieDomain, path:'/'});
		}else{
			Cookie.set(cookieName,1,{'duration':30, 'domain':cookieDomain, path:'/'});
		}
		this.checkEditoDontShowAgainStatus();
	},
	
	checkEditoDontShowAgainStatus:function()
	{
		if(cook = Cookie.get(cookieName))
		{
			if(cook == 1)
			{
				this.showPopup = true;
			}else if(cook==0){
				this.showPopup = false;
			}
		}
		if(this.showPopup)
		{
			this.dontShowBt.removeClass('dontShow');
		} else {
			this.dontShowBt.addClass('dontShow');
		}
	},
	
}
/*
window.addEvent('domready',function()
{
	
	var cook = 1;
	
	if(Cookie.get(cookieName))
	{
		cook = Cookie.get(cookieName);
	}
	
	if(cook == 1)
	{
		Edito.init.delay(1500, Edito);
	}
	
});
*/
