monslider = 0;
nextslide = 2;
function cobaslider(divid, duree){
	$(divid).find('.slide').hide();
	$(divid).find('.slide .caption').hide();
	$(divid).find('.slide').removeClass('current');
	$(divid).find('.slide:first').addClass('current');	

	$(divid).find('.slide:first').fadeIn(500, function(){
		$(this).find('.caption').slideDown(500);												 
	});
	
	// Nombre de slide : nbslide
	nbslide = 0; 
	var titre = new Array();
	$(divid).find('.slide').each(function(){
		titre[nbslide] = $(this).find('h2').text();
		nbslide++;
	});
	
	// Petits points
	$(divid).append('<div class="pagination"></div>');
	points = '';
	for(i=1; i<=nbslide; i++){
		title = titre[parseInt(i-1)];
		points += '<a href="#" title="'+title+'" class="point point_'+i+'">'+i+'</a>';
	}
	$(divid+' .pagination').html(points);
	$(divid+' .pagination .point:first').addClass('current');
	$(divid+' .pagination .point').click(function(){
		var txt_class = $(this).attr('class');
		var classz = txt_class.split(" ");
		
		for(j=0; j<classz.length; j++){
			var nom = classz[j].split('_');
			if(nom[0] == 'point' && !isNaN(nom[1])){
				clearInterval(monslider);
				nextslide = nom[1];
				monslider = setInterval(swapslider, parseInt(duree*1000), divid);
				swapslider(divid);
			}
		}
	
	});

	monslider = setInterval(swapslider, parseInt(duree*1000), divid);
	
	init_tooltip(divid+" a");
	
	// Pause sur le RollOver
	$(divid).live('mouseenter', function(){
		clearInterval(monslider);			
		monslider = 0;
	});
	$(divid).live('mouseleave', function(){
		if(monslider == 0) monslider = setInterval(swapslider, parseInt(duree*1000), divid);							   
	});
	
}

function swapslider(divid){

	if(!divid) divid = '#slider'; // FUCKING IE 
	slidetoshow = (arguments.length==2) ? arguments[1] : nextslide;
	if(!slidetoshow || slidetoshow <= 0 || slidetoshow > nbslide) slidetoshow = nextslide;
	$(divid).find('.slide.current').fadeOut(800, function(){
		$(this).removeClass('current');	
		$(divid+' .pagination .point').removeClass('current');
		$(this).find('.caption').hide();	
		
		cpt = 0;
		$(divid).find('.slide').each(function(){
			cpt++;
			if(cpt == slidetoshow){
				$(this).addClass('current');
				$(divid+' .pagination .point_'+cpt).addClass('current');
				$(this).fadeIn(500, function(){
					$(this).find('.caption').slideDown(800);								 
				});
			}
		});
		
		nextslide++;
		if(nextslide > nbslide){ nextslide = 1; }
	
	});
}


/* COBABOX ---------------------------------------------------------- */
function cobabox(w, h, u){
	var hauteur = document.body.offsetHeight;
	var largeur = document.body.offsetWidth;
	$('#cobabox').css('height', hauteur+'px');
	$('#cobabox').html ("<div id='fermeur' style='z-index: 10; position: absolute;'></div>"
		+"<div id='cobabox_cont' style='width:"+parseInt(parseInt(w)+20)+"px; height:"+parseInt(parseInt(h)+20)+"px; z-index: 1000; display:none;' class='dropshadow2'>"
		+"<iframe class='r5' src='"+u+"' width='"+w+"' height='"+h+"' frameborder='0'></iframe>"
		+"<a href='#' id='fermer_cobabox_btn' class='fermer_cobabox_btn' onClick='fermer_cobabox(); return false;'>Close</a>"
		+"</div>");
	$('#cobabox').fadeIn();
	$('#cobabox_cont').css('left', parseInt((largeur-w)/2)+"px");		
	$('#cobabox_cont').slideDown();
	$('#fermeur').css('height', hauteur+'px');
	$('#fermeur').css('width', '100%');

	//var depart = window.pageYOffset;
	//if(!depart) depart = document.documentElement.scrollTop;
	depart = 0;
	var windowheight = window.innerHeight; 
	if(!windowheight) windowheight = document.documentElement.clientHeight;
	var postop = depart+((windowheight-h)/2);
    if(postop<0) postop = 35;
	$('#cobabox_cont').css('top', postop+"px");	
	$('embed').css('visibility', 'hidden');
	$('object').css('visibility', 'hidden');	
}
document.bloquer_fermeture_cobabox = '0';
function fermer_cobabox(){
	if(document.bloquer_fermeture_cobabox == '0'){
		
		$('#cobabox_cont').slideUp(500, function(){
			$('#cobabox').html('');
			$('#cobabox').fadeOut(500);
			$('embed').css('visibility', 'visible');
			$('object').css('visibility', 'visible');	
		});
		return false;	
	}
}
function cobabox_locker(){
	window.parent.document.getElementById("fermer_cobabox_btn").style.display = "none";
	window.parent.document.bloquer_fermeture_cobabox = '1';
}
function cobabox_unlocker(){
	window.parent.document.getElementById("fermer_cobabox_btn").style.display = "block";
	window.parent.document.bloquer_fermeture_cobabox = '0';
}
function resize_cobabox(pwidth){
	// argument optionnel : pheight
	var pheight = (arguments.length==2) ? arguments[1] : '';
	w = parseInt(pwidth);
	animduration = 500;
	largeur = window.parent.document.body.offsetWidth;
	$("#cobabox_cont iframe", window.parent.document).animate({ width: (w+20)+'px'}, animduration);
	$("#cobabox_cont", window.parent.document).animate({width:(w+40)+'px', left: parseInt((largeur-w)/2)+"px"},animduration);

	if(pheight){
		h = parseInt(pheight);
		var hauteur = window.parent.innerHeight; 
		$("#cobabox_cont iframe", window.parent.document).animate( { height: (h+20)+'px'}, animduration);
		$("#cobabox_cont", window.parent.document).animate({height: (h+40)+'px', top: parseInt((hauteur-h)/2)+"px"}, animduration);
	}
}
function init_cobabox(){
	$('a[rel^=cobabox]').click(function(){								
		vars = $(this).attr('rel').split(" ");
		url = $(this).attr('href');
		cobabox(vars[1], vars[2], url);
		return false;
	});		
}

// AFFICHER UN FLASH SANS BORDURES POUR IE ---------------------------------------------------------------- >>
function flash(width, height, src, wmode){
	var asa = (arguments.length==5) ? arguments[4] : 'never';
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
		+ 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" '
		+ 'width="'+width+'" height="'+height+'">'
		+ '<param name="movie" value="'+src+'" />'
		+ '<param name="quality" value="high" />'
      	+ '<param name="wmode" value="'+wmode+'" />'
      	+ '<param name="allowScriptAccess" value="'+asa+'" />'	
		+ '<param value="true" name="allowFullScreen">'	
		+ '<embed src="'+src+'" width="'+width+'" height="'+height+'" quality="high"'
		+ ' pluginspage="http://www.macromedia.com/go/getflashplayer" '
		+ 'type="application/x-shockwave-flash" wmode="'+wmode+'" allowScriptAccess="'+asa+'" allowfullscreen="true"></embed>'
		+ '</object>');
}

function verif_email(email){
	var place = email.indexOf("@",1);
	var point = email.indexOf(".",place+1);
	if ((place > -1)&&(email.length >2)&&(point > 1)) return(true);
	else return(false);
}

function display_message(mess){
	//alert(mess);
	var hauteur = document.body.offsetHeight;
	var largeur = document.body.offsetWidth;
	$('#cobabox').css('height', hauteur+'px');
	$('#cobabox').html ("<div id='fermeur' style='z-index: 10; position: absolute;'></div>"
		+"<div id='cobabox_cont' style='width:400px; height:200px; z-index: 1000; display:none;' class='dropshadow2'>"
		+"<div class='message'><table height='100%'><tr><td>"
		+mess
		+"</td></tr></table></div>"
		+"<a href='#' id='fermer_cobabox_btn' class='fermer_cobabox_btn' onClick='fermer_cobabox(); return false;'>Close</a>"
		+"</div>");
	$('#cobabox').fadeIn();
	$('#cobabox_cont').css('left', parseInt((largeur-400)/2)+"px");		
	$('#cobabox_cont').css('top', "200px");		
	$('#cobabox_cont').slideDown();
}
$(function(){
	init_cobabox();	   
});
