// JavaScript Document

function stopEvent( event )
{
	event.stopImmediatePropagation();
	if (event.stopPropagation)event.stopPropagation();
	event.cancelBubble = true;
	if (event.preventDefault)event.preventDefault();
	event.returnValue = false;
	return false;
}

function activeSousMenu(){
	jQuery(document).ready(function(){
		jQuery('.activeSousMenu').mouseover(function(e){			
			var sousmenu = jQuery(e.target).children('ul');
			sousmenu.show();
			
			sousmenu.mouseleave(function(e){
				sousmenu.hide();
				sousmenu.unbind();
			});
		});
		
		jQuery('.activeSousMenu').mouseleave(function(e){			
			var sousmenu = jQuery(e.target).children('ul');
			sousmenu.hide();
		});
	});
}

function checkLen(areaId,maxLen,idqval)
{
	var currentValue = $(areaId).value;
	var currentLen = currentValue.length;
	$('textarea_maxlen_max'+idqval).update(maxLen-currentLen);
	$(areaId).value = currentValue.substr(0,249);
}
function annulation_enquete()
{
	new Ajax.Request('modules/poll/enquete-snvel.php?fc=annuler',
  		{
    		method:'post',
    		onSuccess: function(transport)
			{
        		var response = transport.responseText;
	  			$("popup2").update(response);
				end();
    		},
    		onFailure: function()
			{
				end();
			}
  	});	
}
function participer_enquete()
{
	new Ajax.Request('modules/poll/enquete-snvel.php?fc=participer',
  		{
    		method:'post',
    		onSuccess: function(transport)
			{
        		var response = transport.responseText;
	  			$("popup2").update(response);
				end();
    		},
    		onFailure: function()
			{
				end();
			}
  	});
}

function attente_enquete()
{
	new Ajax.Request('modules/poll/enquete-snvel.php?fc=attente',
  		{
    		method:'post',
    		onSuccess: function(transport)
			{
        		var response = transport.responseText;
	  			$("popup2").update(response);
				end();
    		},
    		onFailure: function()
			{
				end();
			}
  	});
}

function afficher_enquete()
{
	var height_body = $$('body')[0].getHeight();
	var width = $$('body')[0].getWidth();
	$$('body')[0].appendChild(Builder.node('div',{id:'overlay2'}));//ajout d'un élément
	$$('body')[0].setStyle({overflow:"hidden"});
	$('overlay2').setStyle({width:"100%",height:height_body+"px",background:"#000000",top:"0px",left:"0px",zIndex:9000, position:"absolute",display:"none"});
	new Effect.Appear('overlay2', { queue: 'end', duration: 0.3, from:0, to:0.8 });
	
	$$('body')[0].appendChild(Builder.node('div',{id:'popup2'}));//ajout d'un élément
	$('popup2').setStyle({border:"1px solid black",width:"600px",height:"320px",background:"#ffffff",top:((height_body-500)/2)+"px",left:((width-500)/2)+"px",zIndex:9001, position:"absolute",display:"none"});
	new Effect.Appear('popup2', { queue: 'end', duration: 0.3, from:0, to:1 });
	
	new Ajax.Request('modules/poll/enquete-snvel.php',
  		{
    		method:'post',
    		onSuccess: function(transport)
			{
        		var response = transport.responseText;
	  			$("popup2").update(response);
    		},
    		onFailure: function()
			{
				end();
			}
  	});
	/*$('overlay2').observe("click",function(event)
	{
		end();
	})*/
}

function annulation_enquete_ssURL()
{
	var stringToPost = $('cancelPoll').serialize();
	new Ajax.Request('modules/poll/index.php?fc=cancel',
  		{
    		method:'post',
			parameters:stringToPost,
    		onSuccess: function(transport)
			{
        		var response = transport.responseText;
	  			$("popup2").update(response);
				end();
    		},
    		onFailure: function()
			{
				end();
			}
  	});	
}

function validation_enquete_ssURL()
{
	var stringToPost = $('validPoll').serialize();
	new Ajax.Request('modules/poll/index.php?file=poll&fc=valid',
  		{
    		method:'post',
			parameters:stringToPost,
    		onSuccess: function(transport)
			{
        		var response = transport.responseText;
	  			$("popup2").update(response);
				//alert(response);
				end();
    		},
    		onFailure: function()
			{
				end();
			}
  	});	
}

function end()
{
	$('overlay2').remove();
	$("popup2").remove();
	$$('body')[0].setStyle({overflow:"auto"});	
}

function anim_bandeau(){

	var arr =  $('bandeau_categories').childElements();
	arr.each(function(node,i){
	if ($(node).fade) {
		if (i == 0){
			$(node).fade({ to: 0.0001 });
			$('bandeau_categories').insert("<div style='color:"+node.getStyle('color')+"'>"+node.innerHTML+"</span>");
			
			Effect.BlindUp(node,{
				duration:1,
				afterFinish: function(){
					$(node).remove();
				}
			});
		}
		
		if (i == 1)
			$(node).fade({ duration: 1, to: 0.0001 });
		if (i == 2)
			$(node).fade({ duration: 1, to: 0.2 });
		if (i == 3)
			$(node).fade({ duration: 1, to: 1 });
		if (i == 4)
			$(node).fade({ duration: 1, to: 0.2 });
		if (i == 5)
			$(node).fade({ to: 0.0001 });
		if (i == 6)
			$(node).fade({ to: 0.0001 });
	}
			
	});
}

function pre_anim_bandeau(){
	if($('bandeau_categories')){
		var arr =  $('bandeau_categories').childElements();
		arr.each(function(node,i){
			if (i == 0)
				$(node).fade({ duration: 0.0001, to: 0.0001 });
			if (i == 1)
				$(node).fade({ duration: 0.0001, to: 0.2 });
			if (i == 2)
				$(node).fade({ duration: 0.0001, to: 1 });
			if (i == 3)
				$(node).fade({ duration: 0.0001, to: 0.2 });
			if (i == 4)
				$(node).fade({ duration: 0.0001, to: 0.0001 });
			if (i == 5)
				$(node).fade({ duration: 0.0001, to: 0.0001 });
			if (i == 6)
				$(node).fade({ duration: 0.0001, to: 0.0001 });
	
		});
		timer = setInterval('anim_bandeau()',3000);
	}
}

document.observe("dom:loaded", function() {
	pre_anim_bandeau();
});


function cacher_pdf_com(){
	$('overlay3').setStyle({display:"none"});
	$('popup3').setStyle({display:"none"});
}
function afficher_pdf_com()
{
	var height_body = $$('body')[0].getHeight();
	var width = $$('body')[0].getWidth();
	// $$('body')[0].appendChild(Builder.node('div',{id:'overlay3'}));//ajout d'un élément
	// $$('body')[0].setStyle({overflow:"hidden"});
	// $('overlay3').setStyle({width:"100%",height:"100%",background:"#000000",top:"0px",left:"0px",zIndex:9000, position:"absolute",display:"none",top:"0px",bottom:"0px"});
	new Effect.Appear('overlay3', { queue: 'end', duration: 0.3, from:0, to:0.8 });
	
	// $$('body')[0].appendChild(Builder.node('div',{id:'popup3'}));//ajout d'un élément
	$('popup3').setStyle({top:"10px",left:((width-800)/2)+"px"});
	new Effect.Appear('popup3', { queue: 'end', duration: 0.3, from:0, to:1 });
	
	$("popup3").update('<span onclick="cacher_pdf_com()" style="position:relative;left:8px;top:3px;font-size:14px;font-weight:bold;color:#FFFFFF;cursor:pointer">FERMER</span><object width="width:100%" height="height:100%"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="livre_pdf_com/megazine.swf" /><embed src="livre_pdf_com/megazine.swf" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="100%" height="100%"></embed></object>');
}

function afficher_video()
{
	var largeur = $$('body')[0].getWidth();
	var hauteur = $$('body')[0].getHeight();
	
	var Ascroll = document.viewport.getScrollOffsets();
	var scrollY = Ascroll[1];

	//alert(scrollY);

	$$('body')[0].appendChild(Builder.node('div',{id:'overlayEVT'}));
	$$('body')[0].appendChild(Builder.node('div',{id:'overlayEVT2'}));
	
	$$('body')[0].setStyle({overflow:"hidden"});
	
	window.onresize = redim;
	$('overlayEVT').observe("click",end);
	
	$('overlayEVT').setStyle({
		zIndex:9100,
		top:scrollY+"px",
		left:"0px",
		position:"absolute",
		display:"block",
		backgroundColor:"#000000",
		width:largeur+"px",
		height:hauteur+"px",
		overflow:"auto",
		opacity:"0.5"
	});

	var topDiv = (hauteur-500)/2;
	var leftDiv = (largeur-700)/2;
	
	$('overlayEVT2').setStyle(
	{
		zIndex:9100,
		top:scrollY+topDiv+"px",
		left:leftDiv+"px",
		position:"absolute",
		display:"block",
		backgroundColor:"#FFFFFF",
		width:"700px",
		height:"520px",
		overflow:"auto"
	});
	
	$("overlayEVT2").update('<table style="width:100%; height:100%; text-align:center;"><tr><td style="height:20px; text-align:right;"><span onclick="end()" style="text-decoration:underline;font-weight:bold;color:#000000;cursor:pointer">Fermer</span></td></tr><tr><td><object type="application/x-shockwave-flash" data="video/player_flv.swf" width="690" height="460"><embed src="video/player_flv.swf" width="690" height="460"></embed><param name="movie" value="video/player_flv.swf" /><param name="FlashVars" value="flv=clip_SAPV.flv&amp;width=690&amp;height=460&amp;autoplay=1&amp;showstop=1&amp;showvolume=1&amp;showtime=1" /></object></td></tr><tr><td style="text-align:center;height:20px;"><a target="_blank" href="http://www.sapv.fr/SITESVETO/" style="text-decoration:underline;font-weight:bold;color:#000000;cursor:pointer;">Plus d\'information ici</a></td></tr></table>');

}

function redim()
{
	var largeur = $$('body')[0].getWidth();
	var hauteur = $$('body')[0].getHeight();
	
	$('overlayEVT').setStyle({
		width:largeur+"px",
		height:hauteur+"px"
	});
}

function end()
{
	$("overlayEVT").remove();
	$("overlayEVT2").remove();
	$$("body")[0].setStyle({overflow:"auto"});
}
