/*************/
/* index.js */
/***********/


/////// LANG ////////
if(langGlobal == "fr"){
	var msg_wrong_com = "Il faut remplir les champs nom, mail et commentaires";
}else{
	var msg_wrong_com = "Name, email and comment must be filled";
}
////// END LANG ///////



var currentPos = 0;
var maxPos=3;
var auto_slide_seconds = 6000;
var timer;


var tabSlides=[
	/*{title: "Headline", id: "#uneAboutCarousel", bg: "#993377"},*/
	{title: "Headline", id: "#articlesAboutBotCarousel", bg: "#993377"},
	{title: "Latest reports", id: "#reportsAboutBotCarousel", bg: "#993377"},
	{title: "Latest travel stories", id: "#storiesAboutBotCarousel", bg: "#009999"},
	{title: "Latest addresses", id: "#addressesAboutBotCarousel", bg: "#E64444"}
];

function init_caroussel(){
  //autoslide
  var auto_slide = 1;

  //check if auto sliding is enabled
  if(auto_slide == 1)
    timer = setInterval('slide()', auto_slide_seconds);
}

 //slide function
function slide(){
	if(currentPos<maxPos){
		moveto(1);
	}else{
		moveto(-maxPos);
		//currentPos=0;
	}
}

 //rewind function
function rewind(){
  if(currentPos>0)
    moveto(-1);
  else
    moveto(maxPos);
}

function clickButtonSlider(pos){
	var to=(pos-currentPos);
	moveto(to);
}

function moveto(pos){
	//clear le timer
	clearInterval(timer);

	//get the item width
	var item_width = $('#carousel_ul li').outerWidth();
	var where="";

	if(pos < 0)
		where="left";
	else if(pos > 0)
		where="right";
	else
		return 1;

	if(where == 'left'){
		var left_indent = parseInt($('#carousel_ul').css('left')) + item_width*Math.abs(pos);
	}else{
		var left_indent = parseInt($('#carousel_ul').css('left')) - item_width*Math.abs(pos);
	}
  
	//Recup des infos sous le carousel (du slide entrain d'arriver donc curpos+1
	infoIndex=(currentPos+1)%(maxPos+1);
	//alert(infoIndex);
	tabInfo=tabSlides[infoIndex];
	
	//make the sliding effect using jQuery's animate function... '
	$('#carousel_ul:not(:animated)').animate({'left' : left_indent},500,function(){
		//maj des champs contextuel autour du carousel
		$("#titleBotCarousel").html(tabInfo.title);
		$("#botCarousel").css("background-color", tabInfo.bg);
		dispInfoCarousel(tabInfo.id);
		currentPos+=pos;
		//alert(pos);
	});
	
	//on rearme le timer
	timer = setInterval('slide("right")', auto_slide_seconds);
}

function dispInfoCarousel(nextId){
	for(i in tabSlides){
		if(tabSlides[i].id==nextId)
			$(nextId).show();
		else
			$(tabSlides[i].id).hide();
	}
}


function check_submit_artCom () {
	var check=1;
	var c_name = window.document.getElementById("author");
	var c_mail = window.document.getElementById("email");
	var c_com = window.document.getElementById("comment");
	
	if(c_name.value == "") { check = 0;}
	if(c_mail.value == "") { check = 0;}
	if(c_com.value == "") { check = 0;}
	
	if(check) {
		return true;
	} else {
		alert(msg_wrong_com);
		return false;
	}
}

