
function initSlider(){
	var active; //= $('ul.slide-eff a.active');
	$('ul.slide-eff li').each(function(i){
		if(i == 0) active = $(this);
	}); 
	$('ul.eff1 li a').click(function(e){
		var li_width = 300;
		var marginVal = parseInt($(this).html()-1) * li_width * (-1);
		active.removeClass("active");
		$(this).parent().addClass("active");
		active = $(this).parent(); 
		$('div.footer_box ul.move-div').animate({"marginLeft": marginVal},500);
		return false;
	});
}

function initSlider2(){
	var active; 
	$('ul.eff2 li.active').each(function(i){
		if(i == 0) active = $(this);
	}); 
	$('ul.eff2 li a').click(function(e){
		var li_width = 300;
		var marginVal = parseInt($(this).html()-1) * li_width * (-1);
		active.removeClass("active");
		$(this).parent().addClass("active");
		active = $(this).parent(); 
		$('div.footer_box ul.move-div2').animate({"marginLeft": marginVal},500);
		return false;
	});
}

var initSelects = function(){
	topSelect();
	var mainObj = document.getElementById('custom-selects');
	
	if (mainObj){
		var selects = $('#custom-selects li');
		var myli = $('#select-on-top li');
		var ulsel = $('#select-on-top ul');
			
		for (i=0; i<selects.length;i++){
			if (selects[i].parentNode.id=='custom-selects'){
				selects[i].onclick = function(i){
					if (this.className.indexOf('open')!=-1){
						this.className = this.className.replace('open','');
					}
					else{
						for (var j=0;j<selects.length;j++){
							if (selects[j].parentNode.id=='custom-selects'){
								selects[j].className = selects[j].className.replace('open','')
							}
						}
						if(this.className == 'li_1'){
							$(ulsel[0]).css('display','block');
							$(ulsel[1]).css('display','none');
							$('#select-on-top ul').css('left',322);
						}	
						if(this.className == 'li_2'){
							$(ulsel[1]).css('display','block');
							$(ulsel[0]).css('display','none');
							$('#select-on-top ul').css('left',472);
						}					
						$('#select-on-top').show();
					}
					var top_li = $('#myTopSelect ul li a').each(function(e){ /* inserting  span elements */
						var this_text = $(this).text();
						$(this).text('');
						var str = '<span></span>';
						$(this).append(str);
						$(this).find('span').append(this_text);
					});
					
					var max_span_width = 0;
					var parent_ul = $('#myTopSelect ul');
					
					for(var i=0;i<parent_ul.length;i++){			/* determing maximum width of span elements */
						var element = parent_ul[i];
						max_span_width = $(element).width();
						var span_mas = $(element).find('span');
						for(var j=0;j<span_mas.length;j++){
							var this_w = $(span_mas[j]).width() + 7;
							if(max_span_width < this_w){
								max_span_width = this_w;
							}
						}
						$(element).css('width',max_span_width);
						$(element).find("a").css('width',max_span_width - 10);
					}
					return false;
				}	
			}
			else{
				var link = selects[i].getElementsByTagName('a')[0];
				link.onclick = function()
				{
					var parent = this.parentNode.parentNode.parentNode;
					var val = this.innerHTML;
					parent.getElementsByTagName('a')[0].innerHTML = val;
					parent.getElementsByTagName('input')[0].value = val;
					
					return false;
				}
			}
		}
		var new_links = $('#select-on-top li a');
		for(i=0;i<new_links.length;i++){
				$(new_links[i]).click(function(){
				 	var link_val = $(this).html();
					var input_val = $(this).text();
					if($(ulsel[0]).css('display')=='block'){
						var masa = $('#custom-selects li.li_1 a');
						var masi = $('#custom-selects li.li_1 input');
						$(masa[0]).html(link_val); 
						//$(masi[0]).html(link_val); 
						$(masi[0]).attr("value", input_val);
						$('#myTopSelect ul').css('display','none');
					} 	
					if($(ulsel[1]).css('display')=='block'){
						var masa = $('#custom-selects li.li_2 a');
						var masi = $('#custom-selects li.li_2 input');
						$(masa[0]).html(link_val); 
						//$(masi[0]).html(link_val); 
						$(masi[0]).attr("value", input_val);
						$('#myTopSelect ul').css('display','none');
					} 

					$('#select-on-top').hide();
					
					return false;
				});	
		}
	}
}

var initSelects2 = function(){
	topSelect2();
	var mainObj = document.getElementById('custom-selects2');
	
	if (mainObj){
		var selects = $('#custom-selects2 li');
		var myli = $('#select-on-top2 li');
		var ulsel = $('#select-on-top2 ul');
			
		for (i=0; i<selects.length;i++){
			if (selects[i].parentNode.id=='custom-selects2'){
				selects[i].onclick = function(i){
					if (this.className.indexOf('open')!=-1){
						this.className = this.className.replace('open','');
					}
					else{
						for (var j=0;j<selects.length;j++){
							if (selects[j].parentNode.id=='custom-selects2'){
								selects[j].className = selects[j].className.replace('open','')
							}
						}
						if(this.className == 'li_3'){
							$(ulsel[0]).css('display','block');
							$(ulsel[1]).css('display','none');
							$('#select-on-top2 ul').css('left',398);
						}	
						if(this.className == 'li_4'){
							$(ulsel[1]).css('display','block');
							$(ulsel[0]).css('display','none');
							$('#select-on-top2 ul').css('left',546);
						}					
						$('#select-on-top2').show();
					}
					var top_li = $('#myTopSelect2 ul li a').each(function(e){ /* inserting  span elements */
						var this_text = $(this).text();
						$(this).text('');
						var str = '<span></span>';
						$(this).append(str);
						$(this).find('span').append(this_text);
					});
					
					var max_span_width = 0;
					var parent_ul = $('#myTopSelect2 ul');
					
					for(var i=0;i<parent_ul.length;i++){			/* determing maximum width of span elements */
						var element = parent_ul[i];
						max_span_width = $(element).width();
						var span_mas = $(element).find('span');
						for(var j=0;j<span_mas.length;j++){
							var this_w = $(span_mas[j]).width() + 7;
							if(max_span_width < this_w){
								max_span_width = this_w;
							}
						}
						$(element).css('width',max_span_width);
						$(element).find("a").css('width',max_span_width - 10);
					}
					return false;
				}	
			}
			else{
				var link = selects[i].getElementsByTagName('a')[0];
				link.onclick = function()
				{
					var parent = this.parentNode.parentNode.parentNode;
					var val = this.innerHTML;
					parent.getElementsByTagName('a')[0].innerHTML = val;
					parent.getElementsByTagName('input')[0].value = val;
					var s=0;
					return false;
					
				}
				
			}
		}
		var new_links = $('#select-on-top2 li a');
		for(i=0;i<new_links.length;i++){
				$(new_links[i]).click(function(){
				 	var link_val = $(this).html();
					var input_val = $(this).text();
					if($(ulsel[0]).css('display')=='block'){
						var masa = $('#custom-selects2 li.li_3 a');
						var masi = $('#custom-selects2 li.li_3 input');
						$(masa[0]).html(link_val); 
						$(masi[0]).attr("value", input_val);
						$('#myTopSelect2 ul').css('display','none');
						
					} 	
					if($(ulsel[1]).css('display')=='block'){
						var masa = $('#custom-selects2 li.li_4 a');
						var masi = $('#custom-selects2 li.li_4 input');
						$(masa[0]).html(link_val); 
						$(masi[0]).attr("value", input_val);
						$('#myTopSelect2 ul').css('display','none');
					} 

					$('#select-on-top2').hide();
					
					return false;
				});	
		}
	}
}

var topSelect = function(){
	var win_h = $(window).height();
	var win_w = $(window).width();
	var scroll_pos = $(document).scrollTop();
	
	$('div.bg-page-bottom').after('<div id="select-on-top"></div>');
	var top_select = $('#select-on-top');
	
	
	top_select.css('top',0);
	top_select.css('left',0);
	top_select.css('display','none');
	top_select.css('width','100%');
	top_select.css('height',win_h + scroll_pos);
		
	top_select.append('<div id="myTopSelect"></div>');
	$('#myTopSelect').css('position','relative');
	$('#myTopSelect').css('width',960);
	$('#myTopSelect').css('margin','36px auto 0 auto');
	
	customSel = $('#custom-selects li ul').clone(true);	
	
	$('#myTopSelect').append(customSel);
	$('#select-on-top ul').css('top',-4);	
	top_select.click(function(){
		$(this).css('display','none');	
		$('#myTopSelect ul').css('display','none');
	});	
}

var topSelect2 = function(){
	var win_h = $(window).height();
	var win_w = $(window).width();
	var scroll_pos = $(document).scrollTop();
	
	$('div.bg-page-bottom').after('<div id="select-on-top2"></div>');
	var top_select = $('#select-on-top2');
	
	
	top_select.css('top',0);
	top_select.css('left',0);
	top_select.css('display','none');
	top_select.css('width','100%');
	top_select.css('height',win_h + scroll_pos);
		
	top_select.append('<div id="myTopSelect2"></div>');
	$('#myTopSelect2').css('position','relative');
	$('#myTopSelect2').css('width',960);
	$('#myTopSelect2').css('margin','36px auto 0 auto');
	
	customSel = $('#custom-selects2 li ul').clone(true);	
	
	$('#myTopSelect2').append(customSel);
	$('#select-on-top2 ul').css('top',205);	
	top_select.click(function(){
		$(this).css('display','none');	
		$('#myTopSelect2 ul').css('display','none');
	});	
}

function togSlide(){
var flag=0;
var q = $('#quest li');
var elem = $('#quest li');//document.getElementById('quest').getElementsByTagName('li');
for (var i=2; i<elem.length; i++){
elem[i].className+='hidden';
$(q[1]).css({background:'none'});
}
$("div.voir-tout a.voir2").hide();

$('div.voir-tout a').click(function(){
$(q[1]).css({background:"url('img/blue_line1.gif') no-repeat 0 100%"});
if (flag==0){
			flag=1;
		}
		else {
			flag=0;
		}
		if (flag==0){
		//$("div.voir-tout a").css({ background:"url('img/ico-view.gif') no-repeat 0 3px"});
		$("div.voir-tout a.voir2").hide();
		$("div.voir-tout a.voir1").show();
		
		$("#quest li[class='hidden']").each(function(){
		
		$(this).slideUp('slow');
		$(q[1]).css({background:'none'});
		});

		}
		else{
		$('#quest li').slideDown('slow');
		//$("div.voir-tout a").css({ background:"url('img/ico-view1.gif') no-repeat 0 3px"});
		$("div.voir-tout a.voir2").show();
		$("div.voir-tout a.voir1").hide();
		
		$("#quest li:last").css({ background:"none"});
		}
return false;
	});
}

$(document).ready(function(){
	
	initSlider();
	initSlider2();
	initSelects();
	initSelects2();
	togSlide();
	/*
	jQuery('#list1a').accordion({ 
	header: '.head',
	animated: 'easeslide',
	autoheight: false 
	});
	*/
	$('#list1a div.level2').hide().filter('.open').show();
	$('#list1a a.head').click(function(e){
		e.preventDefault();
		var curCont = $(this).parents('li').find('div.level2');
		$('#list1a div.level2').not(curCont).slideUp('slow');
		curCont.slideDown('slow');
	});
	$('a[@rel*=lightbox]').lightBox();
	$('input.identification').click(function(){
		$.ajax({
			type: "POST",
			url: "ajax.php",
			data: "inc=identification&lg="+lang+"&identifiant="+$('input#identifiant').val()+"&motdepasse="+$('input#motdepasse').val()+"&inc_rub="+$('input#inc_rub').val(),
			success: function(html){
				eval(html);
			}
		});
	});
	$('a .prec-2').click(function(e){
		/*$('.next-2').hide('fast');
		$('.prec-2').hide('fast');*/
		var pos = $(this).parents("a").attr('href');
		var num = $(this).parents("a").attr('rel');
		var larg_car = 300;
		var marg = 0;
		if(pos == 1){
			marg = (parseInt(larg_car) * (parseInt(num)-1)) * -1;
			$(this).parents("a").attr('href',num);
			$('#next-2-3').parents("a").attr('href',num);
		}else{
			marg = (parseInt(larg_car) * (parseInt(pos)-2)) * -1;
			$(this).parents("a").attr('href',parseInt(pos)-1);
			$('#next-2-3').parents("a").attr('href',parseInt(pos)-1);
		}
		//alert('prec -> '+marg);
		/*alert(pos);*/
		$('div.footer_box ul.move-div2').animate({"marginLeft": marg},500);
		/*$('.next-2').show('fast');
		$('.prec-2').show('fast');*/
		return false;
	});
	$('a .next-2').click(function(e){
		/*$('.next-2').hide('fast');
		$('.prec-2').hide('fast');*/
		var pos = $(this).parents("a").attr('href');
		var num = $(this).parents("a").attr('rel');
		var larg_car = 300;
		var marg = 0;
		if(num == pos){
			marg = 0;
			$(this).parents("a").attr('href','1');
			$('#prec-2-0').parents("a").attr('href','1');
		}else{
			marg = (parseInt(larg_car) * parseInt(pos)) * -1;
			$(this).parents("a").attr('href',parseInt(pos)+1);
			$('#prec-2-0').parents("a").attr('href',parseInt(pos)+1);
		}
		//alert('next -> '+marg);
		$('div.footer_box ul.move-div2').animate({"marginLeft": marg},500);
		/*$('.next-2').show('fast');
		$('.prec-2').show('fast');*/
		return false;
	});
	var timer = setInterval(function(){ $('a .next-2').click() },5000);
	$(".slide-cont").mouseover( function() { clearInterval(timer); });
	$(".slide-cont").mouseout( function() { timer = setInterval(function(){ $('a .next-2').click() },5000); });
});