/////////////////////////////////////////////////////////////On load
var easingM= "easeInOutQuad";  //easeInOutBack ,easeInOutQuad
var animation_duration = 1000;
var pathname = window.location.pathname;
var n = 0;//for testresize
var Lang="FR"; //EN ou PO 
var StageW=$(window).width();
var StageH=$(window).height();
var contentStyle="360";
var Orientation =window.orientation;
var support="";
checkDevice();
//alert(support);
$.backstretch("admin/template/img/bg.jpg");
/////////////////////////////////////////////////////////////On load
$(window).load(function() {
setTimeout(function(){	$('#loader').fadeTo(animation_duration, 0);},500);
});	

/////////////////////////////////////////////////////////////On Ready	
$(document).ready(function() {
	//center loader
	
	$("#anim,#overlay,#news,#footer,#creditPacaud").fadeTo(animation_duration,1.0);
	$("#loader").animate({ right: (StageW/2)+"px", top: (StageH/2)+"px"  }, 1,easingM,function() {$(this).fadeTo('fast', 1);});
	$("#overlay").fadeTo(animation_duration,0).hide(0);
	$('#anim').css('bottom','-'+StageH+'px');
	$('#anim').stop().animate({ bottom: '0' },{duration:animation_duration,easing: easingM});
	$('.content').css('top', (StageH+100)+'px');
	//////
	$("#topnav li").prepend("<span></span>"); 
	
	$("#close").fadeTo(animation_duration,0).hide(0);

	
	if(support!="mobile" && support!="tablet" ){
		
		$("#topnav li").each(function() { 
			var linkText = $(this).find("a").html(); 
			$(this).find("span").show().html(linkText); 
		}); 
		
		$("#topnav li").hover(function() {	
			$(this).find("span").stop().animate({ marginTop: "-40" }, 250);
		} , function() {
			$(this).find("span").stop().animate({
				marginTop: "0" 
			}, 250);
		});
		
		$(".btmenu").click(function() {	
			var linking=$(this).attr("openLink");
			$.address.value($(this).attr("adress"));
		});
	}else{
		$(".btmenu, #openNewsletter").css("color","#FFFFFF");
		$(".btmenu").click(function() {	
			var linking=$(this).attr("openLink");
			$.address.value($(this).attr("adress"));
			//alert("hover");
		});
	}


	
	$.address.change(function(event) {  
	   if($.address.pathNames()!=""){
		$('.content').removeClass("contentactif");
		
		if($.address.pathNames()=="videos"){$('#content4').addClass("contentactif");}
		if($.address.pathNames()=="dates"){$('#content3').addClass("contentactif");}
		if($.address.pathNames()=="discographie"){$('#content5').addClass("contentactif");}
		if($.address.pathNames()=="news"){$('#content6').addClass("contentactif");}
		if($.address.pathNames()=="bio"){$('#contentpag5').addClass("contentactif");}
		if($.address.pathNames()=="contact"){$('#contentpag6').addClass("contentactif");}
		
	    $('#overlay').show(0).fadeTo(animation_duration,1.0);
	    $('#anim').stop().animate({ bottom: '-'+StageH+'px' },{duration:animation_duration,easing: easingM});
	    $("#close").show(0).fadeTo(animation_duration,1.0);
	    
	    /*if ($("video").paused == false) {$("video").pause();}*/	
	    agencement(); 
	    }else{
	    	$('.content').removeClass("contentactif");
	    	$("#close").fadeTo(animation_duration,0).hide(0);
	    	$('#anim').show(0).fadeTo(animation_duration,1.0).animate({ bottom: '0' },{duration:animation_duration,easing: easingM});
	    	$("#overlay").fadeTo(animation_duration,0).hide(0);
	    }
	});  
	
	
	$("#close").click(function() {	
		$('.content').removeClass("contentactif");
		$("#close").fadeTo(animation_duration,0).hide(0);
		$('#anim').show(0).fadeTo(animation_duration,1.0).animate({ bottom: '0' },{duration:animation_duration,easing: easingM});
		$("#overlay").fadeTo(animation_duration,0).hide(0);
		$.address.value("");
		agencement();
	});
	$("#openNewsletter").click(function() {	
		var clicked="false";
		$("#newsletter1").stop().animate({ bottom: "50px" },{duration:animation_duration,easing: easingM});
		$("#newsletter").stop().animate({ bottom: "0px" },{duration:animation_duration,easing: easingM});
		$("#inputContact input").click(function() { clicked="true"; });
		setTimeout(function(){
		if(clicked=="false"){  $("#newsletter").stop().animate({ bottom: "-300px" },{duration:animation_duration,easing: easingM}); }	
		},4000);
		//$("#newsletter").css('bottom',"0px");
	});
	
	//.stop().animate({ bottom: "-200px" },{duration:animation_duration,easing: easingM});
	
	/////////////// FancyBox
	$(".colorboxshow").fancybox({'overlayShow'	: true,'overlayColor':'#000000','transitionIn'	: 'elastic','titleShow':true,'titlePosition':'over','transitionOut'	: 'elastic'});  
	$("a[rel=imggallery]").fancybox({'overlayShow'	: true,'overlayColor':'#000000','transitionIn'	: 'elastic','transitionOut'	: 'elastic'});
	$(".latest_img").hover(function(){$(this).fadeTo("slow", 0.5);},function(){$(this).fadeTo("slow", 1.0);});
	/////
	
	
	
	
	$(".latest_img").hover(function(){
		$(this).stop().animate({opacity:"0"},{queue:false,duration:800});
	}, function() {
		$(this).stop().animate({opacity:"1"},{queue:false,duration:800});
	});
	
	//resize
	$(window).resize(function(){ n=n+1;testresize(n);	});
	//fadeout loader
	setTimeout(function(){	$('#loader').fadeTo(animation_duration, 0).html("");},500);
	
	//patch iframes
	//if(support!="mobile" && support!="tablet" ){
		$('iframe').each(function(){
		var url = $(this).attr("src");
		$(this).attr("src",url+"?wmode=transparent");
		});
	//}
	
	agencement();
		
});	//END of jQuery







//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////fonctions
$(function() {
	$('#loader').activity({segments: 12, steps: 3, opacity: 0.3, width: 3, space: 4, length: 5, color: '#937a60', speed: 1.5});		
});

/////////////////////////////////////////////////////////////fonctions MAJStage	
function MAJStage(){
StageW=$(window).width();
StageH=$(window).height();
}

/////////////////////////////////////////////////////////////fonctions testresize	
function testresize(y) {
	setTimeout(function(){  if(y==n){agencement();} },200);	
}
/////////////////////////////////////////////////////////////fonctions agencement
function agencement(){
MAJStage();
	$('.content').animate({top: (StageH+500)+'px' },{duration:400,easing: easingM});

	if(StageH>560){ 
		var supp=(StageH-360)/2; 
		if(contentStyle!="normal"){
		$('.contentactif').fadeTo(animation_duration,1.0).animate({top: supp+"px" },{duration:animation_duration,easing: easingM});
		}
		$("html").stop().css("overflow","hidden");
		$("body,html").stop().css("height",StageH+"px");
		
	}else{
		if(contentStyle!="normal"){
			$('.contentactif').fadeTo(animation_duration,1.0).animate({top: "148px" },{duration:animation_duration,easing: easingM});
			$('#anim').stop().animate({ bottom: '-600px' },{duration:animation_duration,easing: easingM});
		}
		$("html").stop().css("overflow","auto");
		$("body,html").stop().css("height","560px");
		
	}

	$('.scroll').jScrollPane({showArrows: false});

}

window.onorientationchange = function() {

if(window.orientation==0 || window.orientation==180){ 
$("#turnYourMobil").css("display","block");

}else{$("#turnYourMobil").css("display","none");}

}



/////////////////////////////////////////////////////////////fonctions	Center
function center(div){
var positionY=Math.ceil( (StageH/2)-($(div).height()/1.30) );
var StageCenterW=Math.ceil(StageW/2); var DivCenterW=Math.ceil($(div).width()/1.45);
var positionX=(StageCenterW-DivCenterW);
$(div).animate({ left: positionX+"px", top: positionY+"px"  }, 1,easingM);
}

function alignH(div){
var WidthParent=$(div).parent().width();
var WidthDiv=$(div).width();
var positionX2=(WidthParent -WidthDiv)/2;
$(div).animate({ marginLeft:positionX2+"px" }, 1,easingM,function(){$(this).fadeTo(animation_duration, 1.0);});
}

/////////////////////////////////////////////////////////////fonctions	clickclear/clickrecall	
function clickclear(thisfield, defaulttext){
	if (thisfield.value == defaulttext) {thisfield.value = '';}
}
function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == '') {thisfield.value = defaulttext;}
}

(function(){
    var all = $.event.props,
        len = all.length,
        res = [];
    while (len--) {
      var el = all[len];
      if (el != 'layerX' && el != 'layerY') res.push(el);
    }
    $.event.props = res;
}());

/////////////////////////////////////////////////////////////fonctions convertRGB	 
function convertRGB(rgb) {
	rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
    function hex(x) {return ("0" + parseInt(x).toString(16)).slice(-2);}
    return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}


function checkDevice(){
	if( navigator.userAgent.match(/Android/i) && (navigator.userAgent.match(/Mobile/i))  
		|| navigator.userAgent.match(/webOS/i)  && (navigator.userAgent.match(/Mobile/i))  
		|| navigator.userAgent.match(/iPhone/i) && (navigator.userAgent.match(/Mobile/i))   
		|| navigator.userAgent.match(/iPod/i)  && (navigator.userAgent.match(/Mobile/i))  
		|| navigator.userAgent.match(/opera/i)   && (navigator.userAgent.match(/Mobile/i))  
		|| navigator.userAgent.match(/blackberry/i)  && (navigator.userAgent.match(/Mobile/i))  
		|| navigator.userAgent.match(/palm/i)  && (navigator.userAgent.match(/Mobile/i))  
		
		){ 
		support="mobile";	
	}else{
		
		if ( (navigator.userAgent.match(/Android/i))|| navigator.userAgent.match(/iPad/i) ) {      
		support="tablet";
		}else{
			var userAgent = navigator.userAgent.toLowerCase(); 
			$.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase()); 
			
			// Is this a version of Chrome?
			if($.browser.chrome){
			  userAgent = userAgent.substring(userAgent.indexOf('chrome/') +7);
			  userAgent = userAgent.substring(0,userAgent.indexOf('.'));
			  $.browser.version = userAgent;
			  // If it is chrome then jQuery thinks it's safari so we have to tell it it isn't
			  $.browser.safari = false;
			  support="normal";
			
		
			}else if($.browser.safari){
			  userAgent = userAgent.substring(userAgent.indexOf('safari/') +7);
			  userAgent = userAgent.substring(0,userAgent.indexOf('.'));
			  $.browser.version = userAgent;
			  support="safari";//
			}else{
				support="normal";
			}
		}	
	}
}




