// ------------------ //
// FUNCTIONS CREATION //
// ------------------ //


// AWARDS DIAPORAMA

function awardsDiaporama(){
	$("li.award ul li").hide();
	$("li.award ul li:first").show();
	if($("li.award").length!=0){
		$("li.award").stopTime();
		$("li.award ul").everyTime(5000,function(){
			if($("li.award ul li:visible").next("li.award ul li").length!=0){
				nextAward = $("li.award ul li:visible").next("li.award ul li");
			}
			else{
				nextAward = $("li.award ul li:first");
			}
			$("li.award ul li:visible").fadeOut("slow",function(){
				$(nextAward).fadeIn("slow");														 
			});
		});
	}
}


// TOPIC ABSTRACT DIAPORAMA

function topicAbstractDiaporama(){
	$("ul.topic_abstract").stopTime();
	$("ul.topic_abstract").everyTime(5000,function(){
		if($("ul.topic_abstract li:visible").next("ul.topic_abstract li").length!=0){
			nextTopicAbstract = $("ul.topic_abstract li:visible").next("ul.topic_abstract li");
		}
		else{
			nextTopicAbstract = $("ul.topic_abstract li:first");
		}
		$("ul.topic_abstract li:visible").fadeOut("slow",function(){
			$(nextTopicAbstract).fadeIn("slow");														 
		});
	});
}


// TOPIC ABSTRACT DISPLAY

function topic_abstract_display(){
	$("ul.topic_abstract li").hide();
	$("ul.topic_abstract li:first").show();
	topicAbstractDiaporama();
	$("#features .topic .navigation .previous").click(function(){
		$("ul.topic_abstract").stopTime();
		$("ul.topic_abstract").everyTime(10000,function(){
			topicAbstractDiaporama();
		});
		if($("ul.topic_abstract li:visible").prev("ul.topic_abstract li").length!=0){
			prevTopicAbstract = $("ul.topic_abstract li:visible").prev("ul.topic_abstract li");
		}
		else{
			prevTopicAbstract = $("ul.topic_abstract li:last");
		}
		$("ul.topic_abstract li:visible").fadeOut("slow",function(){
			$(prevTopicAbstract).fadeIn("slow");														 
		});
	});
	$("#features .topic .navigation .next").click(function(){
		$("ul.topic_abstract").stopTime();
		$("ul.topic_abstract").everyTime(10000,function(){
			topicAbstractDiaporama();
		});
		if($("ul.topic_abstract li:visible").next("ul.topic_abstract li").length!=0){
			nextTopicAbstract = $("ul.topic_abstract li:visible").next("ul.topic_abstract li");
		}
		else{
			nextTopicAbstract = $("ul.topic_abstract li:first");
		}
		$("ul.topic_abstract li:visible").fadeOut("slow",function(){
			$(nextTopicAbstract).fadeIn("slow");														 
		});
	});
}


// TESTIMONY DIAPORAMA

function testimonyDiaporama(){
	$(".testimony").stopTime();
	$(".testimony").everyTime(7500,function(){
		if($(".testimony .content:visible").next(".testimony .content").length!=0){
			var nextTestimony = $(".testimony .content:visible").next(".testimony .content");
		}
		else{
			var nextTestimony = $(".testimony .content:first");
		}
		$(".testimony .content:visible").fadeOut("slow",function(){
			$(nextTestimony).fadeIn("slow");														 
		});
	});
}


// TESTIMONY DISPLAY

/* VARIABLES */
testimonyNumber = 0;
/* FUNCTIONS */
function testimony_display(){	
	testimonyDiaporama();
	/* NEXT BUTTON CLICK */
	$(".testimony_navigation .next").click( function(){
		$(".testimony").stopTime();
		$(".testimony").everyTime(30000,function(){
			testimonyDiaporama();
		});
		if($(".testimony .content:visible").next(".testimony .content").length!=0){
			var nextTestimony = $(".testimony .content:visible").next(".testimony .content");
		}
		else{
			var nextTestimony = $(".testimony .content:first");
		}
		$(".testimony .content:visible").fadeOut("slow",function(){
			$(nextTestimony).fadeIn("slow");														 
		});
	});
	/* PREVIOUS BUTTON CLICK */
	$(".testimony_navigation .previous").click( function(){
		$(".testimony").stopTime();
		$(".testimony").everyTime(30000,function(){
			testimonyDiaporama();
		});
		if($(".testimony .content:visible").prev(".testimony .content").length!=0){
			var previousTestimony = $(".testimony .content:visible").prev(".testimony .content");
		}
		else{
			var previousTestimony = $(".testimony .content:last");
		}
		$(".testimony .content:visible").fadeOut("slow",function(){
			$(previousTestimony).fadeIn("slow");														 
		});
	});
	/* TESTIMONY LIST CLICK */
	$(".testimony_list span").click( function(){
		$(".testimony").stopTime();
		$(".testimony").everyTime(30000,function(){
			testimonyDiaporama();
		});
		var href = $(this).attr("rel");
		var testimonyId = href.split("_");
		testimonyNumber = testimonyId[1];
		$(".testimony .content:visible").fadeOut("slow",function(){
			$("#testimony_"+testimonyNumber).fadeIn("slow");														 
		});
	});
}


// PARTNERS LIST
function partners_list_display(){
	$("ul.partners_list li span").toggle(
		function(){
			$(this).addClass("selected");
			$(this).next("ul").slideDown("slow");							
		},
		function(){
			$(this).next("ul").slideUp("slow");
			$(this).removeClass("selected");		
		}
	);
}


// PRESS REVIEWS LIST
function press_reviews_list_display(){
	$("ul.press_reviews_list li span").toggle(
		function(){
			$(this).addClass("selected");
			$(this).next("ul").slideDown("slow");							
		},
		function(){
			$(this).next("ul").slideUp("slow");
			$(this).removeClass("selected");		
		}
	);
}


// CASE STUDIES : LOGOS DIAPORAMA
function logos_diaporama(){
	$(".logos_diaporama").everyTime(2500,function(){
		if($(".logos_diaporama a:visible").next().length!=0){	
			nextDiv = $(".logos_diaporama a:visible").next();
		}
		else{
			nextDiv = $(".logos_diaporama a:first");
		}
		$(".logos_diaporama a:visible").fadeOut("slow",function(){
			$(nextDiv).fadeIn("slow");														 
		});
	});
}


// CASE STUDIES : VISUAL DIAPORAMA
function visual_diaporama(){
	$(".visual_diaporama").everyTime(5000,function(){
		if($(".visual_diaporama .visual:visible").next().length!=0){	
			nextDiv = $(".visual_diaporama .visual:visible").next();
		}
		else{
			nextDiv = $(".visual_diaporama .visual:first");
		}
		$(".visual_diaporama .visual:visible").fadeOut("slow",function(){
			$(nextDiv).fadeIn("slow");														 
		});
	});
}



// MANAGERS DIAPORAMA

/* VARIABLES */
biographyNumber = 0;

/* FUNCTION */
function biographyDisplay(){
	$(".managers_list li:first img").addClass("selected");
	$(".managers_list li").hover( function(){
		var imgClass = $(this).find("img").attr("class");
		var that = $(this);
		if(imgClass != "selected"){
			var that= $(this);
			var managersListLink = $(that).attr("id");
			var biographyId = managersListLink.split("_");
			biographyNumber = parseInt(biographyId[1]);
			$(".biography:visible").fadeOut("fast",function(){
				$("#biography_"+biographyNumber).fadeIn("fast");														 
			});
			$(".managers_list li img").removeClass("selected");
			$(that).find("img").addClass("selected");
		}
	});
}



// ----------------- //
// FUNCTIONS CALLING //
// ----------------- //

$(document).ready(function(){
	awardsDiaporama();
	topic_abstract_display();
	testimony_display();
	partners_list_display();
	press_reviews_list_display();
	visual_diaporama();
	logos_diaporama();
	biographyDisplay();
});
