// JavaScript Document
var initTiny = function()
{
	$j('#slider-code').tinycarousel({
		axis: 'x', display: 6, interval: true, intervaltime: 6000, rewind: true, infinite: true
	});
}

var InitToolTips = function()
{
	$j('.tipsy li a').tipsy({
		gravity: 'sw',
		title: function(){return $j(this).next().html();},
		html:true
	});
}

var initAgenda = function()
{
	var nb_elem_agenda = $j('#slider .slider_agenda ul li').length;
	$j('#slider').tinycarousel({
		axis: 'y', 
		display: 1,
		interval: true, 
		rewind: true, 
		infinite: true,
		intervaltime: 4000, 
		callback: function(element, index){
			if(index == parseInt(nb_elem_agenda-1))
			{
				setTimeout("$j('#slider').tinycarousel_move(1)", 3000);
				return false;
			}
		;}
	});	
}

var initFormMail = function()
{
	var input_mail_val = $j('#mail-newsletter').val();
	array_data = $j(this).serializeArray();
	$j.fancybox.showActivity();		
	$j.ajax({
		type	: "POST",
		cache	: false,
		url		: "/php/newsletter.php",
		data : "input_mail="+input_mail_val,
		success: function(data){
			$j('#fancybox-content').html(data);
		}
	});
	return false;
}

var ajustTitle = function()
{
	if($j('body').attr('id') == 'body-61')
	{
		var nb = $j('#content_center .blockmedia').length;
		$j('#content_center .blockmedia').each(function(e){
			if(e == 2)
				$j(this).find('h3').css('top', '-40px');
		});		
	}
}

var getSurvey = function(id_questionnaire)
{
	 var tab_selected_answer = new Array();
	 var selected_answer = '';
	 var choice = '';
	 $j("#form-votre-avis input").each(function(i){
		 if($j(this).attr('type') == 'radio')
		 {
		 	if($j(this).attr('checked') == 'checked')
		 	{
				selected_answer = $j(this).val();
				choice = selected_answer;
			}
		 }
		 else
		 {
			 if($(this).attr('checked') == 'checked')
		 	 {
			 	tab_selected_answer.push($j(this).val());
			 	choice = tab_selected_answer;
			 }
		 }
	 });
	if(choice != '')
	{
		$j.ajax({
			data: {choice: choice, id_questionnaire: id_questionnaire},
			type: "POST",
			url: "/php/ajax/get_survey.php",
			dataType: 'html',
			success: function(data){
				$j('.votre-avis .bg-content').css('padding', '0 0 25px 0');
				if($j('#form-votre-avis').html(data))	
					resizeBlock('.block-resize');	
			}
		});	
	}
}

var getOnloadSurvey = function(id_questionnaire)
{
	$('#form-votre-avis-onload').bind('click', function(){
		$j.ajax({
			data: {choice: choice, id_questionnaire: id_questionnaire},
			type: "POST",
			url: "/php/ajax/get_survey.php",
			dataType: 'html',
			success: function(data){
				//$j('.votre-avis .bg-content').css('padding', '0 0 25px 0');
				if($j('#form-votre-avis-onload').html(data))	
					resizeBlock('.block-resize');	
			}
		});	
	});
}

function resizeBlock(cible)
{
	var hauteur = 0;
 	var i  = 0;
 	/*calcul de la hauteur maximale*/
    $j(cible).each(function(){
			h=$j(this).height();	
		if(h>hauteur){hauteur=h;};
    });    

	/*attribution de hauteur a chaque div*/
	$j(cible).each(function(e){
		$j(this).height((hauteur));
	});		
}

var $j = jQuery.noConflict();
var initIframe = function()
{
	$j('iframe').each(function(){
		alert('loa');
		var urlsite = $j(this).attr("src");
		$j(this).attr("src",urlsite+"&wmode=transparent");
	});	
}

