function createCookie(name, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"=true"+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return false;
}

//verticalList
function verticalList(){
	if($('.perviewV_Item').length){
		$('.perviewV_Item').hide();
		$('.perviewV_Item').eq(0).show();
	}
	
	$('.vList li a').click(function(){
		var index = $('.vList li a').index($(this));
		$('.vList li a.on').removeClass('on');
		$(this).addClass('on');
		
		$('.perviewV_Item').hide();
		$('.perviewV_Item').eq(index).fadeIn();
		
		return false;
	})
	
	if($('.vList .list').length){
			$('.vList .list').jcarousel({
			buttonNextHTML : '<a class="nextV" href="#"></a>',
			buttonPrevHTML : '<a class="prevV" href="#"></a>',
			buttonNextEvent : 'click',
			buttonPrevEvent : 'click',
			vertical: true,
			scroll: 5
		});
	}


}

/*
function horizontalList(){
	if($('.perviewH').length){
		$('.perviewH .visu > div > img').not($('.perviewH .visu > div > img').eq(0)).css({opacity:'0'});
		$('.perviewH .visu > div > p').not($('.perviewH .visu > div > p').eq(0)).css({opacity:'0'});
		if($('.perviewH .visu > div > p').eq(0).length){
			$('.legend_img').text($('.perviewH .visu > div > p').eq(0).text());			
		}
					
	}

	$('.hList li a').click(function(){
		$('.hList li a.on').removeClass('on');
		$(this).addClass('on');
		var index = $('.hList li a').index($(this));
		$('.perviewH .visu > div > img').animate({opacity:0},300,function(){
			$('.perviewH .visu > div > img').eq(index).css({opacity:1});
			var desc = $('.perviewH .visu > div > p').eq(index).text();
			
			$('.legend_img').css({opacity:0});			
			$('.legend_img').text(desc);			
			$('.legend_img').css({opacity:1});			
		});		
		return false;
	})	
	
	if($('.hList .list').length){
		 $('.hList .list').jcarousel({
			buttonNextHTML : '<a class="nextH" href="#"></a>',
			buttonPrevHTML : '<a class="prevH" href="#"></a>',
			buttonNextEvent : 'click',
			buttonPrevEvent : 'click',
			scroll : 5
		});
	}
}
*/

function manageText(){
	/*$('.description_type').height($('.description_type .item_description').height()+10);*/
	$('.description_type').css({'bottom':-$('.description_type').height(),'visibility' : 'visible'});
	if($('.description_type').height()>230){
		$('.description_type').addClass('txt_long');
		$('.description_type .inner').height(102)
		// afficher description anime
		var hDescT = $('.description_type').height() + 30;
		$('.description_type').css({bottom : -hDescT});
		setTimeout('showDescription()',200);
	}else{
		//$('.description_type').addClass('txt_court');
		//$('.description_type').css({'visibility' : 'visible'});
		showDescription();
	}
}

function showDescription(){
	$('.description_type').animate({bottom : 0},600);
}

function hideBloc(){
	$('.description_type > div').animate({opacity:0},500);
}

var t;
function displayBlocText(){		
	$('body').mouseover(function(e){
		/*if($(e.target).parents('.description_type').length || $(e.target).hasClass('description_type')){
			$('.description_type .item_description').animate({opacity:1},500);
			//clearTimeout(t);
		}else{
			//t = setTimeout('hideBloc()',10000);
		}*/
	})
}

	
//document ready
$(function(){
	
	if($('.cufon').length) {
		Cufon.replace('.cufon',{hover: true});
		Cufon.replace('.information_page .box div',{lineheight:'20px'});
		Cufon.replace('.information_page .box p',{lineheight:'20px'});
	}
	
	if($('.description_type').length && !$('.home_page').length){
		//displayBlocText();
		setTimeout('manageText()',700);
	}
	
	// events Menu Left
	$('nav#nav_left li span a').click(function(){
		var parent = $(this).parents('li');
		var ul = parent.find('ul');
		if(ul.length){
			if(!parent.hasClass('active')){
				$('nav#nav_left li ul').hide();
				$('nav#nav_left li.active').removeClass('active');
				$(this).parents('li').addClass('active');
				ul.slideDown();
			}
			Cufon.refresh();
		}
		if($(this).attr('href') == '#'){
			return false;
		}
	})
	
	// vertical LIST
	verticalList();
	
	// Horizontal LIST
	//horizontalList();
	
	// add video 
	
	if($('#video1').length){
		if(navigator.platform == 'iPhone' || navigator.platform == 'iPad'){
			var img = $('.vjs-poster').attr('src');
			$('#video1').attr('poster',img);
			$('.vjs-poster').hide();
		}else{
			$('#video1').gVideo();	
		}
		
	}
	
	$('.view_video').click(function(){
		$.ajax({
			type:"POST",
			url:$(this).attr('href'),
				success:function(msg) {					
					if(!$('.popin').length){
						$('body').addClass('popin')
						$('#wrapper').append(msg);
					}					
				}
			})
		return false;
	})
	
	//events footer
	if($('#footer #std_new_event ul').length) {
		/*var w = $('#footer #std_new_event ul li').length * $('#footer #std_new_event ul').width();
		$('#footer #std_new_event ul').width(w);*/
		
		
		if($('#footer #std_new_event ul li').length==1) 
			$('#footer #std_new_event ul li').clone().appendTo('#footer #std_new_event ul');			
		
		$('#footer #std_new_event ul li').hide();
		$('#footer #std_new_event ul li').eq(0).show();
		if($('#footer #std_new_event ul li').length>1){
			setTimeout('showEvents()',5000);
		}
		
	}
	
	// scrol desc
	if($('.description_type .inner').length) setTimeout('eventsScrolDesc()',1000);
	
})


var pos = 1;
function showEvents(){	
		$('#footer #std_new_event ul li').hide();
		$('#footer #std_new_event ul li').eq(pos).fadeIn('slow');
		pos ++;
		if(pos==$('#footer #std_new_event ul li').length)
		pos = 0;
		setTimeout('showEvents()',5000);
}

var hInner,hDivtoScrol = 102;
var topp = 0;
function eventsScrolDesc(){
	$('.scrolToDown,.scrolTop').show();
	h = $('.description_type .inner').height();
	hDivtoScrol = $('.description_type .inner .txt_desc').height();
	var y = 25; // valeur pour scroller		
	displayScrolTo();
	$('.scrolToDown a').click(function(){		
		if(hDivtoScrol > h){
		var res = hDivtoScrol - h;
			if(res>0 && (-res)<topp){
				topp = topp - y;
			}
			displayScrolTo();
			$('.description_type .inner .txt_desc').animate({top: topp+'px'},400);			
		}		
		return false;
	})
	
	$('.scrolTop a').click(function(){		
		if(hDivtoScrol > h){
		var res = hDivtoScrol - h;
			if(topp<0){
				topp = topp + 20;
			}else{
				topp=0;
			}
			displayScrolTo();
			$('.description_type .inner .txt_desc').animate({top: topp+'px'},400);			
		}		
		return false;
	})	
}

function displayScrolTo(){	
	var res = hDivtoScrol - h;
	if(hDivtoScrol>h){
		$('a.scrolDisabled').removeClass('scrolDisabled');
		if(topp==0){
			$('.scrolTop a').addClass('scrolDisabled');
		}
		if((-res)>=topp) {
			$('.scrolToDown a').addClass('scrolDisabled');
		}		
	}else{
		$('.scrolToDown a,.scrolTop a').addClass('scrolDisabled');
	}
}

setCenter = function(){
	// $('#cachelogo').css("top", ( $(window).height() - $('#cachelogo').height() ) / 2+$(window).scrollTop() + "px");
}
