var effect1=null;
var effect2=null;
var idactu=1;
var timerActu=null;
var idprec=null;
var player=null;

var globaleval =  function(script){
  if(window.execScript){
    return window.execScript(script);
  } else if(navigator.userAgent.indexOf('KHTML') != -1){ //safari, konqueror..
      var s = document.createElement('script');
      s.type = 'text/javascript';
      s.innerHTML = script;
      document.getElementsByTagName('head')[0].appendChild(s);
  } else {
    return window.eval(script);
  }
}

function log(str){
	if (window.console) {
		console.log(str);
	}
}
function load_page_ajax_appear(page){
	new Effect.Fade('contenu', { from:1.0,to:0.1,afterFinish: function () {
		new Ajax.Updater('contenu', page, {
		  parameters: 'mode_ajax=1',
		  onComplete: new Effect.Appear('contenu')
		});
	}});
	return false;
}
//sheker
function load_page_ajax_sheker(page){
	new Ajax.Updater('contenu', page, {
	  parameters: 'mode_ajax=1',
	  onComplete: new Effect.Shake('contenu')
	});
	return false;
}
function load_page_ajax(page){
	//player.pause_diapo();
		new Ajax.Request(page, {
		  parameters: 'mode_ajax=1',
		  onComplete: function (x){
			if(!!player){
				player.destruct();
			}
		 	var scripts = x.responseText.extractScripts();
		 	$('contenu').innerHTML=x.responseText;
		 	initLightbox();
			var r = scripts.map(function(script) {
				return globaleval(script);
			});
		  }
			
		});
	return false;
}

function apparait(id){
	/*$('txt_'+id).show();
	return false;*/
	if(effect1){
		effect2.cancel();
		effect1.cancel();
	}
	if(idprec){
		$('txt_'+idprec).hide();
		$('txt_'+idprec).style.top='0px';
	}
	$('txt_'+id).style.top='0px';
	$('txt_'+id).style.height='170px';
	$('txt_'+id).hide();
	//overflow: hidden; top: -100px; left: 0px; height: 100px;
	var effect1=new Effect.SlideUpIn('txt_'+id, { duration: 0.5});
	idprec=id;
}
function disparait(id){
/*$('txt_'+id).hide();
	return false;*/
	if(effect2){
		effect2.cancel();
	}
	$('txt_'+id).style.top='-170px';
	$('txt_'+id).style.height='170px';
	$('txt_'+id).show();
	var effect2=new Effect.SlideDownOut('txt_'+id, { duration: 0.5});
	idprec=id;
}




function actu_precedent(){
	if($('actu_'+parseInt(idactu-1))!=undefined){
		if($('actu_'+idactu)!=undefined){
			$('actu_'+idactu).hide();
			$('suivant_actu').show();
		}
		if($('actu_'+parseInt(idactu+1))!=undefined)
			$('actu_'+parseInt(idactu+1)).hide();
		
		if($('actu_'+parseInt(idactu-1))!=undefined)
			$('actu_'+parseInt(idactu-1)).show();
			
		if($('actu_'+parseInt(idactu-2))==undefined)
			$('precedent_actu').hide();
			
		idactu=parseInt(idactu-1);
		
	}
}
function actu_suivant(){
	if($('actu_'+parseInt(idactu+1))!=undefined){
		if($('actu_'+idactu)!=undefined){
			$('actu_'+idactu).hide();
			$('precedent_actu').show();
		}
		$('actu_'+parseInt(idactu+1)).show();	
			
		if($('actu_'+parseInt(idactu+2))==undefined)
			$('suivant_actu').hide();
		idactu=idactu+1;
	}
}

function actu_timer(){
	if(timerActu!='stop')
		actu_suivant();
}

Effect.SlideUpIn = function(element) {
/* 
	SlideUpIn need to have the content of the element wrapped in a container element with fixed height!
*/
	element = $(element).cleanWhitespace();
	var elementDimensions = element.getDimensions();
	return new Effect.Parallel ( [
		new Effect.Move(element, { y: -(element.getHeight()), sync: true, mode: 'absolute' }),
		new Effect.Scale(element, 100, 
			Object.extend({
				sync: true,
				scaleContent: false,
				scaleX: false,
				scaleFrom: 0,
				scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
				beforeSetup: function(effect) {
					effect.element.hide();
				},
				afterSetup: function(effect) {
					effect.element.makeClipping().setStyle({height: '0px'}).show();
				},
				afterFinishInternal: function(effect) {
					effect.element.undoClipping();
				}
			}, arguments[1] || {})
		)
	], Object.extend({
		afterSetup: function(effect) {
			effect.effects[0].element.setStyle({top: elementDimensions.height + 'px' });
		}
	}, arguments[1] || {}));
}


Effect.SlideDownOut = function(element) {
/* 
	SlideDown need to have the content of the element wrapped in a container element with fixed height!
*/
	element = $(element).cleanWhitespace();
	var elementDimensions = element.getDimensions();
	return new Effect.Parallel ( [
		new Effect.Move(element, { y: element.getHeight(), sync: true, mode: 'relative' }),
		new Effect.Scale(element, 0,
			Object.extend({ 
				sync: true,
				scaleContent: false,
				scaleX: false,
				restoreAfterFinish: true,
				beforeSetup: function(effect){
					effect.element.makeClipping();
				},
				afterFinishInternal: function(effect) {
					effect.element.hide().undoClipping();
				}
			}, arguments[1] || {})
		)
	], Object.extend({
	}, arguments[1] || {}));
}

function checketoile(varthis,idimg,input){
	if(varthis.checked){
		for(i=1;i<6;i++){
			if(i>idimg){
				$('etoile_'+input+'_'+i).removeClassName('star');
				$('etoile_'+input+'_'+i).addClassName('stard');
			}else{
				$('etoile_'+input+'_'+i).removeClassName('stard');
				$('etoile_'+input+'_'+i).addClassName('star');
			}
		}
	}
}

function countCheck(){
	var i=0;
	$$('#conteneur_postes input').each(function(e){
		if(e.checked){
			i++;
		}
	});
	return i;
}

