function initGlobal()
{
	initSliders();
	sliderporto();
	initOnglets();
	initAccordeon();
	initAnimAccordeon();
	initDate();
	liensAccord();
	liensAccord2();
	Contact();
	liensContact();
	filtre();
	Portfolio();
	equipe();
	tooltip();		
	Rollover();
	intiTweet();
}


//----------------------------
//les sliders
//----------------------------
function initSliders(){
	
$('#slider1').bxSlider({
	infiniteLoop: true,
            auto: true,
			pause: 10000,
            pager: true
        });	



$('#slider3').bxSlider({
	controls: false, 
	infiniteLoop: true,
            auto: true,
	pause: 5000,
            pager: true
        });	

$('#slider4').bxSlider({
	controls: false, 
	infiniteLoop: true,
            auto: true,
	pause: 10000,
            pager: true
        });	
		
$('#gars').bxSlider({
            displaySlideQty: 4,
            moveSlideQty: 1             
        });
}
//----------------------------
//slider portfolio
//----------------------------
function sliderporto(){
$('#slider2').bxSlider();
}
//----------------------------
//onglets
//----------------------------
function initOnglets(){	
$( "#contact" ).tabs({ fx: { opacity: 'toggle' } });
$( "#apropos" ).tabs();
}

//----------------------------
//accordeon
//----------------------------
function initAccordeon(){
$( "#accordion" ).accordion({
	header: 'div.headeracc',
	animated: 'bounceslide',
	autoHeight: false,
	collapsible: true,
	active: false, 
	icons: false,
	
});
}
//----------------------------
//Anim debut accordeon
//----------------------------
function WhatUrl() {
		myUrl = window.location.href;// lecture de l'URL
		myLink = parseUri(myUrl).anchor;
	
		Look = myLink.split('#');
		
		if(Look[0]) {
			//$("div.headeracc."+Look[0]).trigger("click");
			
			if(Look[0]=='derniers-projets') { 	ZeAnchor = 0; }
			if(Look[0]=='portfolio') { 			ZeAnchor = 1; }
			if(Look[0]=='apropos') { 			ZeAnchor = 2; }
			if(Look[0]=='nosclients') { 		ZeAnchor = 3; }
			
			return ZeAnchor;
				
		}
		
}



function initAnimAccordeon(){
	WhatUrl();
	setTimeout(function() {
	
	if(Look[0]) {	
		$( "#accordion" ).accordion({ active: ZeAnchor });	
		$("div.headeracc."+Look[0]).trigger("click");
	}
	else { 
		$( "#accordion" ).accordion({ active: 0 }); 
	}
		
    }, 2000); 	
}

//----------------------------
//deadline formulaire devis
//----------------------------
function initDate(){
	$( "#datepicker" ).datepicker();
}

//----------------------------
//liens accordeons
//----------------------------
function liensAccord(){
$("#navigation li.rea").addClass("active");
 $("#navigation li.rea").click(function () {
	 $( 'html, body' ).animate( { scrollTop: 300 }, 600 );
	  $("#navigation li").removeClass("active");
 	  $(this).addClass("active");
      $( "#accordion" ).accordion({ active: 0 });
	  $("#featured").slideto({highlight_color: '#e86d1b',slide_duration : 'fast'}); 
    });
	
 $("#navigation li.port").click(function () {
	 $( 'html, body' ).animate( { scrollTop: 300 }, 600 );
 $("#navigation li").removeClass("active");
$('ul#portfolio-list').fadeIn(3000);
 	  $(this).addClass("active");
      $( "#accordion" ).accordion({ active: 1 });
	  $("#portfolio").slideto({highlight_color: '#e86d1b',slide_duration : 'fast'}); 	  
    });
	
$("#navigation li.aprop").click(function () {
	$( 'html, body' ).animate( { scrollTop: 300 }, 600 );
	 $("#navigation li").removeClass("active");
 	  $(this).addClass("active");
      $( "#accordion" ).accordion({ active: 2 });
	  $("#apropos").slideto({highlight_color: '#e86d1b',slide_duration : 'fast'}); 
    });
	
	 $("#navigation li.clients").click(function () {
		 $( 'html, body' ).animate( { scrollTop: 300 }, 600 );
 $("#navigation li").removeClass("active"); 
 	  $(this).addClass("active");
      $( "#accordion" ).accordion({ active: 3 });
	  $("#nosclients").slideto({highlight_color:'#e86d1b',slide_duration : 'fast'});
	});
}

function liensAccord2(){
	$(".featured").click(function () {
		$( 'html, body' ).animate( { scrollTop: 300 }, 600 );
		$("#navigation li").removeClass("active");
		$("#navigation li.rea").addClass("active");
	});
	$(".portfolio").click(function () {
		$( 'html, body' ).animate( { scrollTop: 200 }, 600 );
		$("#navigation li").removeClass("active");
		$("#navigation li.port").addClass("active");
		
	});
	$(".apropos").click(function () {
		$( 'html, body' ).animate( { scrollTop: 300 }, 600 );
		$("#navigation li").removeClass("active");
		$("#navigation li.aprop").addClass("active");
	});
	$(".nosclients").click(function () {
		$( 'html, body' ).animate( { scrollTop: 300 }, 600 );
		$("#navigation li").removeClass("active");
		$("#navigation li.clients").addClass("active");
	});
}

//----------------------------
//contact
//----------------------------
function Contact(){
$("#contact").css('height','10px');
elem = $("a.contact");
	$("a.contact").click(function () { 
    if( elem.hasClass('active') ) 
	{
    FermCont();
    return false;
   }
   else
   {
    OuvreCont();
    return false;
   }
	});	
}

function OuvreCont(){
	$( 'html, body' ).animate( { scrollTop: 0 }, 0 );
	$("#contact").animate({height: "500px"}, {queue:false, duration: 500, })
	$("#header").height(180);
	$("#contact").addClass("active");
	$("a.contact").addClass("active");
}

function FermCont(){
	$("#contact").animate({height: "10px"}, {queue:false, duration: 500, })
	$("#contact").removeClass("active");
	$("#header").height(140);
	$("a.contact").removeClass("active"); 
}


//----------------------------
// bouton contact exterieur
//----------------------------
function liensContact(){
$("a.cont-stud").click(function () { 
	OuvreCont();
	});
}

//----------------------------
//Filtre portfolio
//----------------------------
function filtre(){
	$('ul.wp-tag-cloud a').click(function() {
		$(this).css('outline','none');
		$('ul.wp-tag-cloud .pm-active').removeClass('pm-active');
		$(this).parent().addClass('pm-active');
		
		var filterVal = $(this).text().toLowerCase().replace(' ','-');
		var filterVal = filterVal.replace(/é/g, "e");
		
				
		if(filterVal == 'all') {
			$('ul#portfolio-list li.hidden').fadeIn(1000).removeClass('hidden');
		} else {
			
			$('ul#portfolio-list li').each(function() {
				if(!$(this).hasClass(filterVal)) {
					$(this).fadeOut(1000).addClass('hidden');
				} else {
					$(this).fadeIn(1000).removeClass('hidden');
				}
			});
		}
		
		return false;
	});
}

//----------------------------
//portfolio
//----------------------------
function Portfolio(){
	$("#portfolio-list a").click(function(){ 
		page=($(this).attr("href")); 
		$.ajax({  
		url: page, 
		cache: false,
		success:function(html){ 
		afficher(html);
		},
		error:function(XMLHttpRequest, textStatus, errorThrows){
		}
		});
		return false;
		});					   
		function afficher(data) {
		$("#menuportfolio").hide(1000);
		$("#work").append(data) ;
		sliderporto();
		PortfolioClose();
		$("#work").show(500);
		}		
}

// bouton de retour portfolio
function PortfolioClose(){
	 $(".nav-work a").click(function(){
	 $("#work").empty(1000);
	  $("#menuportfolio").show(500);
	 });
}

//----------------------------
//les gars de l'equipe
//----------------------------
function equipe(){
   $("#gars a").click(function(){
	page=($(this).attr("href")); 
	$.ajax({ 
	url: page,
	cache: false,
	success:function(html){ 
	afficher2(html);
	},
	error:function(XMLHttpRequest, textStatus, errorThrows){
	}
	});
	return false;
   });

	function afficher2(data){
	$("#carou-gras").hide(1000);
	$("#legars").append(data);
	equipeClose();
	$("#legars").show(500);		
	}	 
}

// bouton de retour l'equipe
function equipeClose(){
	 $("a.fermer").click(function(){
	 $("#legars").empty(1000);
	  $("#carou-gras").show(500);
	 });
	 $("ul.apropos-menu a").click(function(){
	 $("#legars").empty(1000);
	  $("#carou-gras").show(500);
	 });
}

//----------------------------
//Tooltips
//----------------------------
function tooltip(){
	var tip;
	$(".tip_trigger").hover(function(){
	//Caching the tooltip and removing it from container; then appending it to the body
	tip = $(this).find('.tip').remove();
	$('body').append(tip);
	tip.show(); //Show tooltip
	}, function() {
	tip.hide().remove(); //Hide and remove tooltip appended to the body
	$(this).append(tip); //Return the tooltip to its original position
	}).mousemove(function(e) {
	//console.log(e.pageX)
	  var mousex = e.pageX + 20; //Get X coodrinates
	  var mousey = e.pageY + 20; //Get Y coordinates
	  var tipWidth = tip.width(); //Find width of tooltip
	  var tipHeight = tip.height(); //Find height of tooltip
	 //Distance of element from the right edge of viewport
	  var tipVisX = $(window).width() - (mousex + tipWidth);
	  var tipVisY = $(window).height() - (mousey + tipHeight);
	
	if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
		mousex = e.pageX - tipWidth - 20;
		$(this).find('.tip').css({  top: mousey, left: mousex });
	} if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport
		mousey = e.pageY - tipHeight - 20;
		tip.css({  top: mousey, left: mousex });
	} else {
		tip.css({  top: mousey, left: mousex });
	}
	});
}

//----------------------------
//rollover
//----------------------------
function Rollover(){
	$('#portfolio-list li').hover(function(){
	$(".cover", this).fadeIn();
	}, function() {
	$(".cover", this).fadeOut();
	});
	
	$('#compet li').hover(function(){
	$(".cover", this).fadeIn();
	}, function() {
	$(".cover", this).fadeOut();
	});
	
	$('#gars li').hover(function(){
	$(".cover", this).fadeIn();
	}, function() {
	$(".cover", this).fadeOut();
	});
}

//----------------------------
//Twitter
//----------------------------

function intiTweet(){
        $(".tweet").tweet({
            username: "newroundtwit",
            join_text: "auto",
            avatar_size: 32,
            count: 1,
            auto_join_text_default: "we said,",
            auto_join_text_ed: "we",
            auto_join_text_ing: "we were",
            auto_join_text_reply: "we replied to",
            auto_join_text_url: "we were checking out",
            loading_text: "loading tweets..."
        });
}



