/*************************
* NouveauProjet          *
* Foctions JS 			 *
*************************/

var img_loader = '<img src="/images/ajax-loader.gif" width="16" height="16">';

var hpDiapoCur = 1;
var hpSlideNb;

//Modales images 
$(function() {
    $('.imgModal').nyroModal();
});
/*
function hpDiapoNext()
{
	if(hpDiapoCur >= hpSlideNb)	
	{
		hpDiapoCur = 1;
	}
	else
	{
		hpDiapoCur ++;
	}
	hpDiapoScroll(hpDiapoCur);
}

function hpDiapoPrev()
{
	if(hpDiapoCur == 1)	
	{
		hpDiapoCur = hpSlideNb;
	}
	else
	{
		hpDiapoCur --;
	}
	hpDiapoScroll(hpDiapoCur);
}

function hpDiapoScroll(scrollNum)
{
	$('div#diapo').stop().scrollTo( $('#hpSlide'+(scrollNum)), 1000, {axis:'x'} );//Scrolling	
}

var hpDiapoTimer;
var hpDiapoStatus = 0;
function hpDiapoStart(periodicite)
{
	clearInterval(hpDiapoTimer);
	hpDiapoTimer = setInterval ( "hpDiapoNext()" , periodicite*1000 );
	hpDiapoStatus = 1;
}

function hpDiapoStop()
{
	clearInterval(hpDiapoTimer);
	hpDiapoStatus = 0;
}

var hpControlTimer;
function hpDiapoControlHide()
{
    clearTimeout(hpControlTimer);
	hpControlTimer = setTimeout(function(){ 	$( "#diapoController" ).fadeOut(); }, 500);
}

function hpDiapoControlShow()
{
    clearTimeout(hpControlTimer);
	hpControlTimer = setTimeout(function(){ 	$( "#diapoController" ).fadeIn(); }, 500);
}
*/
function hpNewsNext()
{
	$('#newsConteneur').fadeOut();
	
	setTimeout(function(){ 	
		$.ajax({
		  url: 'index-bg-news.php',
		  type: 'POST',
		  data: 'sens=next',
		  dataType: 'html',
		  success: function(data) 
		  {
				$('#newsPDF').html(data);
				$('#newsConteneur').fadeIn();
		  }
		});
	
	 }, 1000);
	
	
}

function hpNewsPrev()
{
	$('#newsConteneur').fadeOut();
	
	setTimeout(function(){ 	
		$.ajax({
		  url: 'index-bg-news.php',
		  type: 'POST',
		  data: 'sens=prev',
		  dataType: 'html',
		  success: function(data) 
		  {
				$('#newsPDF').html(data);
				$('#newsConteneur').fadeIn();
		  }
		});
	
	 }, 1000);
}

var hpNewsTimer;
var hpNewsStatus = 0;
function hpNewsTimerStart(periodicite)
{
	clearInterval(hpNewsTimer);
	hpNewsTimer = setInterval ( "hpNewsNext()" , periodicite*1000 );
	hpNewsStatus = 1;
}

function hpNewsTimerStop()
{
	clearInterval(hpNewsTimer);
	hpNewsStatus = 0;
}

function vdoPlayer(ID_media)
{
   $.nyroModalManual({
      url: '/video-reader.php?ID='+ID_media
    });	
	
	//setTimeout(function(){VideoJS.setupAllWhenReady();}, 1000)    
}

//Page reports
function reportsShowLoad(divLoad, date_start, date_end, titre)
{
	$('#'+divLoad).html(img_loader+' Chargement en cours...');
	
	$.ajax({
      url: 'reports-results-media-list-by-date.php',
      type: 'POST',
      data: 'dt_start='+date_start+'&dt_end='+date_end+'&titre='+titre,
      dataType: 'html',
      success: function(data) 
      {
    		$('#'+divLoad).html(data);
      }
    });
}

//Page regulated informations
function regulatedInfoShowLoad(divLoad, date_start, date_end, titre)
{
	$('#'+divLoad).html(img_loader+' Chargement en cours...');
	
	$.ajax({
      url: 'regulated-information-media-list-by-date.php',
      type: 'POST',
      data: 'dt_start='+date_start+'&dt_end='+date_end+'&titre='+titre,
      dataType: 'html',
      success: function(data) 
      {
    		$('#'+divLoad).html(data);
      }
    });
}

//Page news
function newsMediaShowLoad(divLoad, ID_mediatype, date_start, date_end, titre)
{
	$('#'+divLoad).html(img_loader+' Chargement en cours...');
	
	$.ajax({
      url: 'netgem-news-media-list-by-date.php',
      type: 'POST',
      data: 'ID_mediatype='+ID_mediatype+'&dt_start='+date_start+'&dt_end='+date_end+'&titre='+titre,
      dataType: 'html',
      success: function(data) 
      {
    		$('#'+divLoad).html(data);
      }
    });
}

function newsMediaCollateralsPressShowLoad(divLoad, titre, type)
{
	$('#'+divLoad).html(img_loader+' Chargement en cours...');

	$.ajax({
      url: 'netgem-news-media-list-collaterals-press.php',
      type: 'POST',
      data: '&type='+type+'&titre='+titre,
      dataType: 'html',
      success: function(data) 
      {
    		$('#'+divLoad).html(data);
      }
    });
}

var newsMediaCurDivMedia;
function newsMediaDivToggle(divId)
{
	var options = {};

	if(newsMediaCurDivMedia && newsMediaCurDivMedia != divId && $('#'+newsMediaCurDivMedia))
	{
		//Fermeture de l'ancien
		$( "#"+newsMediaCurDivMedia ).hide( 'blind', options, 500 );
	}
	
	newsMediaCurDivMedia = divId;
	
	//Ouverture du nouveau
	if($( "#"+divId ).css('display') == 'none')
	{
		$( "#"+divId ).show( 'blind', options, 500 );
	}
}

function newsListYear( divYearSelected, classMediatype )
{
	$('.'+classMediatype).removeClass('menuListeCellSelected');
	$('.'+classMediatype).addClass('menuListeCellNorm');

	$('#'+divYearSelected).removeClass('menuListeCellNorm');
	$('#'+divYearSelected).addClass('menuListeCellSelected');
}

//CONTACT

function contactFormProcess(nom, prenom, email, txt, sujet)
{
	var url = '/contact-process.php?nom='+encodeURIComponent(nom)+'&prenom='+encodeURIComponent(prenom)+'&email='+encodeURIComponent(email)+"&objet="+encodeURIComponent(sujet)+"&txt="+encodeURIComponent(txt);

	$.ajax({
	  url: url,
	  dataType: "script"
	});	
}

//CONNECTED HOME SOLUTIONS

function connectedHomeShowInfoWin(titre, texte, picto, position_left, position_top, animation_img, animation_left, animation_top)
{
	
	var txt = '';
	if(picto != '')
	{
		txt += '<div id="connectedHomeWinInfoPicto"><img src="images/'+picto+'"></div>';
	}
	txt += '<h1>'+titre+'</h1>';
	txt += '<div>'+texte+'</div>';
	
	$('#connectedHomeWinInfo').css( 'margin-left', position_left  );
	$('#connectedHomeWinInfo').css( 'margin-top', position_top  );
	
	$('#connectedHomeWinInfo').html(txt);
	
	$('#connectedHomeWinInfo').show();
	
	if(animation_img != '')
	{
		$('#connectedHomeAnimation').html( '<img src="images/'+animation_img+'">' );
		$('#connectedHomeAnimation').css( 'margin-left', animation_left  );
		$('#connectedHomeAnimation').css( 'margin-top', animation_top  );
		$('#connectedHomeAnimation').show();
	}
}

function connectedHomeHideInfoWin()
{
	$('#connectedHomeWinInfo').hide();
	$('#connectedHomeAnimation').hide();
}

//Access Map
function locationsAccessMap()
{
    $.nyroModalManual({
      url: '/netgem-locations-access-map.php',
   	  minHeight: 120 // Hauteur minimale
    });
}

/*
//Exemple AJAX jQuery JSON

function login_check(login, pwd)
{
	$('#loader').html(img_loader);
	$.ajax({
	  url: 'login-check.php',
	  type: 'POST',
	  data: 'login='+login+'&pwd='+pwd,
	  dataType: 'json',
	  success: function(data) 
	  {
	  		switch(data.status)
	  		{
				TODO
	  		}
	  }
	});
}

// Exemple fenetre modale jQueryUI

function login_lost_pwd()
{
	var titleWin = 'Rappel de mot de passe';
	
	$( "#modalWin" ).dialog(
	{
				title: titleWin, 
				autoOpen: true,
				//height: 300,
				width: 300,
				modal: true,
				position: Array('center', 90),
				open: function() 
				{
		        		//display correct dialog content
			        	$("#modalWin").load("/login-lost-pwd.php");
				},			
				buttons: 
				{
						"Rappel mot de passe": function() 
						{														
								//Affichage des erreurs						
    							$.ajax(
    							{
    								  url: '/login-lost-pwd-process.php',
									  type: 'POST',
									  data: 'mail='+$( "#mailLostPwd" ).val(),    								  
    								  dataType: 'json',
    								  success: function(data) 
    								  {
											switch(data.result)
											{
												TODO
											}
    								  }
    							});
						},
						"Fermer": function() 
						{
							$( this ).dialog( "close" );
						}
				},
				close: function() 
				{
					$( "#mailLostPwd" ).removeClass( "ui-state-error" );
				}
	});
}

// Exemple zone alerte jQueryUI
function alerteZoneShow(titre, texte, autoHide)
{
	//MAJ des datas
	$( "#headerAlerteTitre" ).html(titre);
	$( "#headerAlerteTxt" ).html(texte);
	
	var options = {};
	if(autoHide == 1)
	{
		$( "#headerAlerteClose" ).hide();
		setTimeout(function() {
			$( "#headerAlerteZone" ).show( 'blind', options, 500, alerteZoneAutoHide );
		}, 1000 );				
	}
	else
	{
		$( "#headerAlerteClose" ).show();
		setTimeout(function() {
			$( "#headerAlerteZone" ).show( 'blind', options, 500 );
		}, 1000 );		
	}
}

function alerteZoneHide()
{
	var options = {};
	$( "#headerAlerteZone" ).hide( 'blind', options, 500 );
}

function alerteZoneAutoHide()
{
	setTimeout(function() {
		alerteZoneHide();
	}, 5000 );
}

*/
